[cfe-commits] r129410 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGenObjC/constant-strings.m

Daniel Dunbar daniel at zuster.org
Tue Apr 12 16:30:52 PDT 2011


Author: ddunbar
Date: Tue Apr 12 18:30:52 2011
New Revision: 129410

URL: http://llvm.org/viewvc/llvm-project?rev=129410&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGenObjC/constant-strings.m

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=129410&r1=129409&r2=129410&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Apr 12 18:30:52 2011
@@ -1693,6 +1693,9 @@
   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 @@
   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);
   

Modified: cfe/trunk/test/CodeGenObjC/constant-strings.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/constant-strings.m?rev=129410&r1=129409&r2=129410&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/constant-strings.m (original)
+++ cfe/trunk/test/CodeGenObjC/constant-strings.m Tue Apr 12 18:30:52 2011
@@ -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!";
 





More information about the cfe-commits mailing list