[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 01:44:45 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: None (YLChenZ)

<details>
<summary>Changes</summary>

Closes #<!-- -->136144.

After the patch:
```llvm
; label-crash.ll
define void @<!-- -->test(label %0) {
1:
    ret void
}
```
```
lambda@<!-- -->ubuntu22:~/test$ llc -o out.s label-crash.ll 
Function argument cannot be of label type!
label %0
llc: error: 'label-crash.ll': input module cannot be verified
```

---
Full diff: https://github.com/llvm/llvm-project/pull/136285.diff


2 Files Affected:

- (modified) llvm/lib/IR/Verifier.cpp (+2) 
- (added) llvm/test/Verifier/invalid-label-param.ll (+7) 


``````````diff
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
+}
+

``````````

</details>


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


More information about the llvm-commits mailing list