]> granicus.if.org Git - clang/commitdiff
Partially revert r204517 and fix a different way:
authorEric Christopher <echristo@gmail.com>
Tue, 1 Apr 2014 22:25:28 +0000 (22:25 +0000)
committerEric Christopher <echristo@gmail.com>
Tue, 1 Apr 2014 22:25:28 +0000 (22:25 +0000)
We don't want to encourage the code to emit a lexical block for
a function that needs one in order for the line table to change,
we need to grab the line information from the body of the pattern
that we were instantiated from, this code should do that.

Modify the test case to ensure that we're still looking in the
right place for all of the scopes and also that we haven't
created a lexical block where we didn't need one.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205368 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
test/CodeGenCXX/linetable-fnbegin.cpp

index 2556cf98508cd2f76bd591b5ca9494bb161e2e60..df6a3ead641f1e3580425586f83e260389a98153 100644 (file)
@@ -2497,14 +2497,25 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType,
   FnBeginRegionCount.push_back(LexicalBlockStack.size());
 
   const Decl *D = GD.getDecl();
-  // Function may lack declaration in source code if it is created by Clang
-  // CodeGen (examples: _GLOBAL__I_a, __cxx_global_array_dtor, thunk).
+
+  // Use the location of the start of the function to determine where
+  // the function definition is located. By default use the location
+  // of the declaration as the location for the subprogram. A function
+  // may lack a declaration in the source code if it is created by code
+  // gen. (examples: _GLOBAL__I_a, __cxx_global_array_dtor, thunk).
   bool HasDecl = (D != 0);
-  // Use the location of the declaration.
   SourceLocation Loc;
-  if (HasDecl)
+  if (HasDecl) {
     Loc = D->getLocation();
 
+    // If this is a function specialization then use the pattern body
+    // as the location for the function.
+    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+      if (const FunctionDecl *SpecDecl = FD->getTemplateInstantiationPattern())
+        if (SpecDecl->hasBody(SpecDecl))
+          Loc = SpecDecl->getLocation();
+  }
+
   unsigned Flags = 0;
   llvm::DIFile Unit = getOrCreateFile(Loc);
   llvm::DIDescriptor FDContext(Unit);
@@ -2585,8 +2596,6 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType,
   // Push the function onto the lexical block stack.
   llvm::MDNode *SPN = SP;
   LexicalBlockStack.push_back(SPN);
-  // Initialize PrevLoc to the location of the function header.
-  PrevLoc = Loc;
 
   if (HasDecl)
     RegionMap[D] = llvm::WeakVH(SP);
index 81e7f7b82a545c1ca4248a599636ad5ab98c4813..24ca5731268b3b8b816b3ba264dc3225a3d4e8df 100644 (file)
@@ -3,10 +3,13 @@
 // right header file.
 // CHECK: define{{.*}}bar
 // CHECK-NOT: define
-// CHECK: ret {{.*}}, !dbg ![[DBG:.*]]
-// CHECK: ![[HPP:.*]] = metadata !{metadata !"./template.hpp",
-// CHECK: ![[DBG]] = metadata !{i32 23, i32 0, metadata ![[BLOCK:.*]], null}
-// CHECK: ![[BLOCK]] = metadata !{{{.*}}, metadata ![[HPP]], {{.*}}} ; [ DW_TAG_lexical_block ]
+// CHECK: ret {{.*}}, !dbg [[DBG:.*]]
+// CHECK: [[HPP:.*]] = metadata !{metadata !"./template.hpp",
+// CHECK: [[SP:.*]] = metadata !{i32 786478, metadata [[HPP]], metadata !"_ZTS3FooIiE", metadata !"bar", metadata !"bar", metadata !"_ZN3FooIiE3barEv", i32 22, metadata !8, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 (%class.Foo*)* @_ZN3FooIiE3barEv, null, metadata !7, metadata !2, i32 22} ; [ DW_TAG_subprogram ] [line 22] [def] [bar]
+// We shouldn't need a lexical block for this function.
+// CHECK: [[DBG]] = metadata !{i32 23, i32 0, metadata [[SP]], null}
+
+
 # 1 "./template.h" 1
 template <typename T>
 class Foo {