MemoryBuiltins: Fix operator new bits.
authorBenjamin Kramer <benny.kra@googlemail.com>
Tue, 24 Sep 2013 17:15:14 +0000 (17:15 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Tue, 24 Sep 2013 17:15:14 +0000 (17:15 +0000)
We really don't want to optimize malloc return value checks away.

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

lib/Analysis/MemoryBuiltins.cpp
test/Transforms/InstSimplify/call.ll

index 2ec2aec4aa0e959e79906e8d8d39443ceee036f7..b904cb188c4bc4464762e3beeb56489990493a89 100644 (file)
@@ -35,9 +35,9 @@ enum AllocType {
   CallocLike         = 1<<1, // allocates + bzero
   ReallocLike        = 1<<2, // reallocates
   StrDupLike         = 1<<3,
-  OpNewLike          = MallocLike | (1<<4), // allocates; never returns null
-  AllocLike          = MallocLike | CallocLike | StrDupLike,
-  AnyAlloc           = MallocLike | CallocLike | ReallocLike | StrDupLike
+  OpNewLike          = 1<<4, // allocates; never returns null
+  AllocLike          = MallocLike | CallocLike | StrDupLike | OpNewLike,
+  AnyAlloc           = AllocLike | ReallocLike
 };
 
 struct AllocFnsTy {
index aa3b08653ad235019c14abab3c0c75104c190d2f..89d4238101540d59d51363ed718f8d17e3da2498 100644 (file)
@@ -121,3 +121,23 @@ cast.end:                                         ; preds = %cast.notnull, %entr
 }
 
 declare noalias i8* @_Znwm(i64)
+
+define i8* @malloc_can_return_null() {
+entry:
+  %call = tail call noalias i8* @malloc(i64 8)
+  %cmp = icmp eq i8* %call, null
+  br i1 %cmp, label %cast.end, label %cast.notnull
+
+cast.notnull:                                     ; preds = %entry
+  %add.ptr = getelementptr inbounds i8* %call, i64 4
+  br label %cast.end
+
+cast.end:                                         ; preds = %cast.notnull, %entry
+  %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry ]
+  ret i8* %cast.result
+
+; CHECK-LABEL: @malloc_can_return_null
+; CHECK: br i1 %cmp, label %cast.end, label %cast.notnull
+}
+
+declare noalias i8* @malloc(i64)