From owner-svn-src-head@FreeBSD.ORG Wed Jun 5 19:46:40 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 418B89EE; Wed, 5 Jun 2013 19:46:40 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 1B2921D70; Wed, 5 Jun 2013 19:46:40 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r55JkdD7017732; Wed, 5 Jun 2013 19:46:39 GMT (envelope-from dim@svn.freebsd.org) Received: (from dim@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r55JkdjL017731; Wed, 5 Jun 2013 19:46:39 GMT (envelope-from dim@svn.freebsd.org) Message-Id: <201306051946.r55JkdjL017731@svn.freebsd.org> From: Dimitry Andric Date: Wed, 5 Jun 2013 19:46:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r251431 - head/contrib/llvm/lib/CodeGen/AsmPrinter X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Jun 2013 19:46:40 -0000 Author: dim Date: Wed Jun 5 19:46:39 2013 New Revision: 251431 URL: http://svnweb.freebsd.org/changeset/base/251431 Log: 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 MFC after: 1 week Modified: head/contrib/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Modified: head/contrib/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp ============================================================================== --- head/contrib/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Wed Jun 5 19:40:52 2013 (r251430) +++ head/contrib/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Wed Jun 5 19:46:39 2013 (r251431) @@ -1538,9 +1538,37 @@ void DwarfDebug::beginFunction(const Mac } void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) { -// SmallVector &Vars = ScopeVariables.lookup(LS); - ScopeVariables[LS].push_back(Var); -// Vars.push_back(Var); + SmallVectorImpl &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::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.