[llvm] [llvm][TableGen] Fix misleading error for invalid use of let (PR #118616)

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 4 03:54:01 PST 2024


https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/118616

Fixes #118490

Point to the value name, otherwise it implies that the part after the '=' is the problem.

Before:
/tmp/test.td:2:27: error: Value 'FlattenedFeatures' unknown!
  let FlattenedFeatures = [];
                          ^
After:
/tmp/test.td:2:7: error: Value 'FlattenedFeatures' unknown!
  let FlattenedFeatures = [];
      ^

>From 52a4dd39b5b56055d216902e237d1bdf344733c4 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Wed, 4 Dec 2024 11:51:32 +0000
Subject: [PATCH] [llvm][TableGen] Fix misleading error for invalid use of let

Fixes #118490

Point to the value name, otherwise it implies that the part after
the '=' is the problem.

Before:
/tmp/test.td:2:27: error: Value 'FlattenedFeatures' unknown!
  let FlattenedFeatures = [];
                          ^
After:
/tmp/test.td:2:7: error: Value 'FlattenedFeatures' unknown!
  let FlattenedFeatures = [];
      ^
---
 llvm/lib/TableGen/TGParser.cpp        | 2 +-
 llvm/test/TableGen/letUnknownValue.td | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/TableGen/letUnknownValue.td

diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index e01342ffcd3c8f..8a8cd2b7356cd3 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -3504,7 +3504,7 @@ bool TGParser::ParseBodyItem(Record *CurRec) {
 
   RecordVal *Field = CurRec->getValue(FieldName);
   if (!Field)
-    return TokError("Value '" + FieldName->getValue() + "' unknown!");
+    return Error(IdLoc, "Value '" + FieldName->getValue() + "' unknown!");
 
   const RecTy *Type = Field->getType();
   if (!BitList.empty() && isa<BitsRecTy>(Type)) {
diff --git a/llvm/test/TableGen/letUnknownValue.td b/llvm/test/TableGen/letUnknownValue.td
new file mode 100644
index 00000000000000..e33dca417f1d1d
--- /dev/null
+++ b/llvm/test/TableGen/letUnknownValue.td
@@ -0,0 +1,9 @@
+// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s --strict-whitespace
+
+def {
+  /// Let can only override something that already exists.
+  let abc = [];
+// CHECK: error: Value 'abc' unknown!
+// CHECK-NEXT:{{^}}  let abc = [];
+// CHECK-NEXT:{{^}}      ^
+}
\ No newline at end of file



More information about the llvm-commits mailing list