svn commit: r251645 - stable/9/contrib/llvm/lib/CodeGen/AsmPrinter

Dimitry Andric dim at FreeBSD.org
Wed Jun 12 07:04:27 UTC 2013


Author: dim
Date: Wed Jun 12 07:04:27 2013
New Revision: 251645
URL: http://svnweb.freebsd.org/changeset/base/251645

Log:
  MFC r251431:
  
  Pull in r183297 from upstream llvm trunk:
  
    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.
  
  Reported by:	avg

Modified:
  stable/9/contrib/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Directory Properties:
  stable/9/contrib/llvm/   (props changed)

Modified: stable/9/contrib/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
==============================================================================
--- stable/9/contrib/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp	Wed Jun 12 06:56:15 2013	(r251644)
+++ stable/9/contrib/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp	Wed Jun 12 07:04:27 2013	(r251645)
@@ -1447,9 +1447,37 @@ void DwarfDebug::beginFunction(const Mac
 }
 
 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);
 }
 
 /// endFunction - Gather and emit post-function debug information.


More information about the svn-src-stable-9 mailing list