DebugInfo: Fix ordering of members after r191928
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 4 Oct 2013 01:39:59 +0000 (01:39 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 4 Oct 2013 01:39:59 +0000 (01:39 +0000)
commitc32f2332b065d0fb8de4db8b8ca0981564dae92b
tree4ec8f6a3f1f347d8717c9fabce8a6fbe1db55d0c
parentb868e9101c138016aad5bd910b67f40a3213d6fc
DebugInfo: Fix ordering of members after r191928

In the case (shown in the attached test) where a member function
definition was emitted into debug info the following could occur:

1) build the debug info for the member function definition
2) in (1), build the debug info for the member function declaration
3) construct and add the member function declaration DIE
4) add it to its context
5) build its context (the type it is a member of)
6) construct the members and add them to the type
7) except don't add member functions because "getOrCreateSubprogram"
adds the function to its parent anyway
8) except we're only partway through building this subprogram
declaration so it hasn't been added yet - but we returned the partially
constructed DIE (since it's already in the MDNode->DIE mapping to avoid
infinitely recursing trying to create the member function DIE)
9) once the type is constructed, add the member function to it
10) now the members are out of order (the member function being defined
is listed as the last member, even though it was declared as the first)

To avoid this, construct the context of the subprogram DIE before we
query to see if it exists. That way we never end up creating it before
creating its context and ending up in this situation.

Alternatively, the type construction that visits/builds all the members
could call something like getOrCreateSubprogram, but that doesn't ever
do the "add to context" step. Then the type building code would always
be responsible for adding members (and the subprogram "addToContextDIE"
would no-op because the context building would have added the subprogram
declaration to the type/context DIE already).

(the test cases updated were overly-sensitive to offsets or abbreviation
numbers. We don't have a nice way to make these tests more robust as yet
- multiline FileCheck matches would be required)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191939 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
test/DebugInfo/X86/DW_AT_specification.ll
test/DebugInfo/X86/concrete_out_of_line.ll
test/DebugInfo/X86/pr11300.ll
test/DebugInfo/member-order.ll [new file with mode: 0644]