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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-tablegen

Author: David Spickett (DavidSpickett)

<details>
<summary>Changes</summary>

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 = [];
      ^
```

---
Full diff: https://github.com/llvm/llvm-project/pull/118616.diff


2 Files Affected:

- (modified) llvm/lib/TableGen/TGParser.cpp (+1-1) 
- (added) llvm/test/TableGen/letUnknownValue.td (+9) 


``````````diff
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

``````````

</details>


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


More information about the llvm-commits mailing list