From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7884 invoked by alias); 7 Dec 2015 17:01:25 -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 7867 invoked by uid 89); 7 Dec 2015 17:01:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 07 Dec 2015 17:01:23 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 394F91306; Mon, 7 Dec 2015 17:01:22 +0000 (UTC) Received: from redhat.com (ovpn-204-18.brq.redhat.com [10.40.204.18]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tB7H1IVO026222 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 7 Dec 2015 12:01:21 -0500 Date: Mon, 07 Dec 2015 17:01:00 -0000 From: Marek Polacek To: Joseph Myers Cc: GCC Patches Subject: Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL) Message-ID: <20151207170117.GN3175@redhat.com> References: <20151203175646.GI3175@redhat.com> <20151203212656.GJ3175@redhat.com> <20151207135409.GM3175@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-SW-Source: 2015-12/txt/msg00769.txt.bz2 On Mon, Dec 07, 2015 at 04:05:11PM +0000, Joseph Myers wrote: > On Mon, 7 Dec 2015, Marek Polacek wrote: > > > + if (orig_qual_indirect != 0) > > + orig_qual_type = TREE_TYPE (orig_qual_type); > > + else > > + orig_qual_indirect--; > > For optimal results for debug info, I think that should be == 0 (i.e. > preserve orig_qual_type, which may be a typedef, if possible - if the > parameter is an array of orig_qual_type), rather than != 0. I'm confused now. If orig_qual_indirect != 0, it is indirect, right? Earlier you said: "if orig_qual_indirect is indirect, in that case you may get better results from changing orig_qual_type without decrementing orig_qual_indirect." Isn't that something else than this version with == 0? Anyway, here's the version with == 0. Thanks, Bootstrapped/regtested on x86_64-linux, ok for trunk? 2015-12-07 Marek Polacek PR c/68668 * c-decl.c (grokdeclarator): If ORIG_QUAL_INDIRECT is indirect, use TREE_TYPE of ORIG_QUAL_TYPE, otherwise decrement ORIG_QUAL_INDIRECT. * gcc.dg/pr68668.c: New test. diff --git gcc/c/c-decl.c gcc/c/c-decl.c index 9ad8219..6a85514 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -6417,6 +6417,13 @@ grokdeclarator (const struct c_declarator *declarator, { /* Transfer const-ness of array into that of type pointed to. */ type = TREE_TYPE (type); + if (orig_qual_type != NULL_TREE) + { + if (orig_qual_indirect == 0) + orig_qual_type = TREE_TYPE (orig_qual_type); + else + orig_qual_indirect--; + } if (type_quals) type = c_build_qualified_type (type, type_quals, orig_qual_type, orig_qual_indirect); diff --git gcc/testsuite/gcc.dg/pr68668.c gcc/testsuite/gcc.dg/pr68668.c index e69de29..d013aa9 100644 --- gcc/testsuite/gcc.dg/pr68668.c +++ gcc/testsuite/gcc.dg/pr68668.c @@ -0,0 +1,53 @@ +/* PR c/68668 */ +/* { dg-do compile } */ + +typedef const int T[]; +typedef const int U[1]; + +int +fn1 (T p) +{ + return p[0]; +} + +int +fn2 (U p[2]) +{ + return p[0][0]; +} + +int +fn3 (U p[2][3]) +{ + return p[0][0][0]; +} + +int +fn4 (U *p) +{ + return p[0][0]; +} + +int +fn5 (U (*p)[1]) +{ + return (*p)[0][0]; +} + +int +fn6 (U (*p)[1][2]) +{ + return (*p)[0][0][0]; +} + +int +fn7 (U **p) +{ + return p[0][0][0]; +} + +int +fn8 (U (**p)[1]) +{ + return (*p)[0][0][0]; +} Marek