From: Frederic Riss Date: Wed, 5 Nov 2014 19:19:04 +0000 (+0000) Subject: [DebugInfo] Do not record artificial global initializer functions in the DeclCache. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86751f338dbac8aa4112506b1a6983c37deb4199;p=clang [DebugInfo] Do not record artificial global initializer functions in the DeclCache. When we are generating the global initializer functions, we call CGDebugInfo::EmitFunctionStart() with a valid decl which is describing the initialized global variable. Do not update the DeclCache with this key as it will overwrite the the cached variable DIGlobalVariable with the newly created artificial DISubprogram. One could wonder if we should put artificial subprograms in the DIE tree at all (there are vaild uses for them carrying line information though). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221385 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index ea8002ab96..4442841296 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2527,7 +2527,10 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc, getOrCreateFunctionType(D, FnType, Unit), Fn->hasInternalLinkage(), true /*definition*/, ScopeLine, Flags, CGM.getLangOpts().Optimize, Fn, TParamsArray, getFunctionDeclaration(D)); - if (HasDecl) + // We might get here with a VarDecl in the case we're generating + // code for the initialization of globals. Do not record these decls + // as they will overwrite the actual VarDecl Decl in the cache. + if (HasDecl && isa(D)) DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(SP))); // Push the function onto the lexical block stack. diff --git a/test/CodeGenCXX/debug-info-namespace.cpp b/test/CodeGenCXX/debug-info-namespace.cpp index 1512e9d79c..da2fefdc32 100644 --- a/test/CodeGenCXX/debug-info-namespace.cpp +++ b/test/CodeGenCXX/debug-info-namespace.cpp @@ -5,8 +5,8 @@ namespace A { #line 1 "foo.cpp" namespace B { -int i; -void f1() { } +extern int i; +int f1() { return 0; } void f1(int) { } struct foo; struct bar { }; @@ -19,7 +19,7 @@ using namespace B; using namespace A; namespace E = A; - +int B::i = f1(); int func(bool b) { if (b) { using namespace A::B; @@ -51,8 +51,8 @@ using B::i; // CHECK: [[FILE]] {{.*}}debug-info-namespace.cpp" // CHECK: [[BAR:![0-9]*]] {{.*}} ; [ DW_TAG_structure_type ] [bar] [line 6, {{.*}}] [decl] [from ] // CHECK: [[F1:![0-9]*]] {{.*}} ; [ DW_TAG_subprogram ] [line 4] [def] [f1] -// CHECK: [[FUNC:![0-9]*]] {{.*}} ; [ DW_TAG_subprogram ] {{.*}} [def] [func] // CHECK: [[FILE2]]} ; [ DW_TAG_file_type ] [{{.*}}foo.cpp] +// CHECK: [[FUNC:![0-9]*]] {{.*}} ; [ DW_TAG_subprogram ] {{.*}} [def] [func] // CHECK: [[I:![0-9]*]] = metadata !{metadata !"0x34\00i\00{{.*}}", metadata [[NS]], {{.*}} ; [ DW_TAG_variable ] [i] // CHECK: [[MODULES]] = metadata !{metadata [[M1:![0-9]*]], metadata [[M2:![0-9]*]], metadata [[M3:![0-9]*]], metadata [[M4:![0-9]*]], metadata [[M5:![0-9]*]], metadata [[M6:![0-9]*]], metadata [[M7:![0-9]*]], metadata [[M8:![0-9]*]], metadata [[M9:![0-9]*]], metadata [[M10:![0-9]*]], metadata [[M11:![0-9]*]], metadata [[M12:![0-9]*]], metadata [[M13:![0-9]*]]} // CHECK: [[M1]] = metadata !{metadata !"0x3a\0011\00", metadata [[CTXT]], metadata [[NS]]} ; [ DW_TAG_imported_module ]