[llvm] [TableGen] Reject "field" keyword in template argument declaration (PR #124924)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 06:13:30 PST 2025
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/124924
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.
>From ec4bbe20efc92c29103f5b11bdadfc303c99663d Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Wed, 29 Jan 2025 14:06:16 +0000
Subject: [PATCH] [TableGen] Reject "field" keyword in template argument
declaration
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.
---
llvm/docs/TableGen/ProgRef.rst | 2 +-
llvm/lib/TableGen/TGParser.cpp | 2 +-
llvm/test/TableGen/field-keyword.td | 14 ++++++++++++++
3 files changed, 16 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/TableGen/field-keyword.td
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
More information about the llvm-commits
mailing list