[llvm] fecfd01 - [Verifier] Allow undef/poison token argument to llvm.experimental.gc.result

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 19 06:51:52 PDT 2022


Author: dbakunevich
Date: 2022-10-19T20:51:21+07:00
New Revision: fecfd012523f963666caeb7e65cca3cd0ec1c159

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

LOG: [Verifier] Allow undef/poison token argument to llvm.experimental.gc.result

As part of the optimization in the unreachable code, we remove
tokens, thereby replacing them with undef/poison in intrinsics.
But the verifier falls on the assertion, within of what it sees
token poison in unreachable code, which in turn is incorrect.

bug: 57871, https://github.com/llvm/llvm-project/issues/57871
Differential Revision: https://reviews.llvm.org/D134427

Added: 
    llvm/test/Verifier/gc_result_token.ll

Modified: 
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 2a19d258e794..de04256282eb 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5230,8 +5230,13 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
   case Intrinsic::experimental_gc_result: {
     Check(Call.getParent()->getParent()->hasGC(),
           "Enclosing function does not use GC.", Call);
+
+    auto *Statepoint = Call.getArgOperand(0);
+    if (isa<UndefValue>(Statepoint))
+      break;
+
     // Are we tied to a statepoint properly?
-    const auto *StatepointCall = dyn_cast<CallBase>(Call.getArgOperand(0));
+    const auto *StatepointCall = dyn_cast<CallBase>(Statepoint);
     const Function *StatepointFn =
         StatepointCall ? StatepointCall->getCalledFunction() : nullptr;
     Check(StatepointFn && StatepointFn->isDeclaration() &&

diff  --git a/llvm/test/Verifier/gc_result_token.ll b/llvm/test/Verifier/gc_result_token.ll
new file mode 100644
index 000000000000..c2de45ddc5aa
--- /dev/null
+++ b/llvm/test/Verifier/gc_result_token.ll
@@ -0,0 +1,21 @@
+; 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 label %label_1
+label_1:
+    ; CHECK: ret void
+    ret void
+
+label_2:
+    ; CHECK: token poison
+    %call = call noundef i32 @llvm.experimental.gc.result.i32(token poison)
+    unreachable
+}   
+
+declare i32 @llvm.experimental.gc.result.i32(token)
+
+declare ptr @P()


        


More information about the llvm-commits mailing list