diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 070ad5d374168e..0307099344c0d4 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -371,8 +371,8 @@ CodeGenModule::CodeGenModule(ASTContext &C, const llvm::DataLayout &DL = M.getDataLayout(); AllocaInt8PtrTy = llvm::PointerType::get(LLVMContext, DL.getAllocaAddrSpace()); - GlobalsInt8PtrTy = llvm::PointerType::get( - LLVMContext, C.getTargetAddressSpace(GetGlobalVarAddressSpace(nullptr))); + GlobalsInt8PtrTy = + llvm::PointerType::get(LLVMContext, DL.getDefaultGlobalsAddressSpace()); ConstGlobalsPtrTy = llvm::PointerType::get( LLVMContext, C.getTargetAddressSpace(GetGlobalConstantAddressSpace())); ASTAllocaAddressSpace = getTargetCodeGenInfo().getASTAllocaAddressSpace(); @@ -3590,10 +3590,8 @@ ConstantAddress CodeGenModule::GetAddrOfTemplateParamObject( isExternallyVisible(TPO->getLinkageAndVisibility().getLinkage()) ? llvm::GlobalValue::LinkOnceODRLinkage : llvm::GlobalValue::InternalLinkage; - auto *GV = new llvm::GlobalVariable( - getModule(), Init->getType(), - /*isConstant=*/true, Linkage, Init, Name, nullptr, - llvm::GlobalValue::NotThreadLocal, GlobalsInt8PtrTy->getAddressSpace()); + auto *GV = new llvm::GlobalVariable(getModule(), Init->getType(), + /*isConstant=*/true, Linkage, Init, Name); setGVProperties(GV, TPO); if (supportsCOMDAT()) GV->setComdat(TheModule.getOrInsertComdat(GV->getName())); @@ -5044,9 +5042,8 @@ llvm::GlobalVariable *CodeGenModule::CreateOrReplaceCXXRuntimeVariable( } // Create a new variable. - GV = new llvm::GlobalVariable( - getModule(), Ty, /*isConstant=*/true, Linkage, nullptr, Name, nullptr, - llvm::GlobalValue::NotThreadLocal, GlobalsInt8PtrTy->getAddressSpace()); + GV = new llvm::GlobalVariable(getModule(), Ty, /*isConstant=*/true, + Linkage, nullptr, Name); if (OldGV) { // Replace occurrences of the old variable if needed. @@ -5161,7 +5158,7 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) { return LangAS::cuda_device; } - if (LangOpts.OpenMP && OpenMPRuntime) { + if (LangOpts.OpenMP) { LangAS AS; if (OpenMPRuntime->hasAllocateAttributeForGlobalVar(D, AS)) return AS; diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index 5e42e94bf31756..18acf7784f714b 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -3279,9 +3279,7 @@ ItaniumRTTIBuilder::GetAddrOfExternalRTTIDescriptor(QualType Ty) { GV = new llvm::GlobalVariable( CGM.getModule(), CGM.GlobalsInt8PtrTy, - /*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr, Name, - nullptr, llvm::GlobalValue::NotThreadLocal, - CGM.GlobalsInt8PtrTy->getAddressSpace()); + /*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr, Name); const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); CGM.setGVProperties(GV, RD); // Import the typeinfo symbol when all non-inline virtual methods are @@ -3675,17 +3673,8 @@ void ItaniumRTTIBuilder::BuildVTablePointer(const Type *Ty) { if (CGM.getItaniumVTableContext().isRelativeLayout()) VTable = CGM.getModule().getNamedAlias(VTableName); if (!VTable) { - VTable = CGM.GetGlobalValue(VTableName); - if (!VTable) { - llvm::Type *Ty = llvm::ArrayType::get(CGM.GlobalsInt8PtrTy, 0); - // FIXME: External StdLib VTables should be constant as well, but changing - // it *might* constitute a very subtle ABI break. - VTable = new llvm::GlobalVariable( - CGM.getModule(), Ty, - /*isConstant=*/false, llvm::GlobalVariable::ExternalLinkage, nullptr, - VTableName, nullptr, llvm::GlobalValue::NotThreadLocal, - CGM.GlobalsInt8PtrTy->getAddressSpace()); - } + llvm::Type *Ty = llvm::ArrayType::get(CGM.GlobalsInt8PtrTy, 0); + VTable = CGM.getModule().getOrInsertGlobal(VTableName, Ty); } CGM.setDSOLocal(cast(VTable->stripPointerCasts())); @@ -3945,9 +3934,7 @@ llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo( llvm::GlobalVariable *OldGV = M.getNamedGlobal(Name); llvm::GlobalVariable *GV = new llvm::GlobalVariable(M, Init->getType(), - /*isConstant=*/true, Linkage, Init, Name, - nullptr, llvm::GlobalValue::NotThreadLocal, - CGM.GlobalsInt8PtrTy->getAddressSpace()); + /*isConstant=*/true, Linkage, Init, Name); // Export the typeinfo in the same circumstances as the vtable is exported. auto GVDLLStorageClass = DLLStorageClass;