From: Alexey Bataev Date: Mon, 9 Jul 2018 19:58:08 +0000 (+0000) Subject: [OPENMP] Do not mark local variables as declare target. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=500eccb77e6a768d61ce43490a3e1842466d75df;p=clang [OPENMP] Do not mark local variables as declare target. When the parsing of the functions happens inside of the declare target region, we may erroneously mark local variables as declare target thought they are not. This attribute can be applied only to global variables. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336592 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 6fb0125e6e..f5a1d0b222 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -13012,8 +13012,12 @@ void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, return; SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); SourceLocation SL = E ? E->getLocStart() : D->getLocation(); - // 2.10.6: threadprivate variable cannot appear in a declare target directive. if (auto *VD = dyn_cast(D)) { + // Only global variables can be marked as declare target. + if (VD->isLocalVarDeclOrParm()) + return; + // 2.10.6: threadprivate variable cannot appear in a declare target + // directive. if (DSAStack->isThreadPrivate(VD)) { Diag(SL, diag::err_omp_threadprivate_in_target); reportOriginalDsa(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); diff --git a/test/OpenMP/dump.cpp b/test/OpenMP/dump.cpp index f54d25f197..28da82b3b8 100644 --- a/test/OpenMP/dump.cpp +++ b/test/OpenMP/dump.cpp @@ -63,7 +63,22 @@ struct S { #pragma omp declare simd inbranch void foo(); -// CHECK: `-FunctionDecl {{.+}} col:6 foo 'void ()' +// CHECK: |-FunctionDecl {{.+}} col:6 foo 'void ()' // CHECK-NEXT: |-OMPDeclareSimdDeclAttr {{.+}} Implicit BS_Inbranch // CHECK: `-OMPDeclareSimdDeclAttr {{.+}} Implicit BS_Undefined +#pragma omp declare target +int bar() { + int f; + return f; +} +#pragma omp end declare target + +// CHECK: `-FunctionDecl {{.+}} line:71:5 bar 'int ()' +// CHECK-NEXT: |-CompoundStmt {{.+}} +// CHECK-NEXT: | |-DeclStmt {{.+}} +// CHECK-NEXT: | | `-VarDecl {{.+}} col:7 used f 'int' +// CHECK-NEXT: | `-ReturnStmt {{.+}} +// CHECK-NEXT: | `-ImplicitCastExpr {{.+}} 'int' +// CHECK-NEXT: | `-DeclRefExpr {{.+}} 'int' lvalue Var {{.+}} 'f' 'int' +// CHECK-NEXT: `-OMPDeclareTargetDeclAttr {{.+}} <> Implicit MT_To