Skip to content

Commit 38cb7d5

Browse files
authored
[IR] Don't allow label arguments (#137799)
We currently accept label arguments to inline asm calls. This support predates both blockaddresses and callbr and is only covered by one X86 test. Remove it in favor of callbr (or at least blockaddress, though that cannot guarantee correct codegen, just like using block labels directly can't). I didn't bother implementing bitcode upgrade support for this, but I can add it if desired.
1 parent c96f019 commit 38cb7d5

File tree

9 files changed

+21
-20
lines changed

9 files changed

+21
-20
lines changed

llvm/docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Changes to the LLVM IR
6464

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

6869
Changes to LLVM infrastructure
6970
------------------------------

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3072,6 +3072,8 @@ bool LLParser::parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
30723072
Value *V;
30733073
if (parseType(ArgTy, ArgLoc))
30743074
return true;
3075+
if (!FunctionType::isValidArgumentType(ArgTy))
3076+
return error(ArgLoc, "invalid type for function argument");
30753077

30763078
AttrBuilder ArgAttrs(M->getContext());
30773079

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

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

33873389
ArgList.emplace_back(TypeLoc, ArgTy,

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,13 +3488,8 @@ void ModuleBitcodeWriter::writeInstruction(const Instruction &I,
34883488
pushValueAndType(CI.getCalledOperand(), InstID, Vals); // Callee
34893489

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

34993494
// Emit type/value pairs for varargs params.
35003495
if (FTy->isVarArg()) {

llvm/lib/IR/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ bool FunctionType::isValidReturnType(Type *RetTy) {
390390
}
391391

392392
bool FunctionType::isValidArgumentType(Type *ArgTy) {
393-
return ArgTy->isFirstClassType();
393+
return ArgTy->isFirstClassType() && !ArgTy->isLabelTy();
394394
}
395395

396396
//===----------------------------------------------------------------------===//

llvm/lib/IR/Verifier.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,8 +2934,6 @@ void Verifier::visitFunction(const Function &F) {
29342934
FT->getParamType(i));
29352935
Check(Arg.getType()->isFirstClassType(),
29362936
"Function arguments must have first-class types!", &Arg);
2937-
Check(!Arg.getType()->isLabelTy(),
2938-
"Function argument cannot be of label type!", &Arg, &F);
29392937
if (!IsIntrinsic) {
29402938
Check(!Arg.getType()->isMetadataTy(),
29412939
"Function takes metadata but isn't an intrinsic", &Arg, &F);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
2+
3+
; CHECK: invalid type for function argument
4+
define void @test() {
5+
bb:
6+
call void asm "", ""(label %bb)
7+
ret void
8+
}
9+

llvm/test/Assembler/invalid-label.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; RUN: FileCheck %s < %t
33
; Test the case where an invalid label name is used
44

5-
; CHECK: unable to create block named 'bb'
5+
; CHECK: invalid type for function argument
66

77
define void @test(label %bb) {
88
bb:

llvm/test/CodeGen/X86/asm-block-labels.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ entry:
1313
call void asm sideeffect "int $$1", "~{dirflag},~{fpsr},~{flags},~{memory}"( )
1414
call void asm sideeffect ".file \22block12.c\22", "~{dirflag},~{fpsr},~{flags}"( )
1515
call void asm sideeffect ".line 2", "~{dirflag},~{fpsr},~{flags}"( )
16-
call void asm sideeffect "brl ${0:l}", "X,~{dirflag},~{fpsr},~{flags},~{memory}"( label %"LASM$foo" )
16+
call void asm sideeffect "brl ${0:l}", "X,~{dirflag},~{fpsr},~{flags},~{memory}"(ptr blockaddress(@bar, %"LASM$foo"))
1717
br label %return
1818

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

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

4848
"LASM$foo": ; preds = %entry

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@ define void @invalid_arg_type(i32 %0) {
77
}
88

99
declare void @foo(label)
10-
; CHECK: Function argument cannot be of label type!
11-
; CHECK-NEXT: label %0
12-
; CHECK-NEXT: ptr @foo
13-
14-
10+
; CHECK: invalid type for function argument

0 commit comments

Comments
 (0)