Skip to content

Commit 17cd344

Browse files
committed
Fix two bugs in TGParser::ParseValue
TGParser::ParseValue contains two recursive calls, one to parse the RHS of a list paste operator and one to parse the RHS of a paste operator in a class/def name. Both of these calls neglect to check the return value to see if it is null (because of some error). This causes a crash in the next line of code, which uses the return value. The code now checks for null returns. Differential Revision: https://reviews.llvm.org/D85852
1 parent e0c01e6 commit 17cd344

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/TableGen/TGParser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,8 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
22032203
break;
22042204
default:
22052205
Init *RHSResult = ParseValue(CurRec, ItemType, ParseNameMode);
2206+
if (!RHSResult)
2207+
return nullptr;
22062208
Result = BinOpInit::getListConcat(LHS, RHSResult);
22072209
}
22082210
break;
@@ -2239,6 +2241,8 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
22392241

22402242
default:
22412243
Init *RHSResult = ParseValue(CurRec, nullptr, ParseNameMode);
2244+
if (!RHSResult)
2245+
return nullptr;
22422246
RHS = dyn_cast<TypedInit>(RHSResult);
22432247
if (!RHS) {
22442248
Error(PasteLoc, "RHS of paste is not typed!");

llvm/test/TableGen/paste-reserved.td

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
2+
// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
3+
4+
defvar list1 = ["foo", "bar", "snork"];
5+
6+
// Pasting a list with a reserved word should produce an error.
7+
8+
#ifdef ERROR1
9+
def list_paste {
10+
list<string> the_list = list1 # in;
11+
}
12+
// ERROR1: error: Unknown token when parsing a value
13+
#endif
14+
15+
16+
// Pasting an identifier with a reserved word should produce an error.
17+
18+
#ifdef ERROR2
19+
def name_paste#in {
20+
}
21+
// ERROR2: error: Unknown token when parsing a value
22+
#endif

0 commit comments

Comments
 (0)