diff options
author | David Blaikie <dblaikie@gmail.com> | 2013-06-05 05:39:59 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2013-06-05 05:39:59 +0000 |
commit | 032d62487c888fe1ce500dfe9e22ae76efbe18e5 (patch) | |
tree | cc966f7443407005ecf5cb053e5c5f1856ee176a /lib/CodeGen | |
parent | ad7ecc65b1b1d6466ff035168c86f208a91aa1b4 (diff) | |
download | external_llvm-032d62487c888fe1ce500dfe9e22ae76efbe18e5.zip external_llvm-032d62487c888fe1ce500dfe9e22ae76efbe18e5.tar.gz external_llvm-032d62487c888fe1ce500dfe9e22ae76efbe18e5.tar.bz2 |
PR15662: Optimized debug info produces out of order function parameters
When a function is inlined we lazily construct the variables
representing the function's parameters. After that, we add any remaining
unused parameters.
If the function doesn't use all the parameters, or uses them out of
order, then the DWARF would produce them in that order, producing a
parameter order that doesn't match the source.
This fix causes us to always keep the arg variables at the start of the
variable list & in the original order from the source.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183297 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index e761afe..f7337d7 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1626,9 +1626,37 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) { } void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) { -// SmallVector<DbgVariable *, 8> &Vars = ScopeVariables.lookup(LS); - ScopeVariables[LS].push_back(Var); -// Vars.push_back(Var); + SmallVectorImpl<DbgVariable *> &Vars = ScopeVariables[LS]; + DIVariable DV = Var->getVariable(); + if (DV.getTag() == dwarf::DW_TAG_arg_variable) { + DISubprogram Ctxt(DV.getContext()); + DIArray Variables = Ctxt.getVariables(); + // If the variable is a parameter (arg_variable) and this is an optimized + // build (the subprogram has a 'variables' list) make sure we keep the + // parameters in order. Otherwise we would produce an incorrect function + // type with parameters out of order if function parameters were used out of + // order or unused (see the call to addScopeVariable in endFunction where + // the remaining unused variables (including parameters) are added). + if (unsigned NumVariables = Variables.getNumElements()) { + // Keep the parameters at the start of the variables list. Search through + // current variable list (Vars) and the full function variable list in + // lock-step looking for this parameter in the full list to find the + // insertion point. + SmallVectorImpl<DbgVariable *>::iterator I = Vars.begin(); + unsigned j = 0; + while (I != Vars.end() && j != NumVariables && + Variables.getElement(j) != DV && + (*I)->getVariable().getTag() == dwarf::DW_TAG_arg_variable) { + if (Variables.getElement(j) == (*I)->getVariable()) + ++I; + ++j; + } + Vars.insert(I, Var); + return; + } + } + + Vars.push_back(Var); } // Gather and emit post-function debug information. |