From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 84944 invoked by alias); 28 Sep 2017 18:33:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 84935 invoked by uid 89); 28 Sep 2017 18:33:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Sep 2017 18:33:47 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB3AD26822; Thu, 28 Sep 2017 18:33:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CB3AD26822 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jakub@redhat.com Received: from tucnak.zalov.cz (ovpn-116-41.ams2.redhat.com [10.36.116.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 96E2B1758B; Thu, 28 Sep 2017 18:33:41 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v8SIXcVa010062; Thu, 28 Sep 2017 20:33:38 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v8SIXaiI010061; Thu, 28 Sep 2017 20:33:36 +0200 Date: Thu, 28 Sep 2017 18:33:00 -0000 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [C PATCH] Fix flags on compound literal VAR_DECLs (PR c/82340) Message-ID: <20170928183336.GC1701@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-09/txt/msg01892.txt.bz2 Hi! As the testcase shows, while build_compound_literal had some code to set up TREE_READONLY flag on compound literal VAR_DECLs, it didn't handle volatile nor restrict quals. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-09-28 Jakub Jelinek PR c/82340 * c-decl.c (build_compound_literal): Use c_apply_type_quals_to_decl instead of trying to set just TREE_READONLY manually. * gcc.dg/tree-ssa/pr82340.c: New test. --- gcc/c/c-decl.c.jj 2017-09-19 16:38:14.000000000 +0200 +++ gcc/c/c-decl.c 2017-09-27 15:18:53.066566172 +0200 @@ -5247,9 +5247,7 @@ build_compound_literal (location_t loc, DECL_ARTIFICIAL (decl) = 1; DECL_IGNORED_P (decl) = 1; TREE_TYPE (decl) = type; - TREE_READONLY (decl) = (TYPE_READONLY (type) - || (TREE_CODE (type) == ARRAY_TYPE - && TYPE_READONLY (TREE_TYPE (type)))); + c_apply_type_quals_to_decl (TYPE_QUALS (strip_array_types (type)), decl); store_init_value (loc, decl, init, NULL_TREE); if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) --- gcc/testsuite/gcc.dg/tree-ssa/pr82340.c.jj 2017-09-27 16:01:36.696296732 +0200 +++ gcc/testsuite/gcc.dg/tree-ssa/pr82340.c 2017-09-27 16:02:09.262886860 +0200 @@ -0,0 +1,14 @@ +/* PR c/82340 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ssa" } */ +/* { dg-final { scan-tree-dump "D.\[0-9]*\\\[0\\\] ={v} 77;" "ssa" } } */ + +int +foo (void) +{ + int i; + volatile char *p = (volatile char[1]) { 77 }; + for (i = 1; i < 10; i++) + *p = 4; + return *p; +} Jakub