From 803d307a5385059b1a84dfe9706ab158c80a20dc Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 17 Jan 2011 22:11:21 +0000 Subject: [PATCH] merge strings created by const NSConstantString *appKey = @"MyApp"; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123680 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 1 + test/CodeGenObjC/ns-constant-strings.m | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 8ae31f7750..0564372a4e 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1681,6 +1681,7 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) { llvm::GlobalVariable *GV = new llvm::GlobalVariable(getModule(), C->getType(), isConstant, Linkage, C, ".str"); + GV->setUnnamedAddr(true); if (isUTF16) { CharUnits Align = getContext().getTypeAlignInChars(getContext().ShortTy); GV->setAlignment(Align.getQuantity()); diff --git a/test/CodeGenObjC/ns-constant-strings.m b/test/CodeGenObjC/ns-constant-strings.m index 3ef5f55842..389132bd05 100644 --- a/test/CodeGenObjC/ns-constant-strings.m +++ b/test/CodeGenObjC/ns-constant-strings.m @@ -31,3 +31,9 @@ int main() { // CHECK-FRAGILE: @_NSConstantStringClassReference = external global // CHECK-NONFRAGILE: @"OBJC_CLASS_$_NSConstantString" = external global + +// CHECK-FRAGILE: @.str = private unnamed_addr constant [6 x i8] c"MyApp\00" +// CHECK-FRAGILE: @.str1 = private unnamed_addr constant [7 x i8] c"MyApp1\00" + +// CHECK-NONFRAGILE: @.str = private unnamed_addr constant [6 x i8] c"MyApp\00" +// CHECK-NONFRAGILE: @.str1 = private unnamed_addr constant [7 x i8] c"MyApp1\00" -- 2.40.0