Skip to content

[ValueTracking] Fix "getOperand() out of range!" assertion crash #87482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnInst>(I)->getReturnValue()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling Handle with a nullptr seems surprising here. I'd add a clause to the if condition to avoid calling Handle instead.

return true;
break;
case Instruction::Switch:
Expand Down
45 changes: 45 additions & 0 deletions llvm/test/Analysis/ValueTracking/gh-issue87441-ret-void-crash.ll
Original file line number Diff line number Diff line change
@@ -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
}