[llvm-commits] [llvm] r143289 - in /llvm/trunk: lib/Transforms/Scalar/SimplifyLibCalls.cpp test/Transforms/SimplifyLibCalls/Printf.ll

Benjamin Kramer benny.kra at googlemail.com
Sat Oct 29 12:43:31 PDT 2011


Author: d0k
Date: Sat Oct 29 14:43:31 2011
New Revision: 143289

URL: http://llvm.org/viewvc/llvm-project?rev=143289&view=rev
Log:
SimplifyLibCalls: Use IRBuilder.CreateGlobalString when creating a string for printf->puts, which correctly sets the unnamed_addr bit on the resulting GlobalVariable.

Fixes PR11264.

Modified:
    llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
    llvm/trunk/test/Transforms/SimplifyLibCalls/Printf.ll

Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=143289&r1=143288&r2=143289&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Sat Oct 29 14:43:31 2011
@@ -1123,10 +1123,8 @@
       // Create a string literal with no \n on it.  We expect the constant merge
       // pass to be run after this pass, to merge duplicate strings.
       FormatStr.erase(FormatStr.end()-1);
-      Constant *C = ConstantArray::get(*Context, FormatStr, true);
-      C = new GlobalVariable(*Callee->getParent(), C->getType(), true,
-                             GlobalVariable::InternalLinkage, C, "str");
-      EmitPutS(C, B, TD);
+      Value *GV = B.CreateGlobalString(FormatStr, "str");
+      EmitPutS(GV, B, TD);
       return CI->use_empty() ? (Value*)CI :
                     ConstantInt::get(CI->getType(), FormatStr.size()+1);
     }

Modified: llvm/trunk/test/Transforms/SimplifyLibCalls/Printf.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyLibCalls/Printf.ll?rev=143289&r1=143288&r2=143289&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyLibCalls/Printf.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyLibCalls/Printf.ll Sat Oct 29 14:43:31 2011
@@ -1,9 +1,10 @@
-; RUN: opt < %s -simplify-libcalls -S -o %t
-; RUN: FileCheck < %t %s
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
 
 @str = internal constant [13 x i8] c"hello world\0A\00"         ; <[13 x i8]*> [#uses=1]
 @str1 = internal constant [2 x i8] c"h\00"              ; <[2 x i8]*> [#uses=1]
 
+; CHECK: internal unnamed_addr constant [12 x i8] c"hello world\00"
+
 declare i32 @printf(i8*, ...)
 
 ; CHECK: define void @f0





More information about the llvm-commits mailing list