[cfe-commits] r147845 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/cfstring.c

Bill Wendling isanbard at gmail.com
Tue Jan 10 00:46:39 PST 2012


Author: void
Date: Tue Jan 10 02:46:39 2012
New Revision: 147845

URL: http://llvm.org/viewvc/llvm-project?rev=147845&view=rev
Log:
The `-fwritable-strings' flag doesn't make the backing store strings of all
CFStrings writable.

The strings (both Unicode and ASCII) should reside in a read-only section. E.g.,
__TEXT,__cstring instead of __DATA,__data. This is done by making the global
variable created for the strings constant despite the value of that flag.
<rdar://problem/10657500>

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/cfstring.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=147845&r1=147844&r2=147845&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Jan 10 02:46:39 2012
@@ -1848,24 +1848,20 @@
   llvm::Constant *C = llvm::ConstantArray::get(VMContext, Entry.getKey().str());
 
   llvm::GlobalValue::LinkageTypes Linkage;
-  bool isConstant;
-  if (isUTF16) {
+  if (isUTF16)
     // FIXME: why do utf strings get "_" labels instead of "L" labels?
     Linkage = llvm::GlobalValue::InternalLinkage;
-    // Note: -fwritable-strings doesn't make unicode CFStrings writable, but
-    // does make plain ascii ones writable.
-    isConstant = true;
-  } else {
+  else
     // FIXME: With OS X ld 123.2 (xcode 4) and LTO we would get a linker error
     // when using private linkage. It is not clear if this is a bug in ld
     // or a reasonable new restriction.
     Linkage = llvm::GlobalValue::LinkerPrivateLinkage;
-    isConstant = !Features.WritableStrings;
-  }
   
+  // Note: -fwritable-strings doesn't make the backing store strings of
+  // CFStrings writable. (See <rdar://problem/10657500>)
   llvm::GlobalVariable *GV =
-    new llvm::GlobalVariable(getModule(), C->getType(), isConstant, Linkage, C,
-                             ".str");
+    new llvm::GlobalVariable(getModule(), C->getType(), /*isConstant=*/true,
+                             Linkage, C, ".str");
   GV->setUnnamedAddr(true);
   if (isUTF16) {
     CharUnits Align = getContext().getTypeAlignInChars(getContext().ShortTy);

Modified: cfe/trunk/test/CodeGen/cfstring.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfstring.c?rev=147845&r1=147844&r2=147845&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/cfstring.c (original)
+++ cfe/trunk/test/CodeGen/cfstring.c Tue Jan 10 02:46:39 2012
@@ -1,4 +1,14 @@
 // RUN: %clang_cc1 -emit-llvm %s -o %t
+
+// <rdar://problem/10657500>: Check that the backing store of CFStrings are
+// constant with the -fwritable-strings flag.
+//
+// RUN: %clang_cc1 -fwritable-strings -emit-llvm %s -o - | FileCheck %s
+//
+// CHECK: @.str = linker_private unnamed_addr constant [14 x i8] c"Hello, World!\00", align 1
+// CHECK: @.str1 = linker_private unnamed_addr constant [7 x i8] c"yo joe\00", align 1
+// CHECK: @.str3 = linker_private unnamed_addr constant [16 x i8] c"Goodbye, World!\00", align 1
+
 #define CFSTR __builtin___CFStringMakeConstantString
 
 void f() {





More information about the cfe-commits mailing list