[llvm] [Statepoint] Return undef value for the statepoint of the none token (PR #72552)

Danila Malyutin via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 17 06:30:00 PST 2023


https://github.com/danilaml updated https://github.com/llvm/llvm-project/pull/72552

>From 0dd28a53f0a6ecd56da2f34e071466fe2f8123db Mon Sep 17 00:00:00 2001
From: Danila Malyutin <dmalyutin at azul.com>
Date: Thu, 16 Nov 2023 22:09:49 +0400
Subject: [PATCH 1/2] [Statepoint] Return undef value for the statepoint of the
 none token

Helps avoid the crash in verifier when it tries to print the error. `none` token
might be produced by llvm-reduce, since it's a default value, so by extension
this also fixes llvm-reduce crash, allowing it to just discard invalid IR.
---
 llvm/lib/IR/IntrinsicInst.cpp       |  5 +++++
 llvm/test/Verifier/gc_none_token.ll | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 llvm/test/Verifier/gc_none_token.ll

diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp
index a24ca8d100527d5..77c3bbbb8baecf5 100644
--- a/llvm/lib/IR/IntrinsicInst.cpp
+++ b/llvm/lib/IR/IntrinsicInst.cpp
@@ -870,6 +870,11 @@ const Value *GCProjectionInst::getStatepoint() const {
   if (isa<UndefValue>(Token))
     return Token;
 
+  // Treat none token as if it was undef here
+  if (isa<ConstantTokenNone>(Token)) {
+    return UndefValue::get(Token->getType());
+  }
+
   // This takes care both of relocates for call statepoints and relocates
   // on normal path of invoke statepoint.
   if (!isa<LandingPadInst>(Token))
diff --git a/llvm/test/Verifier/gc_none_token.ll b/llvm/test/Verifier/gc_none_token.ll
new file mode 100644
index 000000000000000..3847f625c4869f8
--- /dev/null
+++ b/llvm/test/Verifier/gc_none_token.ll
@@ -0,0 +1,18 @@
+; RUN: not opt -passes=verify -S %s 2>&1 | FileCheck %s
+; Check that verifier doesn't crash on relocate with none token
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @check_verify_none_token() gc "statepoint-example" {
+
+entry:
+    ret i32 0
+
+unreach:
+    ; CHECK: gc relocate is incorrectly tied to the statepoint
+    ; CHECK: (undef, undef)
+    %token_call = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token none, i32 0, i32 0)
+    ret i32 1
+}
+
+declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32)

>From 8a5d91f0804fa1af58f5235b86922f1b919d831d Mon Sep 17 00:00:00 2001
From: Danila Malyutin <danilaml at users.noreply.github.com>
Date: Fri, 17 Nov 2023 18:29:52 +0400
Subject: [PATCH 2/2] Update llvm/lib/IR/IntrinsicInst.cpp

Co-authored-by: arpilipe <apilipenko at azul.com>
---
 llvm/lib/IR/IntrinsicInst.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp
index 77c3bbbb8baecf5..7a3b708e7400677 100644
--- a/llvm/lib/IR/IntrinsicInst.cpp
+++ b/llvm/lib/IR/IntrinsicInst.cpp
@@ -871,9 +871,8 @@ const Value *GCProjectionInst::getStatepoint() const {
     return Token;
 
   // Treat none token as if it was undef here
-  if (isa<ConstantTokenNone>(Token)) {
+  if (isa<ConstantTokenNone>(Token))
     return UndefValue::get(Token->getType());
-  }
 
   // This takes care both of relocates for call statepoints and relocates
   // on normal path of invoke statepoint.



More information about the llvm-commits mailing list