summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/DIBuilder.h11
-rw-r--r--include/llvm/DebugInfo.h1
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfDebug.cpp3
-rw-r--r--lib/IR/DIBuilder.cpp49
-rw-r--r--lib/IR/DebugInfo.cpp3
-rw-r--r--test/DebugInfo/namespace.ll78
6 files changed, 104 insertions, 41 deletions
diff --git a/include/llvm/DIBuilder.h b/include/llvm/DIBuilder.h
index 72da916e45..1fa7bc1da4 100644
--- a/include/llvm/DIBuilder.h
+++ b/include/llvm/DIBuilder.h
@@ -577,8 +577,17 @@ namespace llvm {
/// @param NS The namespace being imported here
/// @param Line Line number
DIImportedEntity createImportedModule(DIScope Context, DINameSpace NS,
- unsigned Line);
+ unsigned Line,
+ StringRef Name = StringRef());
+ /// \brief Create a descriptor for an imported module.
+ /// @param Context The scope this module is imported into
+ /// @param NS An aliased namespace
+ /// @param Line Line number
+ DIImportedEntity createImportedModule(DIScope Context, DIImportedEntity NS,
+ unsigned Line, StringRef Name);
+
+ /// \brief Create a descriptor for an imported function.
/// \brief Create a descriptor for an imported function.
/// @param Context The scope this module is imported into
/// @param Decl The declaration (or definition) of a function, type, or
diff --git a/include/llvm/DebugInfo.h b/include/llvm/DebugInfo.h
index 91c3066338..a4330070dc 100644
--- a/include/llvm/DebugInfo.h
+++ b/include/llvm/DebugInfo.h
@@ -695,6 +695,7 @@ namespace llvm {
DIScope getContext() const { return getFieldAs<DIScope>(1); }
DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
unsigned getLineNumber() const { return getUnsignedField(3); }
+ StringRef getName() const { return getStringField(4); }
bool Verify() const;
};
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 19bbc73815..b72e65340f 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -817,6 +817,9 @@ void DwarfDebug::constructImportedEntityDIE(CompileUnit *TheCU,
TheCU->addUInt(IMDie, dwarf::DW_AT_decl_file, 0, FileID);
TheCU->addUInt(IMDie, dwarf::DW_AT_decl_line, 0, Module.getLineNumber());
TheCU->addDIEEntry(IMDie, dwarf::DW_AT_import, dwarf::DW_FORM_ref4, EntityDie);
+ StringRef Name = Module.getName();
+ if (!Name.empty())
+ TheCU->addString(IMDie, dwarf::DW_AT_name, Name);
Context->addChild(IMDie);
}
diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp
index 4bb87c9afb..1c79945275 100644
--- a/lib/IR/DIBuilder.cpp
+++ b/lib/IR/DIBuilder.cpp
@@ -128,21 +128,50 @@ void DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
NMD->addOperand(TheCU);
}
-DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
- DINameSpace NS,
- unsigned Line) {
- Value *Elts[] = {
- GetTagConstant(VMContext, dwarf::DW_TAG_imported_module),
- Context,
- NS,
- ConstantInt::get(Type::getInt32Ty(VMContext), Line),
- };
- DIImportedEntity M(MDNode::get(VMContext, Elts));
+static DIImportedEntity
+createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS,
+ unsigned Line, StringRef Name,
+ SmallVectorImpl<Value *> &AllImportedModules) {
+ const MDNode *R;
+ if (Name.empty()) {
+ Value *Elts[] = {
+ GetTagConstant(C, dwarf::DW_TAG_imported_module),
+ Context,
+ NS,
+ ConstantInt::get(Type::getInt32Ty(C), Line),
+ };
+ R = MDNode::get(C, Elts);
+ } else {
+ Value *Elts[] = {
+ GetTagConstant(C, dwarf::DW_TAG_imported_module),
+ Context,
+ NS,
+ ConstantInt::get(Type::getInt32Ty(C), Line),
+ MDString::get(C, Name)
+ };
+ R = MDNode::get(C, Elts);
+ }
+ DIImportedEntity M(R);
assert(M.Verify() && "Imported module should be valid");
AllImportedModules.push_back(M);
return M;
}
+DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
+ DINameSpace NS, unsigned Line,
+ StringRef Name) {
+ return ::createImportedModule(VMContext, Context, NS, Line, Name,
+ AllImportedModules);
+}
+
+DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
+ DIImportedEntity NS,
+ unsigned Line,
+ StringRef Name) {
+ return ::createImportedModule(VMContext, Context, NS, Line, Name,
+ AllImportedModules);
+}
+
DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
DIDescriptor Decl,
unsigned Line) {
diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp
index 8a0fb8d5b1..6a014aee5f 100644
--- a/lib/IR/DebugInfo.cpp
+++ b/lib/IR/DebugInfo.cpp
@@ -591,7 +591,8 @@ bool DITemplateValueParameter::Verify() const {
/// \brief Verify that the imported module descriptor is well formed.
bool DIImportedEntity::Verify() const {
- return isImportedEntity() && DbgNode->getNumOperands() == 4;
+ return isImportedEntity() &&
+ (DbgNode->getNumOperands() == 4 || DbgNode->getNumOperands() == 5);
}
/// getOriginalTypeSize - If this type is derived from a base type then
diff --git a/test/DebugInfo/namespace.ll b/test/DebugInfo/namespace.ll
index 7db57638d0..81b8a877d3 100644
--- a/test/DebugInfo/namespace.ll
+++ b/test/DebugInfo/namespace.ll
@@ -73,6 +73,18 @@
; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x16)
; CHECK-NEXT: DW_AT_import{{.*}}=> {[[I]]})
; CHECK-NOT: NULL
+; CHECK: [[X:0x[0-9a-f]*]]:{{ *}}DW_TAG_imported_module
+; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2]])
+; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x18)
+; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]})
+; CHECK-NEXT: DW_AT_name{{.*}}"X"
+; CHECK-NOT: NULL
+; CHECK: DW_TAG_imported_module
+; CHECK-NEXT: DW_AT_decl_file{{.*}}(0x0[[F2]])
+; CHECK-NEXT: DW_AT_decl_line{{.*}}(0x19)
+; CHECK-NEXT: DW_AT_import{{.*}}=> {[[X]]})
+; CHECK-NEXT: DW_AT_name{{.*}}"Y"
+; CHECK-NOT: NULL
; CHECK: DW_TAG_lexical_block
; CHECK-NOT: NULL
; CHECK: DW_TAG_imported_module
@@ -119,7 +131,9 @@
; using B::f1;
; using B::i;
; bar x;
-; return i;
+; namespace X = A;
+; namespace Y = X;
+; return i + X::B::i + Y::B::i;
; }
%"struct.A::B::bar" = type { i8 }
@@ -129,7 +143,7 @@
; Function Attrs: nounwind uwtable
define void @_ZN1A1B2f1Ev() #0 {
entry:
- ret void, !dbg !39
+ ret void, !dbg !41
}
; Function Attrs: nounwind uwtable
@@ -137,8 +151,8 @@ define void @_ZN1A1B2f1Ei(i32) #0 {
entry:
%.addr = alloca i32, align 4
store i32 %0, i32* %.addr, align 4
- call void @llvm.dbg.declare(metadata !{i32* %.addr}, metadata !40), !dbg !41
- ret void, !dbg !41
+ call void @llvm.dbg.declare(metadata !{i32* %.addr}, metadata !42), !dbg !43
+ ret void, !dbg !43
}
; Function Attrs: nounwind readnone
@@ -152,25 +166,29 @@ entry:
%x = alloca %"struct.A::B::bar", align 1
%frombool = zext i1 %b to i8
store i8 %frombool, i8* %b.addr, align 1
- call void @llvm.dbg.declare(metadata !{i8* %b.addr}, metadata !42), !dbg !43
- %0 = load i8* %b.addr, align 1, !dbg !44
- %tobool = trunc i8 %0 to i1, !dbg !44
- br i1 %tobool, label %if.then, label %if.end, !dbg !44
+ call void @llvm.dbg.declare(metadata !{i8* %b.addr}, metadata !44), !dbg !45
+ %0 = load i8* %b.addr, align 1, !dbg !46
+ %tobool = trunc i8 %0 to i1, !dbg !46
+ br i1 %tobool, label %if.then, label %if.end, !dbg !46
if.then: ; preds = %entry
- %1 = load i32* @_ZN1A1B1iE, align 4, !dbg !45
- store i32 %1, i32* %retval, !dbg !45
- br label %return, !dbg !45
+ %1 = load i32* @_ZN1A1B1iE, align 4, !dbg !47
+ store i32 %1, i32* %retval, !dbg !47
+ br label %return, !dbg !47
if.end: ; preds = %entry
- call void @llvm.dbg.declare(metadata !{%"struct.A::B::bar"* %x}, metadata !46), !dbg !47
- %2 = load i32* @_ZN1A1B1iE, align 4, !dbg !48
- store i32 %2, i32* %retval, !dbg !48
- br label %return, !dbg !48
+ call void @llvm.dbg.declare(metadata !{%"struct.A::B::bar"* %x}, metadata !48), !dbg !49
+ %2 = load i32* @_ZN1A1B1iE, align 4, !dbg !50
+ %3 = load i32* @_ZN1A1B1iE, align 4, !dbg !50
+ %add = add nsw i32 %2, %3, !dbg !50
+ %4 = load i32* @_ZN1A1B1iE, align 4, !dbg !50
+ %add1 = add nsw i32 %add, %4, !dbg !50
+ store i32 %add1, i32* %retval, !dbg !50
+ br label %return, !dbg !50
return: ; preds = %if.end, %if.then
- %3 = load i32* %retval, !dbg !49
- ret i32 %3, !dbg !49
+ %5 = load i32* %retval, !dbg !51
+ ret i32 %5, !dbg !51
}
attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
@@ -199,7 +217,7 @@ attributes #1 = { nounwind readnone }
!18 = metadata !{i32 786468, null, null, metadata !"bool", i32 0, i64 8, i64 8, i64 0, i32 0, i32 2} ; [ DW_TAG_base_type ] [bool] [line 0, size 8, align 8, offset 0, enc DW_ATE_boolean]
!19 = metadata !{metadata !20}
!20 = metadata !{i32 786484, i32 0, metadata !6, metadata !"i", metadata !"i", metadata !"_ZN1A1B1iE", metadata !15, i32 2, metadata !13, i32 0, i32 1, i32* @_ZN1A1B1iE, null} ; [ DW_TAG_variable ] [i] [line 2] [def]
-!21 = metadata !{metadata !22, metadata !23, metadata !24, metadata !26, metadata !27, metadata !29, metadata !37, metadata !38}
+!21 = metadata !{metadata !22, metadata !23, metadata !24, metadata !26, metadata !27, metadata !29, metadata !37, metadata !38, metadata !39, metadata !40}
!22 = metadata !{i32 786490, metadata !7, metadata !6, i32 8} ; [ DW_TAG_imported_module ]
!23 = metadata !{i32 786490, metadata !0, metadata !7, i32 11} ; [ DW_TAG_imported_module ]
!24 = metadata !{i32 786490, metadata !25, metadata !6, i32 15} ; [ DW_TAG_imported_module ]
@@ -217,14 +235,16 @@ attributes #1 = { nounwind readnone }
!36 = metadata !{i32 786468}
!37 = metadata !{i32 786440, metadata !14, metadata !10, i32 21} ; [ DW_TAG_imported_declaration ]
!38 = metadata !{i32 786440, metadata !14, metadata !20, i32 22} ; [ DW_TAG_imported_declaration ]
-!39 = metadata !{i32 3, i32 0, metadata !4, null}
-!40 = metadata !{i32 786689, metadata !10, metadata !"", metadata !15, i32 16777220, metadata !13, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [line 4]
-!41 = metadata !{i32 4, i32 0, metadata !10, null}
-!42 = metadata !{i32 786689, metadata !14, metadata !"b", metadata !15, i32 16777229, metadata !18, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [b] [line 13]
-!43 = metadata !{i32 13, i32 0, metadata !14, null}
-!44 = metadata !{i32 14, i32 0, metadata !14, null}
-!45 = metadata !{i32 16, i32 0, metadata !25, null}
-!46 = metadata !{i32 786688, metadata !14, metadata !"x", metadata !15, i32 23, metadata !30, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [x] [line 23]
-!47 = metadata !{i32 23, i32 0, metadata !14, null}
-!48 = metadata !{i32 24, i32 0, metadata !14, null}
-!49 = metadata !{i32 25, i32 0, metadata !14, null}
+!39 = metadata !{i32 786490, metadata !14, metadata !7, i32 24, metadata !"X"} ; [ DW_TAG_imported_module ]
+!40 = metadata !{i32 786490, metadata !14, metadata !39, i32 25, metadata !"Y"} ; [ DW_TAG_imported_module ]
+!41 = metadata !{i32 3, i32 0, metadata !4, null}
+!42 = metadata !{i32 786689, metadata !10, metadata !"", metadata !15, i32 16777220, metadata !13, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [line 4]
+!43 = metadata !{i32 4, i32 0, metadata !10, null}
+!44 = metadata !{i32 786689, metadata !14, metadata !"b", metadata !15, i32 16777229, metadata !18, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [b] [line 13]
+!45 = metadata !{i32 13, i32 0, metadata !14, null}
+!46 = metadata !{i32 14, i32 0, metadata !14, null}
+!47 = metadata !{i32 16, i32 0, metadata !25, null}
+!48 = metadata !{i32 786688, metadata !14, metadata !"x", metadata !15, i32 23, metadata !30, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [x] [line 23]
+!49 = metadata !{i32 23, i32 0, metadata !14, null}
+!50 = metadata !{i32 26, i32 0, metadata !14, null}
+!51 = metadata !{i32 27, i32 0, metadata !14, null}