public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/102276] -ftrivial-auto-var-init fails to initialize a variable, causes a spurious warning
Date: Wed, 02 Mar 2022 16:55:34 +0000	[thread overview]
Message-ID: <bug-102276-4-yR8thoOp7N@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102276-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102276

--- Comment #15 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Qing Zhao <qinzhao@gcc.gnu.org>:

https://gcc.gnu.org/g:dbaabd06aaf4a1b0f2a20671c39148a0bd6ccf0e

commit r12-7452-gdbaabd06aaf4a1b0f2a20671c39148a0bd6ccf0e
Author: Qing Zhao <qing.zhao@oracle.com>
Date:   Wed Mar 2 16:48:37 2022 +0000

    Don't emit switch-unreachable warnings for -ftrivial-auto-var-init
(PR102276)

    At the same time, adding -Wtrivial-auto-var-init and update documentation.
     -Wtrivial-auto-var-init and update documentation.

    for the following testing case:
    1 int g(int *);
    2 int f1()
    3 {
    4     switch (0) {
    5         int x;
    6         default:
    7         return g(&x);
    8     }
    9 }
    compiling with -O -ftrivial-auto-var-init causes spurious warning:
    warning: statement will never be executed [-Wswitch-unreachable]
    5 |         int x;
      |             ^
    This is due to the compiler-generated initialization at the point of
    the declaration.

    We could avoid the warning  to exclude the following cases:

    when
    flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    And
    1) call to .DEFERRED_INIT
    2) call to __builtin_clear_padding if the 2nd argument is present and
non-zero
    3) a gimple assign store right after the .DEFERRED_INIT call that has the
LHS
       as RHS

    However, we still need to warn users about the incapability of the option
    -ftrivial-auto-var-init by adding a new warning option
-Wtrivial-auto-var-init
    to report cases when it cannot initialize the auto variable. At the same
    time, update documentation for -ftrivial-auto-var-init to connect it with
    the new warning option -Wtrivial-auto-var-init,  and add documentation
    for -Wtrivial-auto-var-init.

    gcc/ChangeLog:

            PR middle-end/102276
            * common.opt (-Wtrivial-auto-var-init): New option.
            * doc/invoke.texi (-Wtrivial-auto-var-init): Document new option.
            (-ftrivial-auto-var-init): Update option;
            * gimplify.cc (emit_warn_switch_unreachable): New function.
            (warn_switch_unreachable_r): Rename to ...
            (warn_switch_unreachable_and_auto_init_r): This.
            (maybe_warn_switch_unreachable): Rename to ...
            (maybe_warn_switch_unreachable_and_auto_init): This.
            (gimplify_switch_expr): Update calls to renamed function.

    gcc/testsuite/ChangeLog:

            PR middle-end/102276
            * gcc.dg/auto-init-pr102276-1.c: New test.
            * gcc.dg/auto-init-pr102276-2.c: New test.
            * gcc.dg/auto-init-pr102276-3.c: New test.
            * gcc.dg/auto-init-pr102276-4.c: New test.

  parent reply	other threads:[~2022-03-02 16:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 14:17 [Bug middle-end/102276] New: " amonakov at gcc dot gnu.org
2021-09-13 10:14 ` [Bug middle-end/102276] " rguenth at gcc dot gnu.org
2021-09-13 17:50 ` amonakov at gcc dot gnu.org
2021-09-14 17:55 ` kees at outflux dot net
2022-02-12 18:14 ` kees at outflux dot net
2022-02-12 20:22 ` pinskia at gcc dot gnu.org
2022-02-14  7:26 ` rguenth at gcc dot gnu.org
2022-02-14 16:08 ` jakub at gcc dot gnu.org
2022-02-14 17:02 ` qinzhao at gcc dot gnu.org
2022-02-14 23:21 ` qinzhao at gcc dot gnu.org
2022-02-15  8:16 ` rguenther at suse dot de
2022-02-15 16:02 ` qinzhao at gcc dot gnu.org
2022-02-15 19:55 ` qinzhao at gcc dot gnu.org
2022-02-17  7:22 ` rguenther at suse dot de
2022-02-17 19:57 ` qinzhao at gcc dot gnu.org
2022-03-02 16:55 ` cvs-commit at gcc dot gnu.org [this message]
2022-03-02 16:56 ` qinzhao 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-102276-4-yR8thoOp7N@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: link
Be 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).