public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-105180-4-IKP5xgLzPh@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-105180-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105180 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org, | |jsm28 at gcc dot gnu.org --- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> --- int global = 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 != 3) __builtin_abort (); return 0; } shows that for nested functions those side-effects are emitted, but at a wrong location. The side-effects in that case are evaluated when passing through the definition 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 = 0; int foo (void) { return ++global; } void bar (char *s, char c[static foo ()]) { } int main () { bar ("1", "1"); if (global != 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 queued 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 functions, 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.
next prev parent reply other threads:[~2023-01-11 16:48 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-06 14:33 [Bug c/105180] New: " gcc at emil dot codes 2022-04-09 6:33 ` [Bug c/105180] " egallager at gcc dot gnu.org 2022-04-21 15:18 ` [Bug c/105180] [9/10/11/12 Regression] " jsm28 at gcc dot gnu.org 2022-05-27 9:47 ` [Bug c/105180] [10/11/12/13 " rguenth at gcc dot gnu.org 2022-06-28 10:48 ` jakub at gcc dot gnu.org 2022-11-15 6:38 ` pinskia at gcc dot gnu.org 2022-11-15 6:48 ` pinskia at gcc dot gnu.org 2022-11-15 6:52 ` pinskia at gcc dot gnu.org 2023-01-11 16:48 ` jakub at gcc dot gnu.org [this message] 2023-01-13 9:36 ` jakub at gcc dot gnu.org 2023-07-07 10:42 ` [Bug c/105180] [11/12/13/14 " rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-105180-4-IKP5xgLzPh@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).