summaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2020-04-08 09:39:43 +0200
committerTobias Burnus <tobias@codesourcery.com>2020-04-08 09:39:43 +0200
commit13e41d8b9d3d7598c72c38acc86a3d97046c8373 (patch)
tree90000a02958e8b0e36e120c7afcc9b6e839b4c04 /gcc/c
parent38c3017f257484a6739e2fba821d95794f7f175c (diff)
[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/c')
-rw-r--r--gcc/c/ChangeLog9
-rw-r--r--gcc/c/c-decl.c8
-rw-r--r--gcc/c/c-parser.c9
-rw-r--r--gcc/c/c-tree.h1
4 files changed, 27 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index d30d2b02b2e..482a01b307a 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,12 @@
+2020-04-08 Tobias Burnus <tobias@codesourcery.com>
+
+ 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.
+
2020-04-07 Jakub Jelinek <jakub@redhat.com>
PR c++/94512
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index b31d99fcfaf..0b7f4376dd3 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -12041,4 +12041,12 @@ c_check_omp_declare_reduction_r (tree *tp, int *, void *data)
return NULL_TREE;
}
+
+bool
+c_check_in_current_scope (tree decl)
+{
+ struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (decl));
+ return b != NULL && B_IN_CURRENT_SCOPE (b);
+}
+
#include "gt-c-c-decl.h"
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 17a28e97ca0..d1c954cd02a 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -16580,6 +16580,15 @@ c_parser_oacc_declare (c_parser *parser)
break;
}
+ if (!c_check_in_current_scope (decl))
+ {
+ 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)))
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h
index 2015827dbb1..94668866fa2 100644
--- a/gcc/c/c-tree.h
+++ b/gcc/c/c-tree.h
@@ -793,6 +793,7 @@ extern tree c_omp_reduction_id (enum tree_code, tree);
extern tree c_omp_reduction_decl (tree);
extern tree c_omp_reduction_lookup (tree, tree);
extern tree c_check_omp_declare_reduction_r (tree *, int *, void *);
+extern bool c_check_in_current_scope (tree);
extern void c_pushtag (location_t, tree, tree);
extern void c_bind (location_t, tree, bool);
extern bool tag_exists_p (enum tree_code, tree);