SimplifyLibCalls: Use IRBuilder.CreateGlobalString when creating a string for printf...
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 29 Oct 2011 19:43:31 +0000 (19:43 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 29 Oct 2011 19:43:31 +0000 (19:43 +0000)
Fixes PR11264.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143289 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/SimplifyLibCalls.cpp
test/Transforms/SimplifyLibCalls/Printf.ll

index fbb9465743ce2c1d1e3224b31c84efe81fbec350..2a00ae1093ba7439c5bd55c6c3a3d668b09b3e1d 100644 (file)
@@ -1123,10 +1123,8 @@ struct PrintFOpt : public LibCallOptimization {
       // 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);
     }
index caea311ba142f4095b604afaaa9c98a862369158..c98e79ae554d700c41f8500a70eb94baaadb250c 100644 (file)
@@ -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