Let the strcat optimizer return the pointer to the start of the buffer,
authorEd Schouten <ed@80386.nl>
Mon, 6 Apr 2009 13:06:48 +0000 (13:06 +0000)
committerEd Schouten <ed@80386.nl>
Mon, 6 Apr 2009 13:06:48 +0000 (13:06 +0000)
instead of the place where it started to perform the string copy.

- PR3661
- Patch by Benjamin Kramer!

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

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

index b878e4b4790f6647c73f442f0c2912912be8a4c6..c84c23340fccadead761f3aea34d3219f6f9bea8 100644 (file)
@@ -514,11 +514,11 @@ struct VISIBILITY_HIDDEN StrCatOpt : public LibCallOptimization {
     // Now that we have the destination's length, we must index into the
     // destination's pointer to get the actual memcpy destination (end of
     // the string .. we're concatenating).
-    Dst = B.CreateGEP(Dst, DstLen, "endptr");
+    Value *CpyDst = B.CreateGEP(Dst, DstLen, "endptr");
     
     // We have enough information to now generate the memcpy call to do the
     // concatenation for us.  Make a memcpy to copy the nul byte with align = 1.
-    EmitMemCpy(Dst, Src, ConstantInt::get(TD->getIntPtrType(), Len+1), 1, B);
+    EmitMemCpy(CpyDst, Src, ConstantInt::get(TD->getIntPtrType(), Len+1), 1, B);
     return Dst;
   }
 };
index a6ef6771b4605b70dbaec04c9dd396365887adc0..89ef4ea49a79b75352f650fe2a8e92894e1f48d6 100644 (file)
@@ -1,6 +1,9 @@
 ; Test that the StrCatOptimizer works correctly
+; PR3661
 ; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | \
 ; RUN:   not grep {call.*strcat}
+; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | \
+; RUN:   grep {puts.*%arg1}
 
 @hello = constant [6 x i8] c"hello\00"         ; <[6 x i8]*> [#uses=1]
 @null = constant [1 x i8] zeroinitializer              ; <[1 x i8]*> [#uses=1]