diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2011-04-12 23:30:52 +0000 |
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2011-04-12 23:30:52 +0000 |
| commit | 9c8cd4c0978d59f53f6f3e42e478e6aa2985e346 (patch) | |
| tree | 81b24dc6e29daa50d72ed67588419d1fa0f29730 | |
| parent | 987164043c1d1b4cd687fa540cb4be8c9a16eb3a (diff) | |
| download | bcm5719-llvm-9c8cd4c0978d59f53f6f3e42e478e6aa2985e346.tar.gz bcm5719-llvm-9c8cd4c0978d59f53f6f3e42e478e6aa2985e346.zip | |
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.
llvm-svn: 129410
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 6 | ||||
| -rw-r--r-- | clang/test/CodeGenObjC/constant-strings.m | 16 |
2 files changed, 20 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index f740f707e07..440fb47295c 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/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/clang/test/CodeGenObjC/constant-strings.m b/clang/test/CodeGenObjC/constant-strings.m index 227694969bf..398981362e0 100644 --- a/clang/test/CodeGenObjC/constant-strings.m +++ b/clang/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!"; |

