aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2011-04-12 23:30:52 +0000
committerDaniel Dunbar <daniel@zuster.org>2011-04-12 23:30:52 +0000
commitf7e903d7a30891083420c07ebeed281726a101d6 (patch)
treecfa173fd495fd26db7598c28828c15c5530e1acc
parent6591271275f7a3db357f3cb7af37ef86e800e4ba (diff)
IRgen/Obj-C: Emit CFStrings and NSStrings with the alignment of the char type,
there is no reason to align them higher. - This roughly matches llvm-gcc's r126913. - It is an open question whether or not we should do this for cstring's in general (code size vs optimization potential), for now we just match llvm-gcc until someone wants to run some experiments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129410 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CodeGenModule.cpp6
-rw-r--r--test/CodeGenObjC/constant-strings.m16
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index f740f707e0..440fb47295 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1693,6 +1693,9 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
if (isUTF16) {
CharUnits Align = getContext().getTypeAlignInChars(getContext().ShortTy);
GV->setAlignment(Align.getQuantity());
+ } else {
+ CharUnits Align = getContext().getTypeAlignInChars(getContext().CharTy);
+ GV->setAlignment(Align.getQuantity());
}
Fields[2] = llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2);
@@ -1785,6 +1788,9 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) {
if (isUTF16) {
CharUnits Align = getContext().getTypeAlignInChars(getContext().ShortTy);
GV->setAlignment(Align.getQuantity());
+ } else {
+ CharUnits Align = getContext().getTypeAlignInChars(getContext().CharTy);
+ GV->setAlignment(Align.getQuantity());
}
Fields[1] = llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2);
diff --git a/test/CodeGenObjC/constant-strings.m b/test/CodeGenObjC/constant-strings.m
index 227694969b..398981362e 100644
--- a/test/CodeGenObjC/constant-strings.m
+++ b/test/CodeGenObjC/constant-strings.m
@@ -1,6 +1,18 @@
// RUN: %clang_cc1 -emit-llvm -o %t %s
-// RUN: %clang_cc1 -fgnu-runtime -emit-llvm -o %t %s && grep NXConstantString %t | count 1
-// RUN: %clang_cc1 -fgnu-runtime -fconstant-string-class NSConstantString -emit-llvm -o %t %s && grep NSConstantString %t | count 1
+// RUN: FileCheck --check-prefix=CHECK-NEXT < %t %s
+// Check that we set alignment 1 on the string.
+//
+// CHECK-NEXT: @.str = {{.*}}constant [13 x i8] c"Hello World!\00", align 1
+
+// RUN: %clang_cc1 -fgnu-runtime -emit-llvm -o %t %s
+// RUN: FileCheck --check-prefix=CHECK-GNU < %t %s
+// CHECK-GNU: NXConstantString
+// CHECK-GNU-NOT: NXConstantString
+
+// RUN: %clang_cc1 -fgnu-runtime -fconstant-string-class NSConstantString -emit-llvm -o %t %s
+// RUN: FileCheck --check-prefix=CHECK-GNU-WITH-CLASS < %t %s
+// CHECK-GNU-WITH-CLASS: NSConstantString
+// CHECK-GNU-WITH-CLASS-NOT: NSConstantString
id a = @"Hello World!";