[PATCH] D40968: [OpenMP] Diagnose function name on the link clause
Kelvin Li via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 7 09:48:01 PST 2017
kkwli0 created this revision.
This patch is to add diagnose when a function name is specified on the link clause. According to the OpenMP spec, only the list items that exclude the function name are allowed on the link clause.
void foo() {}
#pragma omp declare target link(foo)
d2.c:2:33: error: function name is not allowed in 'link' clause
#pragma omp declare target link(foo)
^
d2.c:1:6: note: 'foo' defined here
void foo() {}
^
1 error generated.
https://reviews.llvm.org/D40968
Files:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaOpenMP.cpp
test/OpenMP/declare_target_ast_print.cpp
test/OpenMP/declare_target_messages.cpp
Index: test/OpenMP/declare_target_messages.cpp
===================================================================
--- test/OpenMP/declare_target_messages.cpp
+++ test/OpenMP/declare_target_messages.cpp
@@ -19,6 +19,10 @@
void c(); // expected-warning {{declaration is not declared in any declare target region}}
+void func() {} // expected-note {{'func' defined here}}
+
+#pragma omp declare target link(func) // expected-error {{function name is not allowed in 'link' clause}}
+
extern int b;
struct NonT {
Index: test/OpenMP/declare_target_ast_print.cpp
===================================================================
--- test/OpenMP/declare_target_ast_print.cpp
+++ test/OpenMP/declare_target_ast_print.cpp
@@ -108,9 +108,7 @@
// CHECK: #pragma omp end declare target
int c1, c2, c3;
-void f3() {
-}
-#pragma omp declare target link(c1) link(c2), link(c3, f3)
+#pragma omp declare target link(c1) link(c2), link(c3)
// CHECK: #pragma omp declare target link
// CHECK: int c1;
// CHECK: #pragma omp end declare target
@@ -120,9 +118,6 @@
// CHECK: #pragma omp declare target link
// CHECK: int c3;
// CHECK: #pragma omp end declare target
-// CHECK: #pragma omp declare target link
-// CHECK: void f3()
-// CHECK: #pragma omp end declare target
struct SSSt {
#pragma omp declare target
Index: lib/Sema/SemaOpenMP.cpp
===================================================================
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -12573,6 +12573,11 @@
if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl())))
Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName();
+ if (MT == OMPDeclareTargetDeclAttr::MT_Link && isa<FunctionDecl>(ND)) {
+ Diag(Id.getLoc(), diag::err_omp_function_in_link_clause);
+ Diag(ND->getLocation(), diag::note_defined_here) << ND;
+ }
+
if (!ND->hasAttr<OMPDeclareTargetDeclAttr>()) {
Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT);
ND->addAttr(A);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8709,6 +8709,8 @@
def warn_omp_not_in_target_context : Warning<
"declaration is not declared in any declare target region">,
InGroup<OpenMPTarget>;
+def err_omp_function_in_link_clause : Error<
+ "function name is not allowed in 'link' clause">;
def err_omp_aligned_expected_array_or_ptr : Error<
"argument of aligned clause should be array"
"%select{ or pointer|, pointer, reference to array or reference to pointer}1"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40968.125983.patch
Type: text/x-patch
Size: 2670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171207/242ec3ef/attachment.bin>
More information about the cfe-commits
mailing list