Partially revert r204517 and fix a different way:

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.

llvm-svn: 205368
This commit is contained in:
Eric Christopher 2014-04-01 22:25:28 +00:00
parent 91567b6700
commit 885c41b28c
2 changed files with 22 additions and 10 deletions

View 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);

View 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 {