[llvm] [llvm][ir]: fix llc crashes on function definitions with label parameters (PR #136285)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 18 07:33:18 PDT 2025


https://github.com/YLChenZ updated https://github.com/llvm/llvm-project/pull/136285

>From 56afe811a36b87ccbca91a651f076ba14b832e3e Mon Sep 17 00:00:00 2001
From: YLChenZ <chentongyongcz at gmail.com>
Date: Fri, 18 Apr 2025 16:32:08 +0800
Subject: [PATCH 1/2] [llvm][ir]: fix llc crashes on function definitions with
 label parameters

---
 llvm/lib/IR/Verifier.cpp                  | 2 ++
 llvm/test/Verifier/invalid-label-param.ll | 7 +++++++
 2 files changed, 9 insertions(+)
 create mode 100644 llvm/test/Verifier/invalid-label-param.ll

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 35c4d60cf325e..274c60af52e76 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2931,6 +2931,8 @@ void Verifier::visitFunction(const Function &F) {
           FT->getParamType(i));
     Check(Arg.getType()->isFirstClassType(),
           "Function arguments must have first-class types!", &Arg);
+    Check(!Arg.getType()->isLabelTy(),
+          "Function argument cannot be of label type!", &Arg);
     if (!IsIntrinsic) {
       Check(!Arg.getType()->isMetadataTy(),
             "Function takes metadata but isn't an intrinsic", &Arg, &F);
diff --git a/llvm/test/Verifier/invalid-label-param.ll b/llvm/test/Verifier/invalid-label-param.ll
new file mode 100644
index 0000000000000..6654c81a1754c
--- /dev/null
+++ b/llvm/test/Verifier/invalid-label-param.ll
@@ -0,0 +1,7 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+define void @invalid_arg_type(label %p) {
+; CHECK: Function argument cannot be of label type!
+  ret void
+}
+

>From d7f2c089675e505dd5ec3cc2f5e7f4904eb194f3 Mon Sep 17 00:00:00 2001
From: YLChenZ <chentongyongcz at gmail.com>
Date: Fri, 18 Apr 2025 22:31:33 +0800
Subject: [PATCH 2/2] add test for call site.

---
 llvm/lib/IR/Verifier.cpp                  |  2 +-
 llvm/test/Verifier/invalid-label-param.ll | 11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 274c60af52e76..8afe360d088bc 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2932,7 +2932,7 @@ void Verifier::visitFunction(const Function &F) {
     Check(Arg.getType()->isFirstClassType(),
           "Function arguments must have first-class types!", &Arg);
     Check(!Arg.getType()->isLabelTy(),
-          "Function argument cannot be of label type!", &Arg);
+          "Function argument cannot be of label type!", &Arg, &F);
     if (!IsIntrinsic) {
       Check(!Arg.getType()->isMetadataTy(),
             "Function takes metadata but isn't an intrinsic", &Arg, &F);
diff --git a/llvm/test/Verifier/invalid-label-param.ll b/llvm/test/Verifier/invalid-label-param.ll
index 6654c81a1754c..c89ce99ce1e9f 100644
--- a/llvm/test/Verifier/invalid-label-param.ll
+++ b/llvm/test/Verifier/invalid-label-param.ll
@@ -1,7 +1,14 @@
 ; RUN: not llvm-as < %s 2>&1 | FileCheck %s
 
-define void @invalid_arg_type(label %p) {
-; CHECK: Function argument cannot be of label type!
+define void @invalid_arg_type(i32 %0) {
+1:
+  call void @foo(label %1)
   ret void
 }
 
+declare void @foo(label)
+; CHECK: Function argument cannot be of label type!
+; CHECK-NEXT: label %0
+; CHECK-NEXT: ptr @foo
+
+



More information about the llvm-commits mailing list