[PATCH] D85852: Fix two bugs in TGParser::ParseValue

Paul C. Anagnostopoulos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 12:30:03 PDT 2020


Paul-C-Anagnostopoulos updated this revision to Diff 286107.
Paul-C-Anagnostopoulos added a comment.

Reformatted the two lines of code correctly.

@nhaehnle, could you do me the favor of committing this?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85852/new/

https://reviews.llvm.org/D85852

Files:
  llvm/lib/TableGen/TGParser.cpp
  llvm/test/TableGen/paste-reserved.td


Index: llvm/test/TableGen/paste-reserved.td
===================================================================
--- /dev/null
+++ llvm/test/TableGen/paste-reserved.td
@@ -0,0 +1,22 @@
+// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
+// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
+
+defvar list1 = ["foo", "bar", "snork"];
+
+// Pasting a list with a reserved word should produce an error.
+
+#ifdef ERROR1
+def list_paste {
+  list<string> the_list = list1 # in;
+}
+// ERROR1: error: Unknown token when parsing a value
+#endif
+
+
+// Pasting an identifier with a reserved word should produce an error.
+
+#ifdef ERROR2
+def name_paste#in {
+}
+// ERROR2: error: Unknown token when parsing a value
+#endif
Index: llvm/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/lib/TableGen/TGParser.cpp
+++ llvm/lib/TableGen/TGParser.cpp
@@ -2203,6 +2203,8 @@
           break;
         default:
           Init *RHSResult = ParseValue(CurRec, ItemType, ParseNameMode);
+          if (!RHSResult)
+            return nullptr;
           Result = BinOpInit::getListConcat(LHS, RHSResult);
         }
         break;
@@ -2239,6 +2241,8 @@
 
       default:
         Init *RHSResult = ParseValue(CurRec, nullptr, ParseNameMode);
+        if (!RHSResult)
+          return nullptr;
         RHS = dyn_cast<TypedInit>(RHSResult);
         if (!RHS) {
           Error(PasteLoc, "RHS of paste is not typed!");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85852.286107.patch
Type: text/x-patch
Size: 1512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200817/3ba7e3e1/attachment.bin>


More information about the llvm-commits mailing list