Skip to content

[IR] Don't allow label arguments #137799

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 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Changes to the LLVM IR

* Updated semantics of `llvm.type.checked.load.relative` to match that of
`llvm.load.relative`.
* Inline asm calls no longer accept ``label`` arguments. Use ``callbr`` instead.

Changes to LLVM infrastructure
------------------------------
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3072,6 +3072,8 @@ bool LLParser::parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
Value *V;
if (parseType(ArgTy, ArgLoc))
return true;
if (!FunctionType::isValidArgumentType(ArgTy))
return error(ArgLoc, "invalid type for function argument");

AttrBuilder ArgAttrs(M->getContext());

Expand Down Expand Up @@ -3381,7 +3383,7 @@ bool LLParser::parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
CurValID = ArgID + 1;
}

if (!ArgTy->isFirstClassType())
if (!FunctionType::isValidArgumentType(ArgTy))
return error(TypeLoc, "invalid type for function argument");

ArgList.emplace_back(TypeLoc, ArgTy,
Expand Down
9 changes: 2 additions & 7 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3488,13 +3488,8 @@ void ModuleBitcodeWriter::writeInstruction(const Instruction &I,
pushValueAndType(CI.getCalledOperand(), InstID, Vals); // Callee

// Emit value #'s for the fixed parameters.
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
// Check for labels (can happen with asm labels).
if (FTy->getParamType(i)->isLabelTy())
Vals.push_back(VE.getValueID(CI.getArgOperand(i)));
else
pushValue(CI.getArgOperand(i), InstID, Vals); // fixed param.
}
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
pushValue(CI.getArgOperand(i), InstID, Vals); // fixed param.

// Emit type/value pairs for varargs params.
if (FTy->isVarArg()) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ bool FunctionType::isValidReturnType(Type *RetTy) {
}

bool FunctionType::isValidArgumentType(Type *ArgTy) {
return ArgTy->isFirstClassType();
return ArgTy->isFirstClassType() && !ArgTy->isLabelTy();
}

//===----------------------------------------------------------------------===//
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2934,8 +2934,6 @@ 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);
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/Assembler/invalid-label-call-arg.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

; CHECK: invalid type for function argument
define void @test() {
bb:
call void asm "", ""(label %bb)
ret void
}

2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-label.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; RUN: FileCheck %s < %t
; Test the case where an invalid label name is used

; CHECK: unable to create block named 'bb'
; CHECK: invalid type for function argument

define void @test(label %bb) {
bb:
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/CodeGen/X86/asm-block-labels.ll
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ entry:
call void asm sideeffect "int $$1", "~{dirflag},~{fpsr},~{flags},~{memory}"( )
call void asm sideeffect ".file \22block12.c\22", "~{dirflag},~{fpsr},~{flags}"( )
call void asm sideeffect ".line 2", "~{dirflag},~{fpsr},~{flags}"( )
call void asm sideeffect "brl ${0:l}", "X,~{dirflag},~{fpsr},~{flags},~{memory}"( label %"LASM$foo" )
call void asm sideeffect "brl ${0:l}", "X,~{dirflag},~{fpsr},~{flags},~{memory}"(ptr blockaddress(@bar, %"LASM$foo"))
br label %return

return: ; preds = %"LASM$foo"
Expand All @@ -24,7 +24,7 @@ define void @baz() {
entry:
call void asm sideeffect ".file \22block12.c\22", "~{dirflag},~{fpsr},~{flags}"( )
call void asm sideeffect ".line 3", "~{dirflag},~{fpsr},~{flags}"( )
call void asm sideeffect "brl ${0:l}", "X,~{dirflag},~{fpsr},~{flags},~{memory}"( label %"LASM$foo" )
call void asm sideeffect "brl ${0:l}", "X,~{dirflag},~{fpsr},~{flags},~{memory}"(ptr blockaddress(@baz, %"LASM$foo"))
call void asm sideeffect ".file \22block12.c\22", "~{dirflag},~{fpsr},~{flags}"( )
call void asm sideeffect ".line 4", "~{dirflag},~{fpsr},~{flags}"( )
call void asm sideeffect "int $$1", "~{dirflag},~{fpsr},~{flags},~{memory}"( )
Expand All @@ -42,7 +42,7 @@ return: ; preds = %"LASM$foo"

define void @quux() {
entry:
call void asm sideeffect inteldialect "brl ${0:l}", "X,~{dirflag},~{fpsr},~{flags},~{memory}"( label %"LASM$foo" )
call void asm sideeffect inteldialect "brl ${0:l}", "X,~{dirflag},~{fpsr},~{flags},~{memory}"(ptr blockaddress(@quux, %"LASM$foo"))
br label %"LASM$foo"

"LASM$foo": ; preds = %entry
Expand Down
6 changes: 1 addition & 5 deletions llvm/test/Verifier/invalid-label-param.ll
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ define void @invalid_arg_type(i32 %0) {
}

declare void @foo(label)
; CHECK: Function argument cannot be of label type!
; CHECK-NEXT: label %0
; CHECK-NEXT: ptr @foo


; CHECK: invalid type for function argument