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

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 18 18:32:43 PDT 2025


Author: YLChenZ
Date: 2025-04-19T09:32:40+08:00
New Revision: b9e11eade7f1c1e2464f9f891d3769d8e48c6509

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

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

Closes #136144.

After the patch:
```llvm
; label-crash.ll
define void @invalid_arg_type(i32 %0) {
1:
  call void @foo(label %1)
  ret void
}

declare void @foo(label)
```
```
lambda at ubuntu22:~/test$ llc -o out.s label-crash.ll 
Function argument cannot be of label type!
label %0
ptr @foo
llc: error: 'label-crash.ll': input module cannot be verified
```

Added: 
    llvm/test/Verifier/invalid-label-param.ll

Modified: 
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 35c4d60cf325e..8afe360d088bc 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, &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
new file mode 100644
index 0000000000000..c89ce99ce1e9f
--- /dev/null
+++ b/llvm/test/Verifier/invalid-label-param.ll
@@ -0,0 +1,14 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+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