Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2025

Conversation

YLChenZ
Copy link
Contributor

@YLChenZ YLChenZ commented Apr 18, 2025

Closes #136144.

After the patch:

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

declare void @foo(label)
lambda@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

@llvmbot
Copy link
Member

llvmbot commented Apr 18, 2025

@llvm/pr-subscribers-llvm-ir

Author: None (YLChenZ)

Changes

Closes #136144.

After the patch:

; 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 --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
+}
+

@@ -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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is checking arguments on the function not calls.

Though really, we should not allow labels as inline asm operands either -- it looks like this is some leftover from an old implementation the predates both blockaddresses and callbr.

Copy link
Contributor

@phoebewang phoebewang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one suggestion.

; CHECK: Function argument cannot be of label type!
ret void
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test for call site, e.g.:

define void @test(i32 %0) {
1:
  call void @foo(label %1)
  ret void
}

declare void @foo(label)

@YLChenZ
Copy link
Contributor Author

YLChenZ commented Apr 18, 2025

@phoebewang Done.

@phoebewang phoebewang merged commit b9e11ea into llvm:main Apr 19, 2025
11 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ters (llvm#136285)

Closes llvm#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@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
```
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ters (llvm#136285)

Closes llvm#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@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
```
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ters (llvm#136285)

Closes llvm#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@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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

llc crashes on function definitions with label parameters
4 participants