From c00d142c7858007a9c8cca3298a6d1c4623f6d2d Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Tue, 9 Feb 2016 09:41:09 +0000 Subject: [PATCH] [OPENMP] Allow to reference threadprivate variable in same directive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260213 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaOpenMP.cpp | 10 ++++++++-- test/OpenMP/threadprivate_messages.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index d4c1f98c99..3ba5daa030 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -1179,8 +1179,10 @@ ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, } QualType ExprType = VD->getType().getNonReferenceType(); - ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); - return DE; + return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), + SourceLocation(), VD, + /*RefersToEnclosingVariableOrCapture=*/false, + Id.getLoc(), ExprType, VK_LValue); } Sema::DeclGroupPtrTy @@ -1230,6 +1232,10 @@ Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef VarList) { VarDecl *VD = cast(DE->getDecl()); SourceLocation ILoc = DE->getExprLoc(); + // Mark variable as used. + VD->setReferenced(); + VD->markUsed(Context); + QualType QType = VD->getType(); if (QType->isDependentType() || QType->isInstantiationDependentType()) { // It will be analyzed later. diff --git a/test/OpenMP/threadprivate_messages.cpp b/test/OpenMP/threadprivate_messages.cpp index 8c442f47ad..9775bfa458 100644 --- a/test/OpenMP/threadprivate_messages.cpp +++ b/test/OpenMP/threadprivate_messages.cpp @@ -70,7 +70,7 @@ class TestClass { namespace ns { int m; -#pragma omp threadprivate (m) +#pragma omp threadprivate (m, m) } #pragma omp threadprivate (m) // expected-error {{use of undeclared identifier 'm'}} #pragma omp threadprivate (ns::m) -- 2.50.1