From 52a4dd39b5b56055d216902e237d1bdf344733c4 Mon Sep 17 00:00:00 2001 From: David Spickett 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 e01342ffcd3c8..8a8cd2b7356cd 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(Type)) { diff --git a/llvm/test/TableGen/letUnknownValue.td b/llvm/test/TableGen/letUnknownValue.td new file mode 100644 index 0000000000000..e33dca417f1d1 --- /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