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 c/103310] null comparison with a weak symbol eliminated
Date: Wed, 01 Dec 2021 18:24:57 +0000	[thread overview]
Message-ID: <bug-103310-4-OLc16jD5Jt@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103310-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:53caa4723d8de73fe21e63ba264082f3071b2887

commit r12-5696-g53caa4723d8de73fe21e63ba264082f3071b2887
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 24 05:45:02 2021 -0500

    c++: constexpr, fold, weak redecl, fp/0 [PR103310]

    For PR61825, honza changed tree_single_nonzero_warnv_p to prevent a later
    declaration from marking a function as weak after we've determined that it
    wasn't weak before.  But we shouldn't do that for speculative folding; we
    should only do it when we actually need a constant value.  In C++, such a
    context is called "manifestly constant-evaluated".  In fold, this seems to
    correspond to the folding_initializer flag, since in C this situation only
    occurs in static initializers.

    This change makes nonzero-1.c well-formed; I've added a nonzero-1a.c to
    verify that we delete the null check eventually if there is no weak
    redeclaration.

    The varasm.c change is so that if we do get the weak redeclaration error,
we
    get it at the position of the weak declaration rather than the previous
    declaration.

    Using the FOLD_INIT paths also affects floating point arithmetic: notably,
    this makes floating point division by zero in a manifestly
    constant-evaluated context constant, as in a C static initializer.  I've
had
    some success convincing CWG that this is the right direction; C++ should
    follow C's floating point semantics more than we have been doing, and
Joseph
    says that the C policy is that Annex F overrides other parts of the
standard
    that say that some operations are undefined.  But since we're in stage 3,
    I'm only making this change with the new flag -fconstexpr-fp-except.  It
may
    turn on by default in a future release.

    I think this distinction is only relevant for binary operations; arithmetic
    for the floating point case, comparison for possibly non-zero addresses.

            PR c++/103310

    gcc/ChangeLog:

            * fold-const.c (maybe_nonzero_address): Use get_create or get
            depending on folding_initializer.
            (fold_binary_initializer_loc): New.
            * fold-const.h (fold_binary_initializer_loc): Declare.
            * varasm.c (mark_weak): Don't use the decl location.
            * doc/invoke.texi: Document -fconstexpr-fp-except.

    gcc/c-family/ChangeLog:

            * c.opt: Add -fconstexpr-fp-except.

    gcc/cp/ChangeLog:

            * constexpr.c (cxx_eval_binary_expression): Use
            fold_binary_initializer_loc if manifestly cxeval.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-fp-except1.C: New test.
            * g++.dg/cpp1z/constexpr-if36.C: New test.
            * gcc.dg/tree-ssa/nonzero-1.c: Now well-formed.
            * gcc.dg/tree-ssa/nonzero-1a.c: New test.

      parent reply	other threads:[~2021-12-01 18:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17 22:01 [Bug middle-end/103310] New: " msebor at gcc dot gnu.org
2021-11-18  0:40 ` [Bug c/103310] " msebor at gcc dot gnu.org
2021-11-18 15:58 ` jason at gcc dot gnu.org
2021-12-01 18:24 ` cvs-commit at gcc dot gnu.org [this message]

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-103310-4-OLc16jD5Jt@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).