[PATCH] D145711: [llvm-tblgen] Support conditional definitions using !casts clauses
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 9 11:04:30 PST 2023
reames created this revision.
reames added a reviewer: foad.
Herald added subscribers: StephenFan, bollu, hiraditya, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added a project: LLVM.
This is a follow on to D145108 <https://reviews.llvm.org/D145108>. This started as simply fixing the crash on an error case reported against that change, but I think this also ends up fixing the original reported issue (https://github.com/llvm/llvm-project/issues/49830) as well. More accurately, D145108 <https://reviews.llvm.org/D145108> fixed the case where the cast resolves to an existing record, and this change fixes the case where the named record doesn't exist.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145711
Files:
llvm/lib/TableGen/Record.cpp
llvm/test/TableGen/if-unresolved-cast.td
Index: llvm/test/TableGen/if-unresolved-cast.td
===================================================================
--- /dev/null
+++ llvm/test/TableGen/if-unresolved-cast.td
@@ -0,0 +1,8 @@
+// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s
+// XFAIL: vg_leak
+
+class A { int x; }
+
+// CHECK: Undefined reference to record: ''
+if !cast<A>("").x then
+ def x;
Index: llvm/lib/TableGen/Record.cpp
===================================================================
--- llvm/lib/TableGen/Record.cpp
+++ llvm/lib/TableGen/Record.cpp
@@ -800,37 +800,40 @@
} else if (isa<RecordRecTy>(getType())) {
if (StringInit *Name = dyn_cast<StringInit>(LHS)) {
- if (!CurRec && !IsFinal)
- break;
- assert(CurRec && "NULL pointer");
- Record *D;
-
- // Self-references are allowed, but their resolution is delayed until
- // the final resolve to ensure that we get the correct type for them.
- auto *Anonymous = dyn_cast<AnonymousNameInit>(CurRec->getNameInit());
- if (Name == CurRec->getNameInit() ||
- (Anonymous && Name == Anonymous->getNameInit())) {
- if (!IsFinal)
- break;
- D = CurRec;
- } else {
- D = CurRec->getRecords().getDef(Name->getValue());
- if (!D) {
- if (IsFinal)
- PrintFatalError(CurRec->getLoc(),
- Twine("Undefined reference to record: '") +
- Name->getValue() + "'\n");
- break;
+ Record *D = RK.getDef(Name->getValue());
+ if (!D && CurRec) {
+ // Self-references are allowed, but their resolution is delayed until
+ // the final resolve to ensure that we get the correct type for them.
+ auto *Anonymous = dyn_cast<AnonymousNameInit>(CurRec->getNameInit());
+ if (Name == CurRec->getNameInit() ||
+ (Anonymous && Name == Anonymous->getNameInit())) {
+ if (!IsFinal)
+ break;
+ D = CurRec;
}
}
+ auto PrintFatalErrorHelper = [CurRec](const Twine &T) {
+ if (CurRec)
+ PrintFatalError(CurRec->getLoc(), T);
+ else
+ PrintFatalError(T);
+ };
+
+ if (!D) {
+ if (IsFinal) {
+ PrintFatalErrorHelper(Twine("Undefined reference to record: '") +
+ Name->getValue() + "'\n");
+ }
+ break;
+ }
+
DefInit *DI = DefInit::get(D);
if (!DI->getType()->typeIsA(getType())) {
- PrintFatalError(CurRec->getLoc(),
- Twine("Expected type '") +
- getType()->getAsString() + "', got '" +
- DI->getType()->getAsString() + "' in: " +
- getAsString() + "\n");
+ PrintFatalErrorHelper(Twine("Expected type '") +
+ getType()->getAsString() + "', got '" +
+ DI->getType()->getAsString() + "' in: " +
+ getAsString() + "\n");
}
return DI;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145711.503855.patch
Type: text/x-patch
Size: 3170 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230309/9ec35fd9/attachment.bin>
More information about the llvm-commits
mailing list