From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 5F6E7383D802; Mon, 30 May 2022 03:36:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F6E7383D802 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8432] pointer-query: Fix ICE with non-pointer param [PR105635] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 864dcf71c87a6afdc534073ee53aea684f7bb985 X-Git-Newrev: 7b88f9b8881b7653b5a834da1b2b8fda463e61c0 Message-Id: <20220530033643.5F6E7383D802@sourceware.org> Date: Mon, 30 May 2022 03:36:43 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 May 2022 03:36:43 -0000 https://gcc.gnu.org/g:7b88f9b8881b7653b5a834da1b2b8fda463e61c0 commit r12-8432-g7b88f9b8881b7653b5a834da1b2b8fda463e61c0 Author: Jakub Jelinek Date: Thu May 19 11:56:21 2022 +0200 pointer-query: Fix ICE with non-pointer param [PR105635] 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. 2022-05-19 Jakub Jelinek PR c/105635 * pointer-query.cc (gimple_parm_array_size): Return NULL if var doesn't have pointer or reference type. * gcc.dg/pr105635.c: New test. (cherry picked from commit 3b4daa0b3c3d8eb2ac3b40ad6898f314ed4d7919) Diff: --- gcc/pointer-query.cc | 2 +- gcc/testsuite/gcc.dg/pr105635.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gcc/pointer-query.cc b/gcc/pointer-query.cc index d93657f3206..b133e7cad14 100644 --- a/gcc/pointer-query.cc +++ b/gcc/pointer-query.cc @@ -554,7 +554,7 @@ gimple_parm_array_size (tree ptr, wide_int rng[2], 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); diff --git a/gcc/testsuite/gcc.dg/pr105635.c b/gcc/testsuite/gcc.dg/pr105635.c new file mode 100644 index 00000000000..aa02f593bfa --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105635.c @@ -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" } */ +}