]> granicus.if.org Git - clang/commitdiff
[OpenMP] Diagnose undeclared variables on declare target clause
authorKelvin Li <kkwli0@gmail.com>
Thu, 30 Nov 2017 18:52:06 +0000 (18:52 +0000)
committerKelvin Li <kkwli0@gmail.com>
Thu, 30 Nov 2017 18:52:06 +0000 (18:52 +0000)
Clang asserts on undeclared variables on the to or link clause in the declare
target directive. The patch is to properly diagnose the error.

// foo1 and foo2 are not declared
#pragma omp declare target to(foo1)
#pragma omp declare target link(foo2)

Differential Revision: https://reviews.llvm.org/D40588

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319458 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOpenMP.cpp
test/OpenMP/declare_target_messages.cpp

index 19dffac5f38314f8838d403d3fd5be125873d6dd..fb60ebf23ac9463eb92e3da45c2571b9c292695c 100644 (file)
@@ -1506,7 +1506,7 @@ public:
   explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {}
   bool ValidateCandidate(const TypoCorrection &Candidate) override {
     NamedDecl *ND = Candidate.getCorrectionDecl();
-    if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) {
+    if (ND && (isa<VarDecl>(ND) || isa<FunctionDecl>(ND))) {
       return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(),
                                    SemaRef.getCurScope());
     }
index bbffc0eeeb2a068425375f0e55d238fc12ae7f1a..7b4ba02bd4f7bda7f7434052ab9b75e682072039 100644 (file)
@@ -13,6 +13,10 @@ void f();
 
 #pragma omp declare target map(a) // expected-error {{unexpected 'map' clause, only 'to' or 'link' clauses expected}}
 
+#pragma omp declare target to(foo1) // expected-error {{use of undeclared identifier 'foo1'}}
+
+#pragma omp declare target link(foo2) // expected-error {{use of undeclared identifier 'foo2'}}
+
 void c(); // expected-warning {{declaration is not declared in any declare target region}}
 
 extern int b;