[llvm] 2d62ce4 - [ValueTracking] Remove faulty dereference of "InsertBefore" (#85034)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 01:58:51 PDT 2024


Author: mikaelholmen
Date: 2024-03-13T09:58:47+01:00
New Revision: 2d62ce4bebe484f7c6855b9ef479e9b398595df9

URL: https://github.com/llvm/llvm-project/commit/2d62ce4bebe484f7c6855b9ef479e9b398595df9
DIFF: https://github.com/llvm/llvm-project/commit/2d62ce4bebe484f7c6855b9ef479e9b398595df9.diff

LOG: [ValueTracking] Remove faulty dereference of "InsertBefore" (#85034)

In 2fe81edef6f
 [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.

Added: 
    llvm/test/Analysis/Lint/crash_empty_iterator.ll

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 371ad41ee96562..8a4a2c4f92a0dc 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -5709,7 +5709,7 @@ llvm::FindInsertedValue(Value *V, ArrayRef<unsigned> idx_range,
       // looking for, then.
       if (*req_idx != *i)
         return FindInsertedValue(I->getAggregateOperand(), idx_range,
-                                 *InsertBefore);
+                                 InsertBefore);
     }
     // If we end up here, the indices of the insertvalue match with those
     // requested (though possibly only partially). Now we recursively look at

diff  --git a/llvm/test/Analysis/Lint/crash_empty_iterator.ll b/llvm/test/Analysis/Lint/crash_empty_iterator.ll
new file mode 100644
index 00000000000000..2fbecbcef5cfb4
--- /dev/null
+++ b/llvm/test/Analysis/Lint/crash_empty_iterator.ll
@@ -0,0 +1,22 @@
+; RUN: opt -passes="lint" -S < %s | FileCheck %s
+
+; After 2fe81edef6f0b
+;  [NFC][RemoveDIs] Insert instruction using iterators in Transforms/
+; this crashed in FindInsertedValue when dereferencing an empty
+; optional iterator.
+; Just see that it doesn't crash anymore.
+
+; CHECK-LABEL: @test1
+
+%struct = type { i32, i32 }
+
+define void @test1() {
+entry:
+  %.fca.1.insert = insertvalue %struct zeroinitializer, i32 0, 1
+  %0 = extractvalue %struct %.fca.1.insert, 0
+  %1 = tail call %struct @foo(i32 %0)
+  ret void
+}
+
+declare %struct @foo(i32)
+


        


More information about the llvm-commits mailing list