]> granicus.if.org Git - clang/commitdiff
[DebugInfo] Do not record artificial global initializer functions in the DeclCache.
authorFrederic Riss <friss@apple.com>
Wed, 5 Nov 2014 19:19:04 +0000 (19:19 +0000)
committerFrederic Riss <friss@apple.com>
Wed, 5 Nov 2014 19:19:04 +0000 (19:19 +0000)
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

lib/CodeGen/CGDebugInfo.cpp
test/CodeGenCXX/debug-info-namespace.cpp

index ea8002ab96997847e5853608024b180445d5827d..44428412968f15d51d79977a3437d134eb9d6087 100644 (file)
@@ -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<FunctionDecl>(D))
     DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(SP)));
 
   // Push the function onto the lexical block stack.
index 1512e9d79cc67b5c2f72244492b3c8ef5ea1cc33..da2fefdc328576b5c34cea7636f801222627d9a4 100644 (file)
@@ -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 ]