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);
// 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);
// 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 {