From d01b74974ba2e87cfc1f05a08ccad54feb9ceb49 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Wed, 15 Aug 2018 19:45:12 +0000 Subject: [OPENMP] FIx processing of declare target variables. The compiler may produce unexpected error messages/crashes when declare target variables were used. Patch fixes problems with the declarations marked as declare target to or link. llvm-svn: 339805 --- clang/lib/CodeGen/CodeGenModule.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 72fa799a541..76527b78c34 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2004,7 +2004,8 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl *Global) { // codegen for global variables, because they may be marked as threadprivate. if (LangOpts.OpenMP && LangOpts.OpenMPUseTLS && getContext().getTargetInfo().isTLSSupported() && isa(Global) && - !isTypeConstant(Global->getType(), false)) + !isTypeConstant(Global->getType(), false) && + !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Global)) return false; return true; @@ -2155,6 +2156,20 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { if (!MustEmitForCuda && VD->isThisDeclarationADefinition() != VarDecl::Definition && !Context.isMSStaticDataMemberInlineDefinition(VD)) { + if (LangOpts.OpenMP) { + // Emit declaration of the must-be-emitted declare target variable. + if (llvm::Optional Res = + OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) { + if (*Res == OMPDeclareTargetDeclAttr::MT_To) { + (void)GetAddrOfGlobalVar(VD); + } else { + assert(*Res == OMPDeclareTargetDeclAttr::MT_Link && + "link claue expected."); + (void)getOpenMPRuntime().getAddrOfDeclareTargetLink(VD); + } + return; + } + } // If this declaration may have caused an inline variable definition to // change linkage, make sure that it's emitted. if (Context.getInlineVariableDefinitionKind(VD) == -- cgit v1.2.3