From a3dd1c817058eab96fd99f1f8b54ece2e2a0df04 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 10 Jun 2014 20:10:08 +0000 Subject: [PATCH] Fix error in tablegen when either operand of !if is an empty list. !if([Something], []) would error with "No type for list". llvm-svn: 210572 --- lib/TableGen/TGParser.cpp | 14 ++++++++------ lib/TableGen/TGParser.h | 2 +- test/TableGen/if-empty-list-arg.td | 7 +++++++ 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 test/TableGen/if-empty-list-arg.td diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index f337c75ed5e..0550692ebce 100644 --- a/lib/TableGen/TGParser.cpp +++ b/lib/TableGen/TGParser.cpp @@ -787,7 +787,7 @@ Init *TGParser::ParseIDValue(Record *CurRec, /// /// Operation ::= XOperator ['<' Type '>'] '(' Args ')' /// -Init *TGParser::ParseOperation(Record *CurRec) { +Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) { switch (Lex.getCode()) { default: TokError("unknown operation"); @@ -1026,8 +1026,9 @@ Init *TGParser::ParseOperation(Record *CurRec) { } Lex.Lex(); // eat the ',' - Init *MHS = ParseValue(CurRec); - if (!MHS) return nullptr; + Init *MHS = ParseValue(CurRec, ItemType); + if (!MHS) + return nullptr; if (Lex.getCode() != tgtok::comma) { TokError("expected ',' in ternary operator"); @@ -1035,8 +1036,9 @@ Init *TGParser::ParseOperation(Record *CurRec) { } Lex.Lex(); // eat the ',' - Init *RHS = ParseValue(CurRec); - if (!RHS) return nullptr; + Init *RHS = ParseValue(CurRec, ItemType); + if (!RHS) + return nullptr; if (Lex.getCode() != tgtok::r_paren) { TokError("expected ')' in binary operator"); @@ -1446,7 +1448,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, case tgtok::XIf: case tgtok::XForEach: case tgtok::XSubst: { // Value ::= !ternop '(' Value ',' Value ',' Value ')' - return ParseOperation(CurRec); + return ParseOperation(CurRec, ItemType); } } diff --git a/lib/TableGen/TGParser.h b/lib/TableGen/TGParser.h index 6fd442a7c21..9f4b7e90826 100644 --- a/lib/TableGen/TGParser.h +++ b/lib/TableGen/TGParser.h @@ -181,7 +181,7 @@ private: // Parser methods. std::vector ParseRangeList(); bool ParseRangePiece(std::vector &Ranges); RecTy *ParseType(); - Init *ParseOperation(Record *CurRec); + Init *ParseOperation(Record *CurRec, RecTy *ItemType); RecTy *ParseOperatorType(); Init *ParseObjectName(MultiClass *CurMultiClass); Record *ParseClassID(); diff --git a/test/TableGen/if-empty-list-arg.td b/test/TableGen/if-empty-list-arg.td new file mode 100644 index 00000000000..39edf58ff29 --- /dev/null +++ b/test/TableGen/if-empty-list-arg.td @@ -0,0 +1,7 @@ +// RUN: llvm-tblgen %s +// XFAIL: vg_leak + +class C { + list X = !if(cond, [1, 2, 3], []); + list Y = !if(cond, [], [4, 5, 6]); +}