From 960ff0810da8fe7bb0059acdc4fdc397440eb245 Mon Sep 17 00:00:00 2001 From: Anastasia Stulova Date: Mon, 15 Jul 2019 11:58:10 +0000 Subject: [OpenCL][PR41727] Prevent ICE on global dtors Pass NULL to pointer arg of __cxa_atexit if addr space is not matching with its param. This doesn't align yet with how dtors are generated that should be changed too. Differential Revision: https://reviews.llvm.org/D62413 llvm-svn: 366059 --- clang/lib/CodeGen/CodeGenModule.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index ea52f0c61fc..ba501d645c2 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3577,8 +3577,12 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D, llvm::Constant * CodeGenModule::CreateRuntimeVariable(llvm::Type *Ty, StringRef Name) { - auto *Ret = - GetOrCreateLLVMGlobal(Name, llvm::PointerType::getUnqual(Ty), nullptr); + auto PtrTy = + getContext().getLangOpts().OpenCL + ? llvm::PointerType::get( + Ty, getContext().getTargetAddressSpace(LangAS::opencl_global)) + : llvm::PointerType::getUnqual(Ty); + auto *Ret = GetOrCreateLLVMGlobal(Name, PtrTy, nullptr); setDSOLocal(cast(Ret->stripPointerCasts())); return Ret; } -- cgit v1.2.3