From 211d68dda14d6b773ad648909ef9dd0d65ec2053 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 24 Nov 2020 15:23:57 -0700 Subject: [PATCH] PR c/97955 - ICE in build_array_type_1 on invalid redeclaration of function with VLA parameter gcc/c-family/ChangeLog: * c-warn.c (warn_parm_array_mismatch): Avoid invalid redeclarations. gcc/testsuite/ChangeLog: * gcc.dg/pr97955.c: New test. --- gcc/c-family/c-warn.c | 4 ++-- gcc/testsuite/gcc.dg/pr97955.c | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr97955.c diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c index 6d22a11..91abafe 100644 --- a/gcc/c-family/c-warn.c +++ b/gcc/c-family/c-warn.c @@ -3379,8 +3379,9 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms) return; /* Only check pointers and C++ references. */ + tree curptype = TREE_TYPE (curp); tree newptype = TREE_TYPE (newp); - if (!POINTER_TYPE_P (newptype)) + if (!POINTER_TYPE_P (curptype) || !POINTER_TYPE_P (newptype)) continue; /* Skip mismatches in __builtin_va_list that is commonly @@ -3430,7 +3431,6 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms) if (origloc == UNKNOWN_LOCATION) origloc = newloc; - tree curptype = TREE_TYPE (curp); const std::string newparmstr = newa->array_as_string (newptype); const std::string curparmstr = cura->array_as_string (curptype); if (new_vla_p && !cur_vla_p) diff --git a/gcc/testsuite/gcc.dg/pr97955.c b/gcc/testsuite/gcc.dg/pr97955.c new file mode 100644 index 0000000..a5236c7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97955.c @@ -0,0 +1,7 @@ +/* PR 97955 - ICE in build_array_type_1 on invalid redeclaration of function + with VLA parameter + { dg-do compile } + { dg-options "-Wall" } */ + +void f (int n, int a[n]); +void f (int *b) { } // { dg-error "conflicting types" } -- 2.7.4