From patchwork Wed Jun 20 22:50:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xinliang David Li X-Patchwork-Id: 166160 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]) by ozlabs.org (Postfix) with SMTP id 5B842B6FB9 for ; Thu, 21 Jun 2012 08:51:14 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1340837475; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=BjNBBNy xrFXwZ/7OQUIUIesytRQ=; b=HxIz6n81tKjcmYSwaRyDvkWCgkueX87ngspq5WZ camDM1DbKtfxdv805301dwdX9ShvKmWsAhJ6fP456nfQMUk8EmncoJnCDzWL7IcM kwk9I1NvCnP0NKk5Tgk6allt1+DeftJIBL/FN+Omfi/pyXJ+xN/Foy3x4H18jtK1 qzVI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Cc:Content-Type:X-System-Of-Record:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=qrxP7ojQeUx6pgtYcZJPHNVGEpLrnSFKB570TbBujdpHbR9LkaEXpns2lonkUW ++qcigMny9kQjdoTOdrPOhX8tlArqCC6C1qo4+7iyWighlfmxTy5nsqXloq3RPeT 8n7tR5FkTONcrLIfFNsyoSzZGa9wsOfsfGWilCikQJnr8=; Received: (qmail 2358 invoked by alias); 20 Jun 2012 22:51:06 -0000 Received: (qmail 2346 invoked by uid 22791); 20 Jun 2012 22:51:03 -0000 X-SWARE-Spam-Status: No, hits=-4.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-lb0-f175.google.com (HELO mail-lb0-f175.google.com) (209.85.217.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 Jun 2012 22:50:50 +0000 Received: by lbol5 with SMTP id l5so1360400lbo.20 for ; Wed, 20 Jun 2012 15:50:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type :x-system-of-record:x-gm-message-state; bh=6uIySPXtsZ/E6jLeKVh0gPtLb7E/LFvv/i+mGDRiQGs=; b=F68sXLUWK1OvaC1ghEVVNzS/t/mkduxnytZ5Y9xlyKuzboGaowY5tC3XVdmd47xVZh EvtDRyBWP1MPMycqjOig/poxrnW+GRXnFeiZCiLxoKKx6Ubdh+7gmdj0EbE7pXOugb2N OogvxiAcumrp+xVrwjF5WHIMCANpmH30yTPmNgCX5jJlX+8iijBYjZmwZ++egKNufjkM sz0WgmKMsEyKYu/rooqOr+wqOasqGqJHUX2OlVEuvAOa6u/Y7iQ/0BPXCsmmJYXeME8S 4T4MH6vIh8UIr48RRjo6+a6F0qs//JgHz8qW6/iilRubNP78l191V6/k4e5Pi5yKjnZz yGOQ== Received: by 10.112.83.200 with SMTP id s8mr10658230lby.13.1340232648867; Wed, 20 Jun 2012 15:50:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.83.200 with SMTP id s8mr10658222lby.13.1340232648684; Wed, 20 Jun 2012 15:50:48 -0700 (PDT) Received: by 10.152.115.34 with HTTP; Wed, 20 Jun 2012 15:50:48 -0700 (PDT) Date: Wed, 20 Jun 2012 15:50:48 -0700 Message-ID: Subject: New option to turn off stack reuse for temporaries From: Xinliang David Li To: GCC Patches Cc: Jason Merrill , Richard Guenther X-System-Of-Record: true X-Gm-Message-State: ALoCoQlCbSjli6MiAdL26K+2E53jq7z7yji1hJ1DYnsZQnykN5G9kuCq1qJkZ9eun+V/RHUGibgiRR0qsZVnfXA9BPYcjpBL8ERBuY7EiZSYGheBjuZoRSgau/Fa9LZCY18WFEjwzUmX3HE66s1StiYGbigPxRf+QA== X-IsSubscribed: yes 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 One of the most common runtime errors we have seen in gcc-4_7 is caused by dangling references to temporaries whole life time have ended e.g, const A& a = foo(); or foo (A());// where temp's address is saved and used after foo. Of course this is user error according to the standard, triaging of bugs like this is pretty time consuming to triage. This patch tries to introduce an option to disable stack reuse for temporaries, which can be used to debugging purpose. Is this good for trunk? thanks, David 2012-06-20 Xinliang David Li * common.opt: -ftemp-reuse-stack option. * gimplify.c (gimplify_target_expr): Check new flag. Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 188362) +++ doc/invoke.texi (working copy) @@ -1003,6 +1003,7 @@ See S/390 and zSeries Options. -fstack-limit-register=@var{reg} -fstack-limit-symbol=@var{sym} @gol -fno-stack-limit -fsplit-stack @gol -fleading-underscore -ftls-model=@var{model} @gol +-ftemp-stack-reuse @gol -ftrapv -fwrapv -fbounds-check @gol -fvisibility -fstrict-volatile-bitfields} @end table @@ -19500,6 +19501,10 @@ indices used to access arrays are within currently only supported by the Java and Fortran front ends, where this option defaults to true and false respectively. +@item -ftemp-stack-reuse +@opindex ftemp_stack_reuse +This option enables stack space reuse for temporaries. The default is on. + @item -ftrapv @opindex ftrapv This option generates traps for signed overflow on addition, subtraction, Index: gimplify.c =================================================================== --- gimplify.c (revision 188362) +++ gimplify.c (working copy) @@ -5487,7 +5487,8 @@ gimplify_target_expr (tree *expr_p, gimp /* Add a clobber for the temporary going out of scope, like gimplify_bind_expr. */ if (gimplify_ctxp->in_cleanup_point_expr - && needs_to_live_in_memory (temp)) + && needs_to_live_in_memory (temp) + && flag_temp_stack_reuse) { tree clobber = build_constructor (TREE_TYPE (temp), NULL); TREE_THIS_VOLATILE (clobber) = true; Index: common.opt =================================================================== --- common.opt (revision 188362) +++ common.opt (working copy) @@ -1322,6 +1322,10 @@ fif-conversion2 Common Report Var(flag_if_conversion2) Optimization Perform conversion of conditional jumps to conditional execution +ftemp-stack-reuse +Common Report Var(flag_temp_stack_reuse) Init(1) +Enable stack reuse for compiler generated temps + ftree-loop-if-convert Common Report Var(flag_tree_loop_if_convert) Init(-1) Optimization Convert conditional jumps in innermost loops to branchless equivalents