-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-llvm-ir Author: None (YLChenZ) ChangesCloses #136144. After the patch: ; label-crash.ll
define void @<!-- -->test(label %0) {
1:
ret void
}
Full diff: https://github.com/llvm/llvm-project/pull/136285.diff 2 Files Affected:
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(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should allow it for asm, see https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/X86/asm-block-labels.ll
There was a problem hiding this comment.
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.
There was a problem hiding this 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 | ||
} | ||
|
There was a problem hiding this comment.
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)
@phoebewang Done. |
…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 ```
…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 ```
…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 ```
Closes #136144.
After the patch: