From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 5283C3858C54 for ; Thu, 19 May 2022 09:46:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5283C3858C54 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 45BC32188C; Thu, 19 May 2022 09:46:35 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 3ED7A2C141; Thu, 19 May 2022 09:46:35 +0000 (UTC) Date: Thu, 19 May 2022 09:46:35 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] pointer-query: Fix ICE with non-pointer param [PR105635] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 May 2022 09:46:37 -0000 On Thu, 19 May 2022, Jakub Jelinek wrote: > Hi! > > The gimple_parm_array_size function comment talks about pointe parameters > but doesn't actually verify it, it checks whether an attribute is present > on the function and then just uses TREE_TYPE (TREE_TYPE (var)) which > assumes a pointer type (or in theory could work for ARRAY_TYPE but > c-family languages which only have that attribute will never have ARRAY_TYPE > parameters; and for VECTOR_TYPE/COMPLEX_TYPE it would mean something quite > different). > > So, this patch punts early if var doesn't have pointer/reference type. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. Richard. > 2022-05-19 Jakub Jelinek > > PR c/105635 > * poiinter-query.cc (gimple_parm_array_size): Return NULL if var > doesn't have pointer or reference type. > > * gcc.dg/pr105635.c: New test. > > --- gcc/pointer-query.cc.jj 2022-05-13 09:34:23.996147311 +0200 > +++ gcc/pointer-query.cc 2022-05-18 12:12:21.398849571 +0200 > @@ -555,7 +555,7 @@ gimple_parm_array_size (tree ptr, wide_i > from the current function declaratation (e.g., attribute access or > related). */ > tree var = SSA_NAME_VAR (ptr); > - if (TREE_CODE (var) != PARM_DECL) > + if (TREE_CODE (var) != PARM_DECL || !POINTER_TYPE_P (TREE_TYPE (var))) > return NULL_TREE; > > const unsigned prec = TYPE_PRECISION (sizetype); > --- gcc/testsuite/gcc.dg/pr105635.c.jj 2022-05-18 12:23:56.868371600 +0200 > +++ gcc/testsuite/gcc.dg/pr105635.c 2022-05-18 12:23:41.728577929 +0200 > @@ -0,0 +1,11 @@ > +/* PR c/105635 */ > +/* { dg-do compile } */ > +/* { dg-options "-Wall" } */ > + > +void foo (int, int[*]); /* { dg-message "previous declaration of 'foo' with type" } */ > + > +foo (int x, int y) /* { dg-warning "return type defaults to 'int'" } */ > +{ /* { dg-warning "conflicting types for 'foo'" "" { target *-*-* } .-1 } */ > + /* { dg-message "declared here" "" { target *-*-* } .-2 } */ > + return (x >= 0) != (y < 0); /* { dg-warning "'return' with a value, in function returning void" } */ > +} > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)