public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-8894] c: Fix ICE with _Atomic side-effect in nested fn param decls [PR94842] Date: Wed, 16 Sep 2020 19:21:44 +0000 (GMT) [thread overview] Message-ID: <20200916192144.EDA4C3951875@sourceware.org> (raw) https://gcc.gnu.org/g:b66139a3ba159473432edabb983c62219a28590d commit r9-8894-gb66139a3ba159473432edabb983c62219a28590d Author: Jakub Jelinek <jakub@redhat.com> Date: Thu Apr 30 21:48:30 2020 +0200 c: Fix ICE with _Atomic side-effect in nested fn param decls [PR94842] If there are _Atomic side-effects in the parameter declarations of non-nested function, when they are parsed, current_function_decl is NULL, the create_artificial_label created labels during build_atomic* are then adjusted by store_parm_decls through set_labels_context_r callback. Unfortunately, if such thing happens in nested function parameter declarations, while those decls are parsed current_function_decl is the parent function (and am not sure it is a good idea to temporarily clear it, some code perhaps should be aware it is in a nested function, or it can refer to variables from the parent function etc.) and that means store_param_decls through set_labels_context_r doesn't adjust anything. As those labels are emitted in the nested function body rather than in the parent, I think it is ok to override the context in those cases. 2020-04-30 Jakub Jelinek <jakub@redhat.com> PR c/94842 * c-decl.c (set_labels_context_r): In addition to context-less LABEL_DECLs adjust also LABEL_DECLs with context equal to parent function if any. (store_parm_decls): Adjust comment. * gcc.dg/pr94842.c: New test. (cherry picked from commit 61fb8963c22d91152a9c46a3512307bef3b3d7f7) Diff: --- gcc/c/c-decl.c | 15 +++++++++++---- gcc/testsuite/gcc.dg/pr94842.c | 11 +++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index caa2b75ac6d..80071112130 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -9464,15 +9464,18 @@ store_parm_decls_from (struct c_arg_info *arg_info) store_parm_decls (); } -/* Called by walk_tree to look for and update context-less labels. */ +/* Called by walk_tree to look for and update context-less labels + or labels with context in the parent function. */ static tree set_labels_context_r (tree *tp, int *walk_subtrees, void *data) { + tree ctx = static_cast<tree>(data); if (TREE_CODE (*tp) == LABEL_EXPR - && DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == NULL_TREE) + && (DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == NULL_TREE + || DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == DECL_CONTEXT (ctx))) { - DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) = static_cast<tree>(data); + DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) = ctx; *walk_subtrees = 0; } @@ -9543,7 +9546,11 @@ store_parm_decls (void) gotos, labels, etc. Because at that time the function decl for F has not been created yet, those labels do not have any function context. But we have the fndecl now, so update the - labels accordingly. gimplify_expr would crash otherwise. */ + labels accordingly. gimplify_expr would crash otherwise. + Or with nested functions the labels could be created with parent + function's context, while when the statement is emitted at the + start of the nested function, it needs the nested function's + context. */ walk_tree_without_duplicates (&arg_info->pending_sizes, set_labels_context_r, fndecl); add_stmt (arg_info->pending_sizes); diff --git a/gcc/testsuite/gcc.dg/pr94842.c b/gcc/testsuite/gcc.dg/pr94842.c new file mode 100644 index 00000000000..33d9d42644c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr94842.c @@ -0,0 +1,11 @@ +/* PR c/94842 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +_Atomic float x = 5; + +void +foo (void) +{ + void bar (float y[(int) (x += 2)]) {} +}
reply other threads:[~2020-09-16 19:21 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20200916192144.EDA4C3951875@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@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).