From 8871b402ec162c1967b4b287cae4d5696983ccf5 Mon Sep 17 00:00:00 2001 From: "Paul C. Anagnostopoulos" Date: Sun, 24 Jan 2021 13:30:31 -0500 Subject: [PATCH] [TableGen] [DetailedRecords] Print record name that is null string as "" Differential Revision: https://reviews.llvm.org/D95312 Add a test for the backend. --- lib/TableGen/DetailedRecordsBackend.cpp | 3 ++- test/TableGen/detailed-records.td | 36 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/TableGen/detailed-records.td diff --git a/lib/TableGen/DetailedRecordsBackend.cpp b/lib/TableGen/DetailedRecordsBackend.cpp index 2c3c3358b34..482a0d71da8 100644 --- a/lib/TableGen/DetailedRecordsBackend.cpp +++ b/lib/TableGen/DetailedRecordsBackend.cpp @@ -104,7 +104,8 @@ void DetailedRecordsEmitter::printRecords(raw_ostream &OS) { for (const auto &RecPair : RecordList) { auto *const Rec = RecPair.second.get(); - OS << formatv("\n{0} |{1}|\n", Rec->getNameInitAsString(), + std::string Name = Rec->getNameInitAsString(); + OS << formatv("\n{0} |{1}|\n", Name.empty() ? "\"\"" : Name, SrcMgr.getFormattedLocationNoOffset(Rec->getLoc().front())); printDefms(Rec, OS); printSuperclasses(Rec, OS); diff --git a/test/TableGen/detailed-records.td b/test/TableGen/detailed-records.td new file mode 100644 index 00000000000..15b5f268f2c --- /dev/null +++ b/test/TableGen/detailed-records.td @@ -0,0 +1,36 @@ +// RUN: llvm-tblgen -print-detailed-records %s | FileCheck %s + +// This test file ensures that the DetailedRecords backend prints all +// the global variables, classes, and records. + +// CHECK: ----- Global Variables +// CHECK: Answer +// CHECK: Greeting + +// CHECK: ----- Classes +// CHECK: Class1 +// CHECK: Class2 + +// CHECK: ----- Records +// CHECK: "" +// CHECK: Info +// CHECK: Rec1 +// CHECK: anonymous_0 + +defvar Greeting = "Hello there."; +defvar Answer = 42; + +class Class1 { +} + +class Class2 { +} + +def : Class1; + +def "" : Class2; + +def Rec1; + +def Info : Class1; +