[PATCH] D134427: Fixed bug on token undef/poison in unreachable code

Dmitry Bakunevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 04:34:55 PDT 2022


dbakunevich created this revision.
dbakunevich added reviewers: mkazantsev, apilipenko.
Herald added a subscriber: hiraditya.
Herald added a project: All.
dbakunevich requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The verifier checks that the token of “experimental_gc_result” intrinsic is some kind of call. Therefore, checks that the token is not poison or undef.
See: https://github.com/llvm/llvm-project/issues/57871


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134427

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/test/Verifier/gc_result_token.ll


Index: llvm/test/Verifier/gc_result_token.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/gc_result_token.ll
@@ -0,0 +1,22 @@
+; RUN: opt -S -passes=verify < %s | FileCheck %s
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @foo() gc "statepoint_example" personality ptr @P {
+; CHECK-NOT: gc.result operand #1 must be from a statepoint   
+entry:
+    br i1 true, label %label_1, label %label_2
+
+label_1:
+    ; CHECK: ret void
+    ret void
+
+label_2:
+    ; CHECK: token poison
+    %a = call noundef i32 @llvm.experimental.gc.result.i32(token poison)
+    unreachable
+}   
+
+declare i32 @llvm.experimental.gc.result.i32(token)
+
+declare ptr @P()
\ No newline at end of file
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -5116,6 +5116,11 @@
   case Intrinsic::experimental_gc_result: {
     Check(Call.getParent()->getParent()->hasGC(),
           "Enclosing function does not use GC.", Call);
+
+    if (isa<UndefValue>(Call.getArgOperand(0)) ||
+        isa<PoisonValue>(Call.getArgOperand(0)))
+      break;
+
     // Are we tied to a statepoint properly?
     const auto *StatepointCall = dyn_cast<CallBase>(Call.getArgOperand(0));
     const Function *StatepointFn =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134427.462133.patch
Type: text/x-patch
Size: 1369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220922/0d15b2c3/attachment.bin>


More information about the llvm-commits mailing list