[llvm] r301352 - SimplifyLibCalls: Fix crash on memset(notmalloc())
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 25 12:44:26 PDT 2017
Author: matze
Date: Tue Apr 25 14:44:25 2017
New Revision: 301352
URL: http://llvm.org/viewvc/llvm-project?rev=301352&view=rev
Log:
SimplifyLibCalls: Fix crash on memset(notmalloc())
rdar://31520787
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/memset-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=301352&r1=301351&r2=301352&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Tue Apr 25 14:44:25 2017
@@ -842,6 +842,9 @@ static Value *foldMallocMemset(CallInst
// Is the inner call really malloc()?
Function *InnerCallee = Malloc->getCalledFunction();
+ if (!InnerCallee)
+ return nullptr;
+
LibFunc Func;
if (!TLI.getLibFunc(*InnerCallee, Func) || !TLI.has(Func) ||
Func != LibFunc_malloc)
Modified: llvm/trunk/test/Transforms/InstCombine/memset-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/memset-1.ll?rev=301352&r1=301351&r2=301352&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/memset-1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/memset-1.ll Tue Apr 25 14:44:25 2017
@@ -26,6 +26,15 @@ define i8* @pr25892_lite(i32 %size) #0 {
; CHECK-NEXT: ret i8* %calloc
}
+; This should not create a calloc and not crash the compiler.
+; CHECK-LABEL: @notmalloc_memset
+; CHECK-NOT: @calloc
+define i8* @notmalloc_memset(i32 %size, i8*(i32)* %notmalloc) {
+ %call1 = call i8* %notmalloc(i32 %size) #1
+ %call2 = call i8* @memset(i8* %call1, i32 0, i32 %size) #1
+ ret i8* %call2
+}
+
; FIXME: memset(malloc(x), 0, x) -> calloc(1, x)
; This doesn't fire currently because the malloc has more than one use.
More information about the llvm-commits
mailing list