Skip to content

Commit 9a2116f

Browse files
author
Sandra Loosemore
committed
OpenMP: Pass a 3-way flag to omp_check_context_selector instead of a bool.
The OpenMP "begin declare variant" directive has slightly different requirements for context selectors than regular "declare variant", so something more than a bool is required to tell the error-checking routine what to check. gcc/ChangeLog * omp-general.cc (omp_check_context_selector): Change metadirective_p argument to a 3-way flag. Add extra check for OMP_CTX_BEGIN_DECLARE_VARIANT. * omp-general.h (enum omp_ctx_directive): New. (omp_check_context_selector): Adjust declaration. gcc/c/ChangeLog * c-parser.cc (c_finish_omp_declare_variant): Update call to omp_check_context_selector. (c_parser_omp_metadirective): Likewise. gcc/cp/ChangeLog * parser.cc (cp_finish_omp_declare_variant): Update call to omp_check_context_selector. (cp_parser_omp_metadirective): Likewise. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Update call to omp_check_context_selector. (gfc_trans_omp_metadirective): Likewise.
1 parent 84854ce commit 9a2116f

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

gcc/c/c-parser.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26982,7 +26982,8 @@ c_finish_omp_declare_variant (c_parser *parser, tree fndecl, tree parms)
2698226982
ctx = c_parser_omp_context_selector_specification (parser, parms);
2698326983
if (ctx == error_mark_node)
2698426984
goto fail;
26985-
ctx = omp_check_context_selector (match_loc, ctx, false);
26985+
ctx = omp_check_context_selector (match_loc, ctx,
26986+
OMP_CTX_DECLARE_VARIANT);
2698626987
if (ctx != error_mark_node && variant != error_mark_node)
2698726988
{
2698826989
if (TREE_CODE (variant) != FUNCTION_DECL)
@@ -29099,7 +29100,8 @@ c_parser_omp_metadirective (c_parser *parser, bool *if_p)
2909929100
NULL_TREE);
2910029101
if (ctx == error_mark_node)
2910129102
goto error;
29102-
ctx = omp_check_context_selector (match_loc, ctx, true);
29103+
ctx = omp_check_context_selector (match_loc, ctx,
29104+
OMP_CTX_METADIRECTIVE);
2910329105
if (ctx == error_mark_node)
2910429106
goto error;
2910529107

gcc/cp/parser.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50437,7 +50437,8 @@ cp_finish_omp_declare_variant (cp_parser *parser, cp_token *pragma_tok,
5043750437
ctx = cp_parser_omp_context_selector_specification (parser, true);
5043850438
if (ctx == error_mark_node)
5043950439
goto fail;
50440-
ctx = omp_check_context_selector (match_loc, ctx, false);
50440+
ctx = omp_check_context_selector (match_loc, ctx,
50441+
OMP_CTX_DECLARE_VARIANT);
5044150442
if (ctx != error_mark_node && variant != error_mark_node)
5044250443
{
5044350444
tree match_loc_node
@@ -51424,7 +51425,8 @@ cp_parser_omp_metadirective (cp_parser *parser, cp_token *pragma_tok,
5142451425
ctx = cp_parser_omp_context_selector_specification (parser, false);
5142551426
if (ctx == error_mark_node)
5142651427
goto fail;
51427-
ctx = omp_check_context_selector (match_loc, ctx, true);
51428+
ctx = omp_check_context_selector (match_loc, ctx,
51429+
OMP_CTX_METADIRECTIVE);
5142851430
if (ctx == error_mark_node)
5142951431
goto fail;
5143051432

gcc/fortran/trans-openmp.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8776,7 +8776,8 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns)
87768776
continue;
87778777
}
87788778
set_selectors = omp_check_context_selector
8779-
(gfc_get_location (&odv->where), set_selectors, false);
8779+
(gfc_get_location (&odv->where), set_selectors,
8780+
OMP_CTX_DECLARE_VARIANT);
87808781
if (set_selectors != error_mark_node)
87818782
{
87828783
if (!variant_proc_sym->attr.implicit_type
@@ -9082,7 +9083,7 @@ gfc_trans_omp_metadirective (gfc_code *code)
90829083
tree ctx = gfc_trans_omp_set_selector (variant->selectors,
90839084
variant->where);
90849085
ctx = omp_check_context_selector (gfc_get_location (&variant->where),
9085-
ctx, true);
9086+
ctx, OMP_CTX_METADIRECTIVE);
90869087
if (ctx == error_mark_node)
90879088
return error_mark_node;
90889089

gcc/omp-general.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,8 @@ expr_uses_parm_decl (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
13021302
it is correct or error_mark_node otherwise. */
13031303

13041304
tree
1305-
omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p)
1305+
omp_check_context_selector (location_t loc, tree ctx,
1306+
enum omp_ctx_directive directive)
13061307
{
13071308
bool tss_seen[OMP_TRAIT_SET_LAST], ts_seen[OMP_TRAIT_LAST];
13081309

@@ -1398,7 +1399,7 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p)
13981399

13991400
/* This restriction is documented in the spec in the section
14001401
for the metadirective "when" clause (7.4.1 in the 5.2 spec). */
1401-
if (metadirective_p
1402+
if (directive == OMP_CTX_METADIRECTIVE
14021403
&& ts_code == OMP_TRAIT_CONSTRUCT_SIMD
14031404
&& OMP_TS_PROPERTIES (ts))
14041405
{
@@ -1408,10 +1409,21 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p)
14081409
return error_mark_node;
14091410
}
14101411

1412+
/* "simd" is not allowed at all in "begin declare variant"
1413+
selectors. */
1414+
if (directive == OMP_CTX_BEGIN_DECLARE_VARIANT
1415+
&& ts_code == OMP_TRAIT_CONSTRUCT_SIMD)
1416+
{
1417+
error_at (loc,
1418+
"the %<simd%> selector is not permitted in a "
1419+
"%<begin declare variant%> context selector");
1420+
return error_mark_node;
1421+
}
1422+
14111423
/* Reject expressions that reference parameter variables in
14121424
"declare variant", as this is not yet implemented. FIXME;
14131425
see PR middle-end/113904. */
1414-
if (!metadirective_p
1426+
if (directive != OMP_CTX_METADIRECTIVE
14151427
&& (ts_code == OMP_TRAIT_DEVICE_NUM
14161428
|| ts_code == OMP_TRAIT_USER_CONDITION))
14171429
{

gcc/omp-general.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,12 @@ extern tree find_combined_omp_for (tree *, int *, void *);
194194
extern poly_uint64 omp_max_vf (bool);
195195
extern int omp_max_simt_vf (void);
196196
extern const char *omp_context_name_list_prop (tree);
197+
enum omp_ctx_directive
198+
{ OMP_CTX_DECLARE_VARIANT,
199+
OMP_CTX_BEGIN_DECLARE_VARIANT,
200+
OMP_CTX_METADIRECTIVE };
197201
extern tree omp_check_context_selector (location_t loc, tree ctx,
198-
bool metadirective_p);
202+
enum omp_ctx_directive directive);
199203
extern void omp_mark_declare_variant (location_t loc, tree variant,
200204
tree construct);
201205
extern int omp_context_selector_matches (tree, tree, bool);

0 commit comments

Comments
 (0)