Skip to content

Commit 299fbba

Browse files
committed
Replace GENERIC_TBP_ONCE macro with function.
In queue_generic_tbp_once(), add the check that was originally in GENERIC_TBP_ONCE macro and also check whether we are in a nested subprogram. If we are, then we also need to regenerate the generic type-bound procedure bindings once. Before, we were never regenerating them because they were already generated by the host subprogram.
1 parent 5eecfa2 commit 299fbba

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

tools/flang1/flang1exe/semgnr.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static void get_type_rank(SST *, int *, int *);
4949
static ITEM *make_list(SST *, SST *);
5050
static int resolve_operator(int, SST *, SST *);
5151
static int find_operator(int, SST *, SST *, LOGICAL);
52+
static bool queue_generic_tbp_once(SPTR gnr);
5253

5354
/* macros used by the arg scoring routines */
5455
#define UNIT_SZ 3 /**< bits necessary to hold the max *_MATCH value */
@@ -111,19 +112,25 @@ static struct optabstruct {
111112
};
112113
#define OPTABSIZE 29
113114

114-
static int generic_tbp_scope = 0;
115-
116-
static int
117-
queue_generic_tbp_once()
115+
/** \brief Determines if we should (re)generate generic type bound procedure
116+
* (tbp) bindings based on scope. This should only be done once per scope.
117+
*
118+
* \param gnr is the SPTR of the symbol to check or 0 if N/A.
119+
*
120+
* \return true if we should (re)generate generic tbp bindings, else false.
121+
*/
122+
static bool
123+
queue_generic_tbp_once(SPTR gnr)
118124
{
119-
int rslt;
120-
rslt = (generic_tbp_scope != stb.curr_scope);
121-
generic_tbp_scope = stb.curr_scope;
122-
return rslt;
125+
if (GNCNTG(gnr) == 0 || gbl.internal > 1) {
126+
static int generic_tbp_scope = 0;
127+
bool rslt = (generic_tbp_scope != stb.curr_scope);
128+
generic_tbp_scope = stb.curr_scope;
129+
return rslt;
130+
}
131+
return false;
123132
}
124133

125-
#define QUEUE_GENERIC_TBP_ONCE (queue_generic_tbp_once())
126-
127134
void
128135
check_generic(int gnr)
129136
{
@@ -148,7 +155,7 @@ generic_tbp_call(int gnr, SST *stktop, ITEM *list, ITEM *chevlist)
148155
if (DBGBIT(3, 256))
149156
fprintf(gbl.dbgfil, "user generic, call %s\n", SYMNAME(gnr));
150157
#endif
151-
if (GNCNTG(gnr) == 0 && QUEUE_GENERIC_TBP_ONCE) {
158+
if (queue_generic_tbp_once(gnr)) {
152159
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
153160
}
154161

@@ -194,7 +201,7 @@ generic_tbp_func(int gnr, SST *stktop, ITEM *list)
194201
fprintf(gbl.dbgfil, "user generic %s\n", SYMNAME(gnr));
195202
#endif
196203

197-
if (GNCNTG(gnr) == 0 && QUEUE_GENERIC_TBP_ONCE) {
204+
if (queue_generic_tbp_once(gnr)) {
198205
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
199206
}
200207

@@ -352,7 +359,7 @@ find_best_generic(int gnr, ITEM *list, int arg_cnt, int try_device,
352359
if (GNCNTG(sptrgen) == 0 && GTYPEG(sptrgen)) {
353360
continue; /* Could be an overloaded type */
354361
}
355-
if (GNCNTG(sptrgen) == 0 && QUEUE_GENERIC_TBP_ONCE) {
362+
if (queue_generic_tbp_once(sptrgen)) {
356363
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
357364
}
358365
if (GNCNTG(sptrgen) == 0 && !IS_TBP(sptrgen)) {
@@ -840,7 +847,7 @@ defined_operator(int opr, SST *stktop, SST *lop, SST *rop)
840847
if (DBGBIT(3, 256))
841848
fprintf(gbl.dbgfil, "user operator %s\n", SYMNAME(opr));
842849
#endif
843-
if (QUEUE_GENERIC_TBP_ONCE)
850+
if (queue_generic_tbp_once(0))
844851
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
845852
if (STYPEG(opr) != ST_OPERATOR) {
846853
i = findByNameStypeScope(SYMNAME(opr), ST_OPERATOR, stb.curr_scope);
@@ -1068,7 +1075,7 @@ is_intrinsic_opr(int val, SST *stktop, SST *lop, SST *rop, int tkn_alias)
10681075
if (opr) {
10691076
func = resolve_operator(opr, lop, rop);
10701077
if (!func && /*IN_MODULE*/ sem.mod_cnt && sem.which_pass) {
1071-
if (QUEUE_GENERIC_TBP_ONCE)
1078+
if (queue_generic_tbp_once(0))
10721079
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
10731080
func = resolve_operator(opr, lop, rop);
10741081
}
@@ -1357,7 +1364,7 @@ check_defined_io2(char *proc, int silentmode, int chk_dtype)
13571364
continue;
13581365
if (GNCNTG(sptrgen) == 0 && GTYPEG(sptrgen))
13591366
continue;
1360-
if (GNCNTG(sptrgen) == 0 && QUEUE_GENERIC_TBP_ONCE) {
1367+
if (queue_generic_tbp_once(sptrgen)) {
13611368
queue_tbp(0, 0, 0, 0, TBP_COMPLETE_GENERIC);
13621369
}
13631370

0 commit comments

Comments
 (0)