diff --git a/llvm/lib/TableGen/DetailedRecordsBackend.cpp b/llvm/lib/TableGen/DetailedRecordsBackend.cpp --- a/llvm/lib/TableGen/DetailedRecordsBackend.cpp +++ b/llvm/lib/TableGen/DetailedRecordsBackend.cpp @@ -104,7 +104,8 @@ 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/llvm/test/TableGen/detailed-records.td b/llvm/test/TableGen/detailed-records.td new file mode 100644 --- /dev/null +++ b/llvm/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; +