summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp6
-rw-r--r--clang/test/CodeGenObjC/constant-strings.m16
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!";
OpenPOWER on IntegriCloud