Calling null is undefined behavior, a call to undef can be trivially
treated as a call to null.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273776
91177308-0d34-0410-b5e6-
96231b3b80d8
}
if (CallInst *CI = dyn_cast<CallInst>(BBI)) {
+ Value *Callee = CI->getCalledValue();
+ if (isa<ConstantPointerNull>(Callee) || isa<UndefValue>(Callee)) {
+ changeToUnreachable(CI, /*UseLLVMTrap=*/false);
+ Changed = true;
+ break;
+ }
if (CI->doesNotReturn()) {
// If we found a call to a no-return function, insert an unreachable
// instruction after it. Make sure there isn't *already* one there
if (I->use_empty())
return false;
- if (C->isNullValue()) {
+ if (C->isNullValue() || isa<UndefValue>(C)) {
// Only look at the first use, avoid hurting compile time with long uselists
User *Use = *I->user_begin();
if (!SI->isVolatile())
return SI->getPointerAddressSpace() == 0 &&
SI->getPointerOperand() == I;
+
+ // A call to null is undefined.
+ if (auto CS = CallSite(Use))
+ return CS.getCalledValue() == I;
}
return false;
}
store i8 2, i8* %ptr.2, align 8
ret void
}
+
+define i32 @test7(i1 %X) {
+entry:
+ br i1 %X, label %if, label %else
+
+if:
+ call void undef()
+ br label %else
+
+else:
+ %phi = phi i32 [ 0, %entry ], [ 1, %if ]
+ ret i32 %phi
+}
+; CHECK-LABEL: define i32 @test7(
+; CHECK-NOT: call
+; CHECK: ret i32 0
+
+define void @test8(i1 %X, void ()* %Y) {
+entry:
+ br i1 %X, label %if, label %else
+
+if:
+ br label %else
+
+else:
+ %phi = phi void ()* [ %Y, %entry ], [ null, %if ]
+ call void %phi()
+ ret void
+}
+; CHECK-LABEL: define void @test8(
+; CHECK: call void %Y(