From b4dd6d24d7567869e66e901b02d886095b87525d Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Wed, 29 Aug 2018 20:41:37 +0000 Subject: [OPENMP] Do not create offloading entry for declare target variables declarations. We should not create offloading entries for declare target var declarations as it causes compiler crash. llvm-svn: 340968 --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CGOpenMPRuntime.cpp') diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 050f4a616c3..6c37c6cf115 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -3989,6 +3989,9 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() { CGM.getDiags().Report(DiagID); continue; } + // The vaiable has no definition - no need to add the entry. + if (CE->getVarSize().isZero()) + continue; break; } case OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryLink: @@ -8108,7 +8111,12 @@ void CGOpenMPRuntime::registerTargetGlobalVariable(const VarDecl *VD, case OMPDeclareTargetDeclAttr::MT_To: Flags = OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryTo; VarName = CGM.getMangledName(VD); - VarSize = CGM.getContext().getTypeSizeInChars(VD->getType()); + if (VD->hasDefinition(CGM.getContext()) != VarDecl::DeclarationOnly) { + VarSize = CGM.getContext().getTypeSizeInChars(VD->getType()); + assert(!VarSize.isZero() && "Expected non-zero size of the variable"); + } else { + VarSize = CharUnits::Zero(); + } Linkage = CGM.getLLVMLinkageVarDefinition(VD, /*IsConstant=*/false); // Temp solution to prevent optimizations of the internal variables. if (CGM.getLangOpts().OpenMPIsDevice && !VD->isExternallyVisible()) { -- cgit v1.2.3