Skip to content

Commit 29baa13

Browse files
committed
Add a few negative tests
1 parent 4a8b23d commit 29baa13

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

llvm/test/TableGen/GlobalISelEmitter-optional-def.td

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: llvm-tblgen -gen-global-isel -I %p/../../include -I %p/Common < %s | FileCheck %s
1+
// RUN: llvm-tblgen -gen-global-isel -warn-on-skipped-patterns \
2+
// RUN: -I %p/../../include -I %p/Common %s 2> %t | FileCheck %s
3+
// RUN: FileCheck -DFILE=%s -check-prefix=ERR %s < %t
24

35
include "llvm/Target/Target.td"
46
include "GlobalISelEmitterCommon.td"
@@ -35,3 +37,20 @@ def tst2 : I<(outs GPR32:$rd, s_cc_out:$s), (ins GPR32:$rs1, GPR32:$rs2),
3537
// TODO: There should be more tests, but any attempt to write something
3638
// more complex results in tablegen crashing somewhere in
3739
// TreePatternNode::UpdateNodeType.
40+
41+
42+
def not_leaf : OptionalDefOperand<i32, (ops GPR8), (ops (i8 imm))>;
43+
def not_rec : OptionalDefOperand<i32, (ops GPR8), (ops (i8 0))>;
44+
def not_reg : OptionalDefOperand<i32, (ops GPR8), (ops GPR8)>;
45+
46+
// ERR: [[#@LINE+1]]:5: warning: Skipped pattern: optional def is not a leaf
47+
def tst_not_leaf : I<(outs GPR32:$rd, not_leaf:$s), (ins i32imm:$imm),
48+
[(set GPR32:$rd, imm:$imm)]>;
49+
50+
// ERR: [[#@LINE+1]]:5: warning: Skipped pattern: optional def is not a record
51+
def tst_not_rec : I<(outs GPR32:$rd, not_rec:$s), (ins i32imm:$imm),
52+
[(set GPR32:$rd, imm:$imm)]>;
53+
54+
// ERR: [[#@LINE+1]]:5: warning: Skipped pattern: optional def is not a register
55+
def tst_not_reg : I<(outs GPR32:$rd, not_reg:$s), (ins i32imm:$imm),
56+
[(set GPR32:$rd, imm:$imm)]>;

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,8 +1470,15 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitDefRenderers(
14701470
if (OpInfo.Rec->isSubClassOf("OptionalDefOperand")) {
14711471
for (const TreePatternNode &DefaultOp :
14721472
make_pointee_range(CGP.getDefaultOperand(OpInfo.Rec).DefaultOps)) {
1473-
const Record *Reg = cast<DefInit>(DefaultOp.getLeafValue())->getDef();
1473+
// TODO: Do these checks in ParseDefaultOperands.
1474+
if (!DefaultOp.isLeaf())
1475+
return failedImport("optional def is not a leaf");
14741476

1477+
const auto *RegDI = dyn_cast<DefInit>(DefaultOp.getLeafValue());
1478+
if (!RegDI)
1479+
return failedImport("optional def is not a record");
1480+
1481+
const Record *Reg = RegDI->getDef();
14751482
if (!Reg->isSubClassOf("Register") && Reg->getName() != "zero_reg")
14761483
return failedImport("optional def is not a register");
14771484

0 commit comments

Comments
 (0)