From dca06024e877e37e3631bd6a378c3945317dae85 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 20 Mar 2018 15:48:00 +0000 Subject: [PATCH] Set dso_local for CFConstantStringClassReference. This one cannot use setGVProperties since it has special logic for when it is dllimport or not. llvm-svn: 327993 --- clang/lib/CodeGen/CodeGenModule.cpp | 14 +++++++------- clang/test/CodeGen/cfstring-windows.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 310fb8e1904c..307ef23dd66b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3810,14 +3810,13 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { if (!CFConstantStringClassRef) { llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy); Ty = llvm::ArrayType::get(Ty, 0); - llvm::Constant *GV = - CreateRuntimeVariable(Ty, "__CFConstantStringClassReference"); + llvm::GlobalValue *GV = cast( + CreateRuntimeVariable(Ty, "__CFConstantStringClassReference")); if (getTriple().isOSBinFormatCOFF()) { IdentifierInfo &II = getContext().Idents.get(GV->getName()); TranslationUnitDecl *TUDecl = getContext().getTranslationUnitDecl(); DeclContext *DC = TranslationUnitDecl::castToDeclContext(TUDecl); - llvm::GlobalValue *CGV = cast(GV); const VarDecl *VD = nullptr; for (const auto &Result : DC->lookup(&II)) @@ -3825,13 +3824,14 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { break; if (!VD || !VD->hasAttr()) { - CGV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); - CGV->setLinkage(llvm::GlobalValue::ExternalLinkage); + GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); + GV->setLinkage(llvm::GlobalValue::ExternalLinkage); } else { - CGV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); - CGV->setLinkage(llvm::GlobalValue::ExternalLinkage); + GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); + GV->setLinkage(llvm::GlobalValue::ExternalLinkage); } } + setDSOLocal(GV); // Decay array -> ptr CFConstantStringClassRef = diff --git a/clang/test/CodeGen/cfstring-windows.c b/clang/test/CodeGen/cfstring-windows.c index 554c4d9982e9..fe7511eae141 100644 --- a/clang/test/CodeGen/cfstring-windows.c +++ b/clang/test/CodeGen/cfstring-windows.c @@ -31,7 +31,7 @@ __declspec(dllimport) long __CFConstantStringClassReference[]; typedef struct __CFString *CFStringRef; const CFStringRef string = (CFStringRef)__builtin___CFStringMakeConstantString("string"); -// CHECK-CF-IN-CF-DECL: @__CFConstantStringClassReference = external dllexport global [0 x i32] +// CHECK-CF-IN-CF-DECL: @__CFConstantStringClassReference = external dso_local dllexport global [0 x i32] // CHECK-CF-IN-CF-DEFN: @__CFConstantStringClassReference = common dso_local dllexport global [32 x i32] // CHECK-CF: @__CFConstantStringClassReference = external dllimport global [0 x i32] // CHECK-CF-EXTERN: @__CFConstantStringClassReference = external dllimport global [0 x i32]