From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AA3DC3857BA4; Wed, 11 Jan 2023 16:48:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA3DC3857BA4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673455685; bh=A4u+cDM+qVZH9qd4Nd+gbDrDcktAmCoA9Vq6m5E0MYk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TLBWmpKcg4NDDWAybCtG1x2JvH7RVBfK3U1no1BwB+jQXnxuGUEeUckhb1R25otYC RNz50C9lEL9rP2Q/BVaZiVVnCwiaEyYkgBXMgtlPC7VIgXTh1MFkVSZleTQoQKWxnl X6e/schXnYAsYMOfQDJ/zzGiUJzP5fYjbF6+PbQA= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105180] [10/11/12/13 Regression] K&R style definition does not evaluate array size Date: Wed, 11 Jan 2023 16:48:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: needs-bisection, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105180 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org, | |jsm28 at gcc dot gnu.org --- Comment #7 from Jakub Jelinek --- int global =3D 0; int foo (void) { ++global; return 1; } void baz (void) { void bar (s, c) char *s; char c[static foo ()]; { } bar ("1", "1"); bar ("1", "1"); bar ("1", "1"); } int main () { baz (); if (global !=3D 3) __builtin_abort (); return 0; } shows that for nested functions those side-effects are emitted, but at a wr= ong location. The side-effects in that case are evaluated when passing through the defini= tion of bar inside of the baz function, rather than when bar is called. So above, foo () is called just once, not 3 times. If standard C declarations are used: int global =3D 0; int foo (void) { return ++global; } void bar (char *s, char c[static foo ()]) { } int main () { bar ("1", "1"); if (global !=3D 1) __builtin_abort (); return 0; } then it works properly, in that case the pending sizes are recorded by c_parser_parms_list_declarator -> push_parm_decl -> grokdeclarator and queu= ed by get_parm_info called from c_parser_parms_list_declarator. But in case of K&R argument declarations, those are done by: while (c_parser_next_token_is_not (parser, CPP_EOF) && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) c_parser_declaration_or_fndef (parser, false, false, false, true, false); in c_parser_declaration_or_fndef and in that case that nested c_parser_declaration_or_fndef calls start_decl which after calling grokdeclarator which collects the pending expressions just does: if (expr) add_stmt (fold_convert (void_type_node, expr)); and so it is unclear where exactly it is pushed for the non-nested function= s, for nested ones at the current statement location (the definition of nested function). Bet we need to arrange for those side-effects to be instead remembered somewhere and queued into pending_sizes later.=