Skip to content

Commit 2d62ce4

Browse files
authored
[ValueTracking] Remove faulty dereference of "InsertBefore" (#85034)
In 2fe81ed [NFC][RemoveDIs] Insert instruction using iterators in Transforms/ we changed if (*req_idx != *i) return FindInsertedValue(I->getAggregateOperand(), idx_range, - InsertBefore); + *InsertBefore); } but there is no guarantee that is InsertBefore is non-empty at that point, which we e.g can see in the added testcase. Instead just pass on the optional InsertBefore in the recursive call to FindInsertedValue, as we do at several other places already.
1 parent 676c495 commit 2d62ce4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5709,7 +5709,7 @@ llvm::FindInsertedValue(Value *V, ArrayRef<unsigned> idx_range,
57095709
// looking for, then.
57105710
if (*req_idx != *i)
57115711
return FindInsertedValue(I->getAggregateOperand(), idx_range,
5712-
*InsertBefore);
5712+
InsertBefore);
57135713
}
57145714
// If we end up here, the indices of the insertvalue match with those
57155715
// requested (though possibly only partially). Now we recursively look at
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: opt -passes="lint" -S < %s | FileCheck %s
2+
3+
; After 2fe81edef6f0b
4+
; [NFC][RemoveDIs] Insert instruction using iterators in Transforms/
5+
; this crashed in FindInsertedValue when dereferencing an empty
6+
; optional iterator.
7+
; Just see that it doesn't crash anymore.
8+
9+
; CHECK-LABEL: @test1
10+
11+
%struct = type { i32, i32 }
12+
13+
define void @test1() {
14+
entry:
15+
%.fca.1.insert = insertvalue %struct zeroinitializer, i32 0, 1
16+
%0 = extractvalue %struct %.fca.1.insert, 0
17+
%1 = tail call %struct @foo(i32 %0)
18+
ret void
19+
}
20+
21+
declare %struct @foo(i32)
22+

0 commit comments

Comments
 (0)