mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-24 20:30:06 +00:00
Add DWARF debug info support for C++11 inline namespaces.
This implements the DWARF 5 DW_AT_export_symbols feature: http://dwarfstd.org/ShowIssue.php?issue=141212.1 <rdar://problem/18616046> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285959 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2d1f4f5e9e
commit
60a7c431c0
@ -239,13 +239,13 @@ enum MetadataCodes {
|
||||
METADATA_SUBPROGRAM = 21, // [distinct, ...]
|
||||
METADATA_LEXICAL_BLOCK = 22, // [distinct, scope, file, line, column]
|
||||
METADATA_LEXICAL_BLOCK_FILE = 23, //[distinct, scope, file, discriminator]
|
||||
METADATA_NAMESPACE = 24, // [distinct, scope, file, name, line]
|
||||
METADATA_TEMPLATE_TYPE = 25, // [distinct, scope, name, type, ...]
|
||||
METADATA_TEMPLATE_VALUE = 26, // [distinct, scope, name, type, value, ...]
|
||||
METADATA_GLOBAL_VAR = 27, // [distinct, ...]
|
||||
METADATA_LOCAL_VAR = 28, // [distinct, ...]
|
||||
METADATA_EXPRESSION = 29, // [distinct, n x element]
|
||||
METADATA_OBJC_PROPERTY = 30, // [distinct, name, file, line, ...]
|
||||
METADATA_NAMESPACE = 24, // [distinct, scope, file, name, line, exportSymbols]
|
||||
METADATA_TEMPLATE_TYPE = 25, // [distinct, scope, name, type, ...]
|
||||
METADATA_TEMPLATE_VALUE = 26, // [distinct, scope, name, type, value, ...]
|
||||
METADATA_GLOBAL_VAR = 27, // [distinct, ...]
|
||||
METADATA_LOCAL_VAR = 28, // [distinct, ...]
|
||||
METADATA_EXPRESSION = 29, // [distinct, n x element]
|
||||
METADATA_OBJC_PROPERTY = 30, // [distinct, name, file, line, ...]
|
||||
METADATA_IMPORTED_ENTITY = 31, // [distinct, tag, scope, entity, line, name]
|
||||
METADATA_MODULE = 32, // [distinct, scope, name, ...]
|
||||
METADATA_MACRO = 33, // [distinct, macinfo, line, name, value]
|
||||
|
@ -598,8 +598,9 @@ namespace llvm {
|
||||
/// \param Name Name of this namespace
|
||||
/// \param File Source file
|
||||
/// \param LineNo Line number
|
||||
/// \param ExportSymbols True for C++ inline namespaces.
|
||||
DINamespace *createNameSpace(DIScope *Scope, StringRef Name, DIFile *File,
|
||||
unsigned LineNo);
|
||||
unsigned LineNo, bool ExportSymbols);
|
||||
|
||||
/// This creates new descriptor for a module with the specified
|
||||
/// parent scope.
|
||||
|
@ -1636,40 +1636,45 @@ class DINamespace : public DIScope {
|
||||
friend class MDNode;
|
||||
|
||||
unsigned Line;
|
||||
unsigned ExportSymbols : 1;
|
||||
|
||||
DINamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
|
||||
ArrayRef<Metadata *> Ops)
|
||||
bool ExportSymbols, ArrayRef<Metadata *> Ops)
|
||||
: DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace,
|
||||
Ops),
|
||||
Line(Line) {}
|
||||
Line(Line), ExportSymbols(ExportSymbols) {}
|
||||
~DINamespace() = default;
|
||||
|
||||
static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
|
||||
DIFile *File, StringRef Name, unsigned Line,
|
||||
StorageType Storage, bool ShouldCreate = true) {
|
||||
bool ExportSymbols, StorageType Storage,
|
||||
bool ShouldCreate = true) {
|
||||
return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
|
||||
Line, Storage, ShouldCreate);
|
||||
Line, ExportSymbols, Storage, ShouldCreate);
|
||||
}
|
||||
static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
|
||||
Metadata *File, MDString *Name, unsigned Line,
|
||||
StorageType Storage, bool ShouldCreate = true);
|
||||
bool ExportSymbols, StorageType Storage,
|
||||
bool ShouldCreate = true);
|
||||
|
||||
TempDINamespace cloneImpl() const {
|
||||
return getTemporary(getContext(), getScope(), getFile(), getName(),
|
||||
getLine());
|
||||
getLine(), getExportSymbols());
|
||||
}
|
||||
|
||||
public:
|
||||
DEFINE_MDNODE_GET(DINamespace, (DIScope * Scope, DIFile *File, StringRef Name,
|
||||
unsigned Line),
|
||||
(Scope, File, Name, Line))
|
||||
DEFINE_MDNODE_GET(DINamespace, (Metadata * Scope, Metadata *File,
|
||||
MDString *Name, unsigned Line),
|
||||
(Scope, File, Name, Line))
|
||||
unsigned Line, bool ExportSymbols),
|
||||
(Scope, File, Name, Line, ExportSymbols))
|
||||
DEFINE_MDNODE_GET(DINamespace,
|
||||
(Metadata * Scope, Metadata *File, MDString *Name,
|
||||
unsigned Line, bool ExportSymbols),
|
||||
(Scope, File, Name, Line, ExportSymbols))
|
||||
|
||||
TempDINamespace clone() const { return cloneImpl(); }
|
||||
|
||||
unsigned getLine() const { return Line; }
|
||||
bool getExportSymbols() const { return ExportSymbols; }
|
||||
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
|
||||
StringRef getName() const { return getStringOperand(2); }
|
||||
|
||||
|
@ -4092,12 +4092,13 @@ bool LLParser::ParseDINamespace(MDNode *&Result, bool IsDistinct) {
|
||||
REQUIRED(scope, MDField, ); \
|
||||
OPTIONAL(file, MDField, ); \
|
||||
OPTIONAL(name, MDStringField, ); \
|
||||
OPTIONAL(line, LineField, );
|
||||
OPTIONAL(line, LineField, ); \
|
||||
OPTIONAL(exportSymbols, MDBoolField, );
|
||||
PARSE_MD_FIELDS();
|
||||
#undef VISIT_MD_FIELDS
|
||||
|
||||
Result = GET_OR_DISTINCT(DINamespace,
|
||||
(Context, scope.Val, file.Val, name.Val, line.Val));
|
||||
(Context, scope.Val, file.Val, name.Val, line.Val, exportSymbols.Val));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2628,11 +2628,13 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
|
||||
if (Record.size() != 5)
|
||||
return error("Invalid record");
|
||||
|
||||
IsDistinct = Record[0];
|
||||
IsDistinct = Record[0] & 1;
|
||||
bool ExportSymbols = Record[0] & 2;
|
||||
MetadataList.assignValue(
|
||||
GET_OR_DISTINCT(DINamespace, (Context, getMDOrNull(Record[1]),
|
||||
getMDOrNull(Record[2]),
|
||||
getMDString(Record[3]), Record[4])),
|
||||
GET_OR_DISTINCT(DINamespace,
|
||||
(Context, getMDOrNull(Record[1]),
|
||||
getMDOrNull(Record[2]), getMDString(Record[3]),
|
||||
Record[4], ExportSymbols)),
|
||||
NextMetadataNo++);
|
||||
break;
|
||||
}
|
||||
|
@ -1627,7 +1627,7 @@ void ModuleBitcodeWriter::writeDILexicalBlockFile(
|
||||
void ModuleBitcodeWriter::writeDINamespace(const DINamespace *N,
|
||||
SmallVectorImpl<uint64_t> &Record,
|
||||
unsigned Abbrev) {
|
||||
Record.push_back(N->isDistinct());
|
||||
Record.push_back(N->isDistinct() | N->getExportSymbols() << 1);
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getScope()));
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getFile()));
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
|
||||
|
@ -1083,6 +1083,8 @@ DIE *DwarfUnit::getOrCreateNameSpace(const DINamespace *NS) {
|
||||
DD->addAccelNamespace(Name, NDie);
|
||||
addGlobalName(Name, NDie, NS->getScope());
|
||||
addSourceLine(NDie, NS);
|
||||
if (NS->getExportSymbols())
|
||||
addFlag(NDie, dwarf::DW_AT_export_symbols);
|
||||
return &NDie;
|
||||
}
|
||||
|
||||
|
@ -1740,6 +1740,7 @@ static void writeDINamespace(raw_ostream &Out, const DINamespace *N,
|
||||
Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
|
||||
Printer.printMetadata("file", N->getRawFile());
|
||||
Printer.printInt("line", N->getLine());
|
||||
Printer.printBool("exportSymbols", N->getExportSymbols(), false);
|
||||
Out << ")";
|
||||
}
|
||||
|
||||
|
@ -685,9 +685,10 @@ DISubprogram *DIBuilder::createMethod(DIScope *Context, StringRef Name,
|
||||
}
|
||||
|
||||
DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name,
|
||||
DIFile *File, unsigned LineNo) {
|
||||
DIFile *File, unsigned LineNo,
|
||||
bool ExportSymbols) {
|
||||
return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name,
|
||||
LineNo);
|
||||
LineNo, ExportSymbols);
|
||||
}
|
||||
|
||||
DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name,
|
||||
|
@ -471,11 +471,12 @@ DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
|
||||
|
||||
DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
|
||||
Metadata *File, MDString *Name, unsigned Line,
|
||||
StorageType Storage, bool ShouldCreate) {
|
||||
bool ExportSymbols, StorageType Storage,
|
||||
bool ShouldCreate) {
|
||||
assert(isCanonical(Name) && "Expected canonical MDString");
|
||||
DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, Name, Line));
|
||||
DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, Name, Line, ExportSymbols));
|
||||
Metadata *Ops[] = {File, Scope, Name};
|
||||
DEFINE_GETIMPL_STORE(DINamespace, (Line), Ops);
|
||||
DEFINE_GETIMPL_STORE(DINamespace, (Line, ExportSymbols), Ops);
|
||||
}
|
||||
|
||||
DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
|
||||
|
@ -674,16 +674,20 @@ template <> struct MDNodeKeyImpl<DINamespace> {
|
||||
Metadata *File;
|
||||
MDString *Name;
|
||||
unsigned Line;
|
||||
bool ExportSymbols;
|
||||
|
||||
MDNodeKeyImpl(Metadata *Scope, Metadata *File, MDString *Name, unsigned Line)
|
||||
: Scope(Scope), File(File), Name(Name), Line(Line) {}
|
||||
MDNodeKeyImpl(Metadata *Scope, Metadata *File, MDString *Name, unsigned Line,
|
||||
bool ExportSymbols)
|
||||
: Scope(Scope), File(File), Name(Name), Line(Line),
|
||||
ExportSymbols(ExportSymbols) {}
|
||||
MDNodeKeyImpl(const DINamespace *N)
|
||||
: Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getRawName()),
|
||||
Line(N->getLine()) {}
|
||||
Line(N->getLine()), ExportSymbols(N->getExportSymbols()) {}
|
||||
|
||||
bool isKeyOf(const DINamespace *RHS) const {
|
||||
return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
|
||||
Name == RHS->getRawName() && Line == RHS->getLine();
|
||||
Name == RHS->getRawName() && Line == RHS->getLine() &&
|
||||
ExportSymbols == RHS->getExportSymbols();
|
||||
}
|
||||
unsigned getHashValue() const {
|
||||
return hash_combine(Scope, File, Name, Line);
|
||||
|
@ -1,8 +1,8 @@
|
||||
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
|
||||
; RUN: verify-uselistorder %s
|
||||
|
||||
; CHECK: !named = !{!0, !1, !2, !3, !4, !4}
|
||||
!named = !{!0, !1, !2, !3, !4, !5}
|
||||
; CHECK: !named = !{!0, !1, !2, !3, !4, !4, !4, !5}
|
||||
!named = !{!0, !1, !2, !3, !4, !5, !6, !7}
|
||||
|
||||
!0 = !DIFile(filename: "file.cpp", directory: "/path/to/dir")
|
||||
!1 = distinct !{}
|
||||
@ -14,3 +14,6 @@
|
||||
; CHECK: !4 = !DINamespace(scope: !0)
|
||||
!4 = !DINamespace(name: "", scope: !0, file: null, line: 0)
|
||||
!5 = !DINamespace(scope: !0)
|
||||
!6 = !DINamespace(scope: !0, exportSymbols: false)
|
||||
; CHECK: !5 = !DINamespace(scope: !0, exportSymbols: true)
|
||||
!7 = !DINamespace(name: "", scope: !0, exportSymbols: true)
|
||||
|
23
test/Bitcode/DINamespace.ll
Normal file
23
test/Bitcode/DINamespace.ll
Normal file
@ -0,0 +1,23 @@
|
||||
; RUN: llvm-dis %s.bc -o - | FileCheck %s
|
||||
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-apple-macosx10.12.0"
|
||||
|
||||
@_ZN1N1iE = global i32 0, align 4, !dbg !0
|
||||
|
||||
!llvm.dbg.cu = !{!4}
|
||||
!llvm.module.flags = !{!7, !8, !9}
|
||||
!llvm.ident = !{!10}
|
||||
|
||||
!0 = distinct !DIGlobalVariable(name: "i", linkageName: "_ZN1N1iE", scope: !1, file: !2, line: 2, type: !3, isLocal: false, isDefinition: true)
|
||||
; Test bitcode upgrade for DINamespace without an exportSymbols field.
|
||||
; CHECK: !DINamespace(name: "N", scope: null, file: !{{[0-9]+}}, line: 1)
|
||||
!1 = !DINamespace(name: "N", scope: null, file: !2, line: 1)
|
||||
!2 = !DIFile(filename: "dinamespace.cpp", directory: "/")
|
||||
!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
|
||||
!4 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 4.0.0 (trunk 283228) (llvm/trunk 283225)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, globals: !6)
|
||||
!5 = !{}
|
||||
!6 = !{!0}
|
||||
!7 = !{i32 2, !"Dwarf Version", i32 4}
|
||||
!8 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!9 = !{i32 1, !"PIC Level", i32 2}
|
||||
!10 = !{!"clang version 4.0.0 (trunk 283228) (llvm/trunk 283225)"}
|
BIN
test/Bitcode/DINamespace.ll.bc
Normal file
BIN
test/Bitcode/DINamespace.ll.bc
Normal file
Binary file not shown.
40
test/DebugInfo/X86/inline-namespace.ll
Normal file
40
test/DebugInfo/X86/inline-namespace.ll
Normal file
@ -0,0 +1,40 @@
|
||||
; RUN: %llc_dwarf %s -o - -filetype=obj | llvm-dwarfdump -debug-dump=info - | FileCheck %s
|
||||
; Generated from:
|
||||
; namespace normal { inline namespace inlined { int i; } }
|
||||
; Check that an inline namespace is emitted with DW_AT_export_symbols
|
||||
|
||||
; CHECK: DW_TAG_namespace
|
||||
; CHECK-NEXT: DW_AT_name {{.*}} "normal"
|
||||
; CHECK-NOT: DW_AT_export_symbols
|
||||
; CHECK-NOT: NULL
|
||||
; CHECK: DW_TAG_namespace
|
||||
; CHECK-NEXT: DW_AT_name {{.*}} "inlined"
|
||||
; CHECK-NOT: DW_TAG
|
||||
; CHECK-NOT: NULL
|
||||
; CHECK: DW_AT_export_symbols [DW_FORM_flag_present] (true)
|
||||
; CHECK-NOT: DW_TAG
|
||||
; CHECK: DW_TAG_variable
|
||||
; CHECK-NEXT: DW_AT_name {{.*}} "i"
|
||||
|
||||
source_filename = "namespace.cpp"
|
||||
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-apple-macosx10.12.0"
|
||||
|
||||
@_ZN6normal7inlined1iE = global i32 0, align 4, !dbg !0
|
||||
|
||||
!llvm.dbg.cu = !{!5}
|
||||
!llvm.module.flags = !{!8, !9, !10}
|
||||
!llvm.ident = !{!11}
|
||||
|
||||
!0 = distinct !DIGlobalVariable(name: "i", linkageName: "_ZN6normal7inlined1iE", scope: !1, file: !2, line: 1, type: !4, isLocal: false, isDefinition: true)
|
||||
!1 = !DINamespace(name: "inlined", scope: !3, file: !2, line: 1, exportSymbols: true)
|
||||
!2 = !DIFile(filename: "namespace.cpp", directory: "/")
|
||||
!3 = !DINamespace(name: "normal", scope: null, file: !2, line: 1)
|
||||
!4 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
|
||||
!5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 4.0.0 (trunk 285825) (llvm/trunk 285822)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !6, globals: !7)
|
||||
!6 = !{}
|
||||
!7 = !{!0}
|
||||
!8 = !{i32 2, !"Dwarf Version", i32 5}
|
||||
!9 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!10 = !{i32 1, !"PIC Level", i32 2}
|
||||
!11 = !{!"clang version 4.0.0 (trunk 285825) (llvm/trunk 285822)"}
|
@ -1706,20 +1706,28 @@ TEST_F(DINamespaceTest, get) {
|
||||
DIFile *File = getFile();
|
||||
StringRef Name = "namespace";
|
||||
unsigned Line = 5;
|
||||
bool ExportSymbols = true;
|
||||
|
||||
auto *N = DINamespace::get(Context, Scope, File, Name, Line);
|
||||
auto *N = DINamespace::get(Context, Scope, File, Name, Line, ExportSymbols);
|
||||
|
||||
EXPECT_EQ(dwarf::DW_TAG_namespace, N->getTag());
|
||||
EXPECT_EQ(Scope, N->getScope());
|
||||
EXPECT_EQ(File, N->getFile());
|
||||
EXPECT_EQ(Name, N->getName());
|
||||
EXPECT_EQ(Line, N->getLine());
|
||||
EXPECT_EQ(N, DINamespace::get(Context, Scope, File, Name, Line));
|
||||
EXPECT_EQ(N,
|
||||
DINamespace::get(Context, Scope, File, Name, Line, ExportSymbols));
|
||||
|
||||
EXPECT_NE(N, DINamespace::get(Context, getFile(), File, Name, Line));
|
||||
EXPECT_NE(N, DINamespace::get(Context, Scope, getFile(), Name, Line));
|
||||
EXPECT_NE(N, DINamespace::get(Context, Scope, File, "other", Line));
|
||||
EXPECT_NE(N, DINamespace::get(Context, Scope, File, Name, Line + 1));
|
||||
EXPECT_NE(N,
|
||||
DINamespace::get(Context, getFile(), File, Name, Line, ExportSymbols));
|
||||
EXPECT_NE(N,
|
||||
DINamespace::get(Context, Scope, getFile(), Name, Line, ExportSymbols));
|
||||
EXPECT_NE(N,
|
||||
DINamespace::get(Context, Scope, File, "other", Line, ExportSymbols));
|
||||
EXPECT_NE(N,
|
||||
DINamespace::get(Context, Scope, File, Name, Line + 1, ExportSymbols));
|
||||
EXPECT_NE(N,
|
||||
DINamespace::get(Context, Scope, File, Name, Line, !ExportSymbols));
|
||||
|
||||
TempDINamespace Temp = N->clone();
|
||||
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
|
||||
|
Loading…
Reference in New Issue
Block a user