From patchwork Sun Jul 7 09:41:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1128622 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-504533-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IE6VGC4m"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45hNrz2SPpz9s8m for ; Sun, 7 Jul 2019 19:41:55 +1000 (AEST) 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; q=dns; s= default; b=LOxJpX75VsBG35c8/9Lp9jrlAcu2LEwFRP3XC3QD/SH4LtgpPfKSj bom2wpdEG6a6yWvkyvK2boFUpV9m9MHedUQsmhaBiPF/q9pnmB+WONsyhdJdoKnf cPU1oNLwi+BEYByl6LSpetpzTJVS2put5wCNxE8tT5wHgm9EO/YC90= 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; s= default; bh=8JWDNAlM3R+jUqO6NMvhdPBeu9U=; b=IE6VGC4maJrgVxMjCK30 jVSCgtrd7dq3vczpFh5GrmvE3Y5osYOf2H8GH/UlbspC1iuzALXfMTTSmQ4F/uZL w66dyDqJkISD0HsIFAbHEOk2Ng0TgxB54KAoMEdONePg3CiIF9HssWLIXjC9MoSK +mZo72+dH/ReTcseBRPxWm4= Received: (qmail 9337 invoked by alias); 7 Jul 2019 09:41:48 -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 9326 invoked by uid 89); 7 Jul 2019 09:41:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 07 Jul 2019 09:41:46 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 017AE360 for ; Sun, 7 Jul 2019 02:41:45 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.39]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9D22C3F246 for ; Sun, 7 Jul 2019 02:41:44 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Prevent -Og from deleting stores to write-only variables Date: Sun, 07 Jul 2019 10:41:43 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 This patch prevents -Og from deleting stores to write-only variables, so that the values are still available when debugging. This seems more convenient than forcing users to use __attribute__((used)) (probably conditionally, if it's not something they want in release builds). Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard 2019-07-07 Richard Sandiford gcc/ * tree-cfg.c (execute_fixup_cfg): Don't delete stores to write-only variables for -Og. gcc/testsuite/ * c-c++-common/guality/Og-static-wo-1.c: New test. * g++.dg/guality/guality.exp: Separate the c-c++-common tests into "Og" and "general" tests. Run the latter at -O0 and -Og only. * gcc.dg/guality/guality.exp: Likewise. Index: gcc/tree-cfg.c =================================================================== --- gcc/tree-cfg.c 2019-07-06 09:25:08.717486045 +0100 +++ gcc/tree-cfg.c 2019-07-07 10:29:19.999365874 +0100 @@ -9571,7 +9571,8 @@ execute_fixup_cfg (void) Keep access when store has side effect, i.e. in case when source is volatile. */ if (gimple_store_p (stmt) - && !gimple_has_side_effects (stmt)) + && !gimple_has_side_effects (stmt) + && !optimize_debug) { tree lhs = get_base_address (gimple_get_lhs (stmt)); Index: gcc/testsuite/c-c++-common/guality/Og-static-wo-1.c =================================================================== --- /dev/null 2019-06-14 15:59:19.298479944 +0100 +++ gcc/testsuite/c-c++-common/guality/Og-static-wo-1.c 2019-07-07 10:29:19.999365874 +0100 @@ -0,0 +1,15 @@ +/* { dg-do run } */ +/* { dg-options "-g" } */ + +#include "../../gcc.dg/nop.h" + +static int x = 0; + +int +main (void) +{ + asm volatile (NOP); /* { dg-final { gdb-test . "x" "0" } } */ + x = 1; + asm volatile (NOP); /* { dg-final { gdb-test . "x" "1" } } */ + return 0; +} Index: gcc/testsuite/g++.dg/guality/guality.exp =================================================================== --- gcc/testsuite/g++.dg/guality/guality.exp 2019-07-01 10:15:31.000000000 +0100 +++ gcc/testsuite/g++.dg/guality/guality.exp 2019-07-07 10:29:19.999365874 +0100 @@ -65,8 +65,22 @@ if {[check_guality " return 0; } "]} { - gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C]] "" "" - gcc-dg-runtest [lsort [glob $srcdir/c-c++-common/guality/*.c]] "" "" + set general [list] + set Og [list] + foreach file [lsort [glob $srcdir/c-c++-common/guality/*.c]] { + switch -glob -- [file tail $file] { + Og-* { lappend Og $file } + * { lappend general $file } + } + } + + gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C]] "" "" + gcc-dg-runtest $general "" "" + set-torture-options \ + [list "-O0" "-Og"] \ + [list {}] \ + [list "-Og -flto"] + gcc-dg-runtest $Og "" "" } if [info exists guality_gdb_name] { Index: gcc/testsuite/gcc.dg/guality/guality.exp =================================================================== --- gcc/testsuite/gcc.dg/guality/guality.exp 2019-07-01 10:15:31.000000000 +0100 +++ gcc/testsuite/gcc.dg/guality/guality.exp 2019-07-07 10:29:19.999365874 +0100 @@ -80,8 +80,22 @@ if {[check_guality " return 0; } "]} { - gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" "" - gcc-dg-runtest [lsort [glob $srcdir/c-c++-common/guality/*.c]] "" "-Wc++-compat" + set general [list] + set Og [list] + foreach file [lsort [glob $srcdir/c-c++-common/guality/*.c]] { + switch -glob -- [file tail $file] { + Og-* { lappend Og $file } + * { lappend general $file } + } + } + + gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" "" + gcc-dg-runtest $general "" "-Wc++-compat" + set-torture-options \ + [list "-O0" "-Og"] \ + [list {}] \ + [list "-Og -flto"] + gcc-dg-runtest $Og "" "-Wc++-compat" } if [info exists guality_gdb_name] {