[llvm] [TableGen] Reject "field" keyword in template argument declaration (PR #124924)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 06:14:10 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Jay Foad (jayfoad)
<details>
<summary>Changes</summary>
This seems like an obvious oversight in the parser.
Also document where the "field" keyword is allowed: only on the
declaration of a field in a class or def.
---
Full diff: https://github.com/llvm/llvm-project/pull/124924.diff
3 Files Affected:
- (modified) llvm/docs/TableGen/ProgRef.rst (+1-1)
- (modified) llvm/lib/TableGen/TGParser.cpp (+1-1)
- (added) llvm/test/TableGen/field-keyword.td (+14)
``````````diff
diff --git a/llvm/docs/TableGen/ProgRef.rst b/llvm/docs/TableGen/ProgRef.rst
index cfe61382658ec4..849adea90201b4 100644
--- a/llvm/docs/TableGen/ProgRef.rst
+++ b/llvm/docs/TableGen/ProgRef.rst
@@ -670,7 +670,7 @@ arguments.
.. productionlist::
Body: ";" | "{" `BodyItem`* "}"
- BodyItem: (`Type` | "code") `TokIdentifier` ["=" `Value`] ";"
+ BodyItem: ["field"] (`Type` | "code") `TokIdentifier` ["=" `Value`] ";"
:| "let" `TokIdentifier` ["{" `RangeList` "}"] "=" `Value` ";"
:| "defvar" `TokIdentifier` "=" `Value` ";"
:| `Assert`
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 9a8301cffb930b..5cc3cde12c0608 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -3286,7 +3286,7 @@ bool TGParser::ParseTemplateArgValueList(
const Init *TGParser::ParseDeclaration(Record *CurRec,
bool ParsingTemplateArgs) {
// Read the field prefix if present.
- bool HasField = consume(tgtok::Field);
+ bool HasField = !ParsingTemplateArgs && consume(tgtok::Field);
const RecTy *Type = ParseType();
if (!Type) return nullptr;
diff --git a/llvm/test/TableGen/field-keyword.td b/llvm/test/TableGen/field-keyword.td
new file mode 100644
index 00000000000000..fe95ea7661d331
--- /dev/null
+++ b/llvm/test/TableGen/field-keyword.td
@@ -0,0 +1,14 @@
+// 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
+
+#ifdef ERROR1
+// ERROR1: [[@LINE+1]]:9: error: Unknown token when expecting a type
+class C<field int x = 0>;
+#endif
+
+#ifdef ERROR2
+// ERROR2: [[@LINE+1]]:14: error: Unknown token when expecting a type
+multiclass M<field string s> {
+ def D;
+}
+#endif
``````````
</details>
https://github.com/llvm/llvm-project/pull/124924
More information about the llvm-commits
mailing list