[llvm] r267605 - Revert "[SimplifyLibCalls] sprintf doesn't copy null bytes"

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 14:04:47 PDT 2016


Author: majnemer
Date: Tue Apr 26 16:04:47 2016
New Revision: 267605

URL: http://llvm.org/viewvc/llvm-project?rev=267605&view=rev
Log:
Revert "[SimplifyLibCalls] sprintf doesn't copy null bytes"

The destination buffer that sprintf uses is restrict qualified, we do
not need to worry about derived pointers referenced via format
specifiers.

This reverts commit r267580.

Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
    llvm/trunk/test/Transforms/InstCombine/sprintf-1.ll

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=267605&r1=267604&r2=267605&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Tue Apr 26 16:04:47 2016
@@ -1995,10 +1995,9 @@ Value *LibCallSimplifier::optimizeSPrint
     Value *Len = emitStrLen(CI->getArgOperand(2), B, DL, TLI);
     if (!Len)
       return nullptr;
-    B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(2), Len, 1);
-    Value *PtrToNullByte =
-        B.CreateGEP(B.getInt8Ty(), CI->getArgOperand(0), Len, "nul");
-    B.CreateStore(B.getInt8(0), PtrToNullByte);
+    Value *IncLen =
+        B.CreateAdd(Len, ConstantInt::get(Len->getType(), 1), "leninc");
+    B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(2), IncLen, 1);
 
     // The sprintf result is the unincremented number of bytes in the string.
     return B.CreateIntCast(Len, CI->getType(), false);

Modified: llvm/trunk/test/Transforms/InstCombine/sprintf-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sprintf-1.ll?rev=267605&r1=267604&r2=267605&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sprintf-1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sprintf-1.ll Tue Apr 26 16:04:47 2016
@@ -65,9 +65,8 @@ define void @test_simplify5(i8* %dst, i8
   %fmt = getelementptr [3 x i8], [3 x i8]* @percent_s, i32 0, i32 0
   call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, i8* %str)
 ; CHECK-NEXT: [[STRLEN:%[a-z0-9]+]] = call i32 @strlen(i8* %str)
-; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %str, i32 [[STRLEN]], i32 1, i1 false)
-; CHECK-NEXT: [[NUL:%[a-z0-9]+]] = getelementptr i8, i8* %dst, i32 [[STRLEN]]
-; CHECK-NEXT: store i8 0, i8* [[NUL]], align 1
+; CHECK-NEXT: [[LENINC:%[a-z0-9]+]] = add i32 [[STRLEN]], 1
+; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %str, i32 [[LENINC]], i32 1, i1 false)
   ret void
 ; CHECK-NEXT: ret void
 }




More information about the llvm-commits mailing list