From patchwork Sun Jul 1 16:19:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 937591 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-480807-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="AG6W9s3k"; 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 41JbDz2r8Lz9s1B for ; Mon, 2 Jul 2018 02:19:29 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=euNEsnvNR+cvDrIzAK06jrDdybADNmUe9mi04ZF4wr+gn+hL3sn0/ N6yc08Zy2b4NXWjpRvb48C7bSOpAqLApQ3/XQVpHAt5ONT6U3iHGef9ruYKUeVjp oHWbcqsgtInfLO9g2R57fe5cuiHucopX6XKGfceNCWm6je7Jtwxy8w= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=fUBH3b3hZ1KcvOJ6/cflTwrpvUk=; b=AG6W9s3kc+DpK1P6X4b9 b7VWa2RECLO46fraJThNWx4gntkYW1KYr6weuCLajZgorzKETnHBYQrghQMNfwD5 3woUSQtMUOmF+wusgTZtEOLyScQg3PznKV1mFU+U2bCz8u/lp4H+gLU/j8FhgA/d YsdBC61Q+8b3SPsOiHi5c8g= Received: (qmail 4545 invoked by alias); 1 Jul 2018 16:19:22 -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 4528 invoked by uid 89); 1 Jul 2018 16:19:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=loc, relevant X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 01 Jul 2018 16:19:20 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B2CA5ADBA for ; Sun, 1 Jul 2018 16:19:18 +0000 (UTC) Date: Sun, 1 Jul 2018 18:19:20 +0200 From: Tom de Vries To: gcc-patches@gcc.gnu.org Subject: [testsuite/guality, committed] Prevent optimization of local in vla-1.c Message-ID: <20180701161920.lzm5ikaiyr3pspxn@delia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170912 (1.9.0) X-IsSubscribed: yes Hi, Atm vla-1.c has the following failures: ... FAIL: gcc.dg/guality/vla-1.c -O1 -DPREVENT_OPTIMIZATION line 17 sizeof (a) == 6 FAIL: gcc.dg/guality/vla-1.c -O2 -DPREVENT_OPTIMIZATION line 17 sizeof (a) == 6 FAIL: gcc.dg/guality/vla-1.c -O3 -g -DPREVENT_OPTIMIZATION line 17 sizeof (a) == 6 FAIL: gcc.dg/guality/vla-1.c -Os -DPREVENT_OPTIMIZATION line 17 sizeof (a) == 6 FAIL: gcc.dg/guality/vla-1.c -O2 -flto -fno-use-linker-plugin -flto-partition=none -DPREVENT_OPTIMIZATION line 17 sizeof (a) == 6 FAIL: gcc.dg/guality/vla-1.c -O2 -flto -fno-use-linker-plugin -flto-partition=none -DPREVENT_OPTIMIZATION line 24 sizeof (a) == 17 * sizeof (short) FAIL: gcc.dg/guality/vla-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects -DPREVENT_OPTIMIZATION line 17 sizeof (a) == 6 FAIL: gcc.dg/guality/vla-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects -DPREVENT_OPTIMIZATION line 24 sizeof (a) == 17 * sizeof (short) ... For the non-lto failures, the relevant bit is: ... int __attribute__((noinline)) f1 (int i) { char a[i + 1]; a[0] = 5; /* { dg-final { gdb-test .+1 "i" "5" } } */ return a[0]; /* { dg-final { gdb-test . "sizeof (a)" "6" } } */ } ... which at -O1 already ends up as: ... # vla-1.c:14:1 .loc 1 14 1 is_stmt 1 .cfi_startproc # DEBUG i => di # vla-1.c:15:3 .loc 1 15 3 # DEBUG => sxn(di+0x1)-0x1 # vla-1.c:16:3 .loc 1 16 3 # vla-1.c:17:3 .loc 1 17 3 # vla-1.c:18:1 .loc 1 18 1 is_stmt 0 movl $5, %eax ret ... So, the local vla a is optimized away. This patch adds VOLATILE to 'a', which prevents it from being optimized away, and fixes the non-lto failures. Committed as obvious. Thanks, - Tom [testsuite/guality] Prevent optimization of local in vla-1.c 2018-07-01 Tom de Vries * gcc.dg/guality/prevent-optimization.h (VOLATILE): Define. * gcc.dg/guality/vla-1.c (f1): Mark local vla a as VOLATILE. --- gcc/testsuite/gcc.dg/guality/prevent-optimization.h | 2 ++ gcc/testsuite/gcc.dg/guality/vla-1.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/guality/prevent-optimization.h b/gcc/testsuite/gcc.dg/guality/prevent-optimization.h index 0ef84a3d9c8..57e945cafb4 100644 --- a/gcc/testsuite/gcc.dg/guality/prevent-optimization.h +++ b/gcc/testsuite/gcc.dg/guality/prevent-optimization.h @@ -21,8 +21,10 @@ along with GCC; see the file COPYING3. If not see #ifdef PREVENT_OPTIMIZATION #define ATTRIBUTE_USED __attribute__((used)) +#define VOLATILE volatile #else #define ATTRIBUTE_USED +#define VOLATILE #endif #endif diff --git a/gcc/testsuite/gcc.dg/guality/vla-1.c b/gcc/testsuite/gcc.dg/guality/vla-1.c index 264b9f3f92b..d281185c18c 100644 --- a/gcc/testsuite/gcc.dg/guality/vla-1.c +++ b/gcc/testsuite/gcc.dg/guality/vla-1.c @@ -2,6 +2,8 @@ /* { dg-do run } */ /* { dg-options "-g" } */ +#include "prevent-optimization.h" + void __attribute__((noinline)) bar (short *p) { @@ -12,7 +14,7 @@ bar (short *p) int __attribute__((noinline)) f1 (int i) { - char a[i + 1]; + VOLATILE char a[i + 1]; a[0] = 5; /* { dg-final { gdb-test .+1 "i" "5" } } */ return a[0]; /* { dg-final { gdb-test . "sizeof (a)" "6" } } */ }