From 2f5b2671da60692da9dc4593d81456d19ceac145 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Fri, 27 Jul 2018 17:37:32 +0000 Subject: [OPENMP] Static variables on device must be externally visible. Do not mark static variable as internal on the device as they must be visible from the host to be mapped correctly. llvm-svn: 338139 --- clang/lib/AST/ASTContext.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'clang/lib/AST/ASTContext.cpp') diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 9cd08441848..25dc4441aaf 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -9504,6 +9504,21 @@ static GVALinkage basicGVALinkageForFunction(const ASTContext &Context, return GVA_DiscardableODR; } +static bool isDeclareTargetToDeclaration(const Decl *VD) { + for (const Decl *D : VD->redecls()) { + if (!D->hasAttrs()) + continue; + if (const auto *Attr = D->getAttr()) + return Attr->getMapType() == OMPDeclareTargetDeclAttr::MT_To; + } + if (const auto *V = dyn_cast(VD)) { + if (const VarDecl *TD = V->getTemplateInstantiationPattern()) + return isDeclareTargetToDeclaration(TD); + } + + return false; +} + static GVALinkage adjustGVALinkageForAttributes(const ASTContext &Context, const Decl *D, GVALinkage L) { // See http://msdn.microsoft.com/en-us/library/xa0d9ste.aspx @@ -9520,6 +9535,12 @@ static GVALinkage adjustGVALinkageForAttributes(const ASTContext &Context, // visible externally so they can be launched from host. if (L == GVA_DiscardableODR || L == GVA_Internal) return GVA_StrongODR; + } else if (Context.getLangOpts().OpenMP && Context.getLangOpts().OpenMPIsDevice && + isDeclareTargetToDeclaration(D)) { + // Static variables must be visible externally so they can be mapped from + // host. + if (L == GVA_Internal) + return GVA_StrongODR; } return L; } -- cgit v1.2.3