diff options
author | Tobias Burnus <tobias@codesourcery.com> | 2020-04-08 09:39:43 +0200 |
---|---|---|
committer | Tobias Burnus <tobias@codesourcery.com> | 2020-04-08 09:39:43 +0200 |
commit | 13e41d8b9d3d7598c72c38acc86a3d97046c8373 (patch) | |
tree | 90000a02958e8b0e36e120c7afcc9b6e839b4c04 /gcc/cp | |
parent | 38c3017f257484a6739e2fba821d95794f7f175c (diff) | |
download | gcc-13e41d8b9d3d7598c72c38acc86a3d97046c8373.zip gcc-13e41d8b9d3d7598c72c38acc86a3d97046c8373.tar.gz gcc-13e41d8b9d3d7598c72c38acc86a3d97046c8373.tar.bz2 |
[C/C++, OpenACC] Reject vars of different scope in acc declare (PR94120)
gcc/c/
PR middle-end/94120
* c-decl.c (c_check_in_current_scope): New function.
* c-tree.h (c_check_in_current_scope): Declare it.
* c-parser.c (c_parser_oacc_declare): Add check that variables
are declared in the same scope as the directive. Fix handling
of namespace vars.
gcc/cp/
PR middle-end/94120
* paser.c (cp_parser_oacc_declare): Add check that variables
are declared in the same scope as the directive.
gcc/testsuite/
PR middle-end/94120
* c-c++-common/goacc/declare-pr94120.c: New.
* g++.dg/declare-pr94120.C: New.
libgomp/testsuite/
PR middle-end/94120
* libgomp.oacc-c++/declare-pr94120.C: New.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 21 |
2 files changed, 25 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 31f1fc4..561eb4e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-04-08 Tobias Burnus <tobias@codesourcery.com> + + PR middle-end/94120 + * paser.c (cp_parser_oacc_declare): Add check that variables + are declared in the same scope as the directive. + 2020-04-07 Jason Merrill <jason@redhat.com> PR c++/94480 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a95d431..fec5203 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -40906,6 +40906,7 @@ cp_parser_oacc_declare (cp_parser *parser, cp_token *pragma_tok) { tree clauses, stmt; bool error = false; + bool found_in_scope = global_bindings_p (); clauses = cp_parser_oacc_all_clauses (parser, OACC_DECLARE_CLAUSE_MASK, "#pragma acc declare", pragma_tok, true); @@ -40978,6 +40979,22 @@ cp_parser_oacc_declare (cp_parser *parser, cp_token *pragma_tok) break; } + if (!found_in_scope) + for (tree d = current_binding_level->names; d; d = TREE_CHAIN (d)) + if (d == decl) + { + found_in_scope = true; + break; + } + if (!found_in_scope) + { + error_at (loc, + "%qD must be a variable declared in the same scope as " + "%<#pragma acc declare%>", decl); + error = true; + continue; + } + if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)) || lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (decl))) @@ -40999,7 +41016,7 @@ cp_parser_oacc_declare (cp_parser *parser, cp_token *pragma_tok) DECL_ATTRIBUTES (decl) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl)); - if (global_bindings_p ()) + if (current_binding_level->kind == sk_namespace) { symtab_node *node = symtab_node::get (decl); if (node != NULL) @@ -41016,7 +41033,7 @@ cp_parser_oacc_declare (cp_parser *parser, cp_token *pragma_tok) } } - if (error || global_bindings_p ()) + if (error || current_binding_level->kind == sk_namespace) return NULL_TREE; stmt = make_node (OACC_DECLARE); |