diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index b5e8a1d22f264..e56503b9d5b61 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -7378,7 +7378,7 @@ static bool handleGuaranteedWellDefinedOps(const Instruction *I, } case Instruction::Ret: if (I->getFunction()->hasRetAttribute(Attribute::NoUndef) && - Handle(I->getOperand(0))) + Handle(cast(I)->getReturnValue())) return true; break; case Instruction::Switch: diff --git a/llvm/test/Analysis/ValueTracking/gh-issue87441-ret-void-crash.ll b/llvm/test/Analysis/ValueTracking/gh-issue87441-ret-void-crash.ll new file mode 100644 index 0000000000000..7b60c27717038 --- /dev/null +++ b/llvm/test/Analysis/ValueTracking/gh-issue87441-ret-void-crash.ll @@ -0,0 +1,45 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 +; RUN: opt -S -passes=inline < %s | FileCheck %s + +define fastcc void @w() { +; CHECK-LABEL: define fastcc void @w() { +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[IF_THEN:%.*]] +; CHECK: land.end.thread: +; CHECK-NEXT: br label [[IF_THEN]] +; CHECK: if.then: +; CHECK-NEXT: [[CONV246:%.*]] = phi i8 [ 0, [[LAND_END_THREAD:%.*]] ], [ 0, [[ENTRY:%.*]] ] +; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr null, align 4 +; CHECK-NEXT: [[DOTFR:%.*]] = freeze i32 [[TMP0]] +; CHECK-NEXT: [[CONV17:%.*]] = trunc i32 [[DOTFR]] to i8 +; CHECK-NEXT: [[CMP21:%.*]] = icmp eq i8 [[CONV246]], [[CONV17]] +; CHECK-NEXT: ret void +; +entry: + br label %if.then + +land.end.thread: ; No predecessors! + br label %if.then + +if.then: ; preds = %land.end.thread, %entry + %conv246 = phi i8 [ 0, %land.end.thread ], [ 0, %entry ] + %0 = load i32, ptr null, align 4 + %.fr = freeze i32 %0 + %conv17 = trunc i32 %.fr to i8 + %cmp21 = icmp eq i8 %conv246, %conv17 + ret void +} + +define noundef i32 @main() { +; CHECK-LABEL: define noundef i32 @main() { +; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr null, align 4 +; CHECK-NEXT: [[DOTFR_I:%.*]] = freeze i32 [[TMP0]] +; CHECK-NEXT: [[CONV17_I:%.*]] = trunc i32 [[DOTFR_I]] to i8 +; CHECK-NEXT: [[CMP21_I:%.*]] = icmp eq i8 0, [[CONV17_I]] +; CHECK-NEXT: ret i32 0 +; +entry: + call fastcc void @w() + ret i32 0 +}