From patchwork Sun Jun 16 10:51:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 251667 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 13F1D2C00A2 for ; Sun, 16 Jun 2013 20:53:14 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=phMHNA6530Ls1TU6 FjtIop8toeo47VAjkPdL7l86ufcpUW/SqoG0XXPmpwh9FaMiGwTm7ibehLuPbmiM xqALR60R4csMrRcQG860VVNepioCfSeA9ji5d6VoVfvxiy7yvCCcNxZMoeS1/yPT +IPtOuBZgcTU9qXRgJ8HkuYgD8A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=8bgomqsPXnaoh/2pG0IGvg lvpaQ=; b=TpZTKwazmdP9Ypr0/S9T8/I8RAuewYQiJCf+7KLKZZR4x1N0QHFghI 5YlIGhvzTJp0KmB5wzAVV1Bs6dRCseHSztP5E7hVhXpeFUSStTN/Uju8zb9ecHMF A8vx56NzEsTqMAmqmT6VMuCWh1+VQmo1Cy1+rCHR/5Tf5i31WXBSw= Received: (qmail 18159 invoked by alias); 16 Jun 2013 10:53:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 18150 invoked by uid 89); 16 Jun 2013 10:53:08 -0000 X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.1 Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 16 Jun 2013 10:53:07 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 408C9264D7FE for ; Sun, 16 Jun 2013 12:50:57 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FScNklawoEpi for ; Sun, 16 Jun 2013 12:50:57 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 18DE6264D7EF for ; Sun, 16 Jun 2013 12:50:57 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Improve debug info for small structures passed by reference Date: Sun, 16 Jun 2013 12:51:25 +0200 Message-ID: <15074732.mILDtaeVB4@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.29-desktop; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 X-Virus-Found: No Hi, the subject is slightly misleading since it's actually about structures with integral modes which are passed by reference on some platforms, e.g. SPARC or PowerPC 32-bit. There are 3 issues: 1. At -O0, the parameters of this kind are not homed on the stack, which means that backtraces can display for them. 2. Since the fix for PR debug/48163, the locations emitted at -O1 and above for them are totally bogus (there is a bogus additional dereference). 3. The location lists are quickly wrong for them because they fail to take into account that the register parameter is clobbered. The attached patch addresses 1. and 2. fully and 3. partially (for now). It has been tested on x86-64 and PowerPC/Linux. OK for the mainline? 2013-06-16 Eric Botcazou * function.c (assign_parm_setup_reg): For a parameter passed by pointer and which can live in a register, always retrieve the value on entry. * var-tracking.c (add_stores): Treat the copy on entry for a parameter passed by invisible reference specially. (emit_notes_in_bb) : Emit notes before the instruction. (vt_add_function_parameter): Correctly deal with a parameter passed by invisible reference. Index: function.c =================================================================== --- function.c (revision 200122) +++ function.c (working copy) @@ -3084,17 +3084,27 @@ assign_parm_setup_reg (struct assign_par emit_move_insn (parmreg, validated_mem); /* If we were passed a pointer but the actual value can safely live - in a register, put it in one. */ - if (data->passed_pointer - && TYPE_MODE (TREE_TYPE (parm)) != BLKmode - /* If by-reference argument was promoted, demote it. */ - && (TYPE_MODE (TREE_TYPE (parm)) != GET_MODE (DECL_RTL (parm)) - || use_register_for_decl (parm))) + in a register, retrieve it and use it directly. */ + if (data->passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode) { /* We can't use nominal_mode, because it will have been set to Pmode above. We must use the actual mode of the parm. */ - parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm))); - mark_user_reg (parmreg); + if (use_register_for_decl (parm)) + { + parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm))); + mark_user_reg (parmreg); + } + else + { + int align = STACK_SLOT_ALIGNMENT (TREE_TYPE (parm), + TYPE_MODE (TREE_TYPE (parm)), + TYPE_ALIGN (TREE_TYPE (parm))); + parmreg + = assign_stack_local (TYPE_MODE (TREE_TYPE (parm)), + GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parm))), + align); + set_mem_attributes (parmreg, parm, 1); + } if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm))) { Index: var-tracking.c =================================================================== --- var-tracking.c (revision 200122) +++ var-tracking.c (working copy) @@ -5836,7 +5836,24 @@ add_stores (rtx loc, const_rtx expr, voi { rtx xexpr = gen_rtx_SET (VOIDmode, loc, src); if (same_variable_part_p (src, REG_EXPR (loc), REG_OFFSET (loc))) - mo.type = MO_COPY; + { + /* If this is an instruction copying (part of) a parameter + passed by invisible reference to its register location, + pretend it's a SET so that the initial memory location + is discarded, as the parameter register can be reused + for other purposes and we do not track locations based + on generic registers. */ + if (MEM_P (src) + && REG_EXPR (loc) + && TREE_CODE (REG_EXPR (loc)) == PARM_DECL + && DECL_MODE (REG_EXPR (loc)) != BLKmode + && MEM_P (DECL_INCOMING_RTL (REG_EXPR (loc))) + && XEXP (DECL_INCOMING_RTL (REG_EXPR (loc)), 0) + != arg_pointer_rtx) + mo.type = MO_SET; + else + mo.type = MO_COPY; + } else mo.type = MO_SET; mo.u.loc = xexpr; @@ -9086,7 +9103,7 @@ emit_notes_in_bb (basic_block bb, datafl else var_mem_set (set, loc, VAR_INIT_STATUS_UNINITIALIZED, NULL); - emit_notes_for_changes (insn, EMIT_NOTE_AFTER_INSN, set->vars); + emit_notes_for_changes (insn, EMIT_NOTE_BEFORE_INSN, set->vars); } break; @@ -9533,12 +9550,11 @@ vt_add_function_parameter (tree parm) if (!vt_get_decl_and_offset (incoming, &decl, &offset)) { - if (REG_P (incoming) || MEM_P (incoming)) + if (MEM_P (incoming)) { /* This means argument is passed by invisible reference. */ offset = 0; decl = parm; - incoming = gen_rtx_MEM (GET_MODE (decl_rtl), incoming); } else {