Skip to content

Commit cf5e5ba

Browse files
committed
PR14606: Debug info for using directives/DW_TAG_imported_module
More changes later for using declarations/DW_TAG_imported_declaration. llvm-svn: 179837
1 parent 88564f3 commit cf5e5ba

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,6 +2929,13 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD,
29292929
getStaticDataMemberDeclaration(VD));
29302930
}
29312931

2932+
void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) {
2933+
DBuilder.createImportedModule(
2934+
getContextDescriptor(cast<Decl>(UD.getDeclContext())),
2935+
getOrCreateNameSpace(UD.getNominatedNamespace()),
2936+
getLineNumber(UD.getLocation()));
2937+
}
2938+
29322939
/// getOrCreateNamesSpace - Return namespace descriptor for the given
29332940
/// namespace decl.
29342941
llvm::DINameSpace

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ class CGDebugInfo {
262262
/// EmitGlobalVariable - Emit global variable's debug info.
263263
void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init);
264264

265+
/// \brief - Emit C++ using directive.
266+
void EmitUsingDirective(const UsingDirectiveDecl &UD);
267+
265268
/// getOrCreateRecordType - Emit record type's standalone debug info.
266269
llvm::DIType getOrCreateRecordType(QualType Ty, SourceLocation L);
267270

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
8080
case Decl::CXXRecord: // struct/union/class X; [C++]
8181
case Decl::Using: // using X; [C++]
8282
case Decl::UsingShadow:
83-
case Decl::UsingDirective: // using namespace X; [C++]
8483
case Decl::NamespaceAlias:
8584
case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
8685
case Decl::Label: // __label__ x;
@@ -90,6 +89,10 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
9089
// None of these decls require codegen support.
9190
return;
9291

92+
case Decl::UsingDirective: // using namespace X; [C++]
93+
if (CGDebugInfo *DI = getDebugInfo())
94+
DI->EmitUsingDirective(cast<UsingDirectiveDecl>(D));
95+
return;
9396
case Decl::Var: {
9497
const VarDecl &VD = cast<VarDecl>(D);
9598
assert(VD.isLocalVarDecl() &&

clang/test/CodeGenCXX/debug-info-namespace.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ int i;
77
}
88
}
99

10+
int func() {
11+
using namespace A::B;
12+
return i;
13+
}
14+
15+
// CHECK: [[MODULES:![0-9]*]], metadata !""} ; [ DW_TAG_compile_unit ]
1016
// CHECK: [[FILE:![0-9]*]] {{.*}}debug-info-namespace.cpp"
17+
// CHECK: [[FUNC:![0-9]*]] {{.*}} ; [ DW_TAG_subprogram ] [line 6] [def] [func]
18+
// CHECK: [[FILE2:![0-9]*]]} ; [ DW_TAG_file_type ] [{{.*}}foo.cpp]
1119
// CHECK: [[VAR:![0-9]*]] = {{.*}}, metadata [[NS:![0-9]*]], metadata !"i", {{.*}} ; [ DW_TAG_variable ] [i]
12-
// CHECK: [[NS]] = {{.*}}, metadata [[FILE2:![0-9]*]], metadata [[CTXT:![0-9]*]], {{.*}} ; [ DW_TAG_namespace ] [B] [line 1]
20+
// CHECK: [[NS]] = {{.*}}, metadata [[FILE2]], metadata [[CTXT:![0-9]*]], {{.*}} ; [ DW_TAG_namespace ] [B] [line 1]
1321
// CHECK: [[CTXT]] = {{.*}}, metadata [[FILE]], null, {{.*}} ; [ DW_TAG_namespace ] [A] [line 3]
14-
// CHECK: [[FILE2]]} ; [ DW_TAG_file_type ] [{{.*}}foo.cpp]
22+
// CHECK: [[MODULES]] = metadata !{metadata [[MODULE:![0-9]*]]}
23+
// CHECK: [[MODULE]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[NS]], i32 7} ; [ DW_TAG_imported_module ]
1524

1625
// FIXME: It is confused on win32 to generate file entry when dosish filename is given.
1726
// REQUIRES: shell

0 commit comments

Comments
 (0)