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++/99859] constexpr evaluation with member function is incorrect
Date: Thu, 08 Apr 2021 15:19:26 +0000	[thread overview]
Message-ID: <bug-99859-4-Syqv9Q7aNd@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-99859-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #16 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:559d2f1e0eafd96c19dc5324db1a466286c0e7fc

commit r11-8056-g559d2f1e0eafd96c19dc5324db1a466286c0e7fc
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Apr 8 17:15:39 2021 +0200

    c++: Don't cache constexpr functions which are passed pointers to heap or
static vars being constructed [PR99859]

    When cxx_bind_parameters_in_call is called e.g. on a method on an automatic
    variable, we evaluate the argument and because ADDR_EXPR of an automatic
    decl is not TREE_CONSTANT, we set *non_constant_args and don't cache it.
    But when it is called on an object located on the heap (allocated using
    C++20 constexpr new) where we represent it as TREE_STATIC artificial
    var, or when it is called on a static var that is currently being
    constructed, such ADDR_EXPRs are TREE_CONSTANT and we happily cache
    such calls, but they can in those cases have side-effects in the heap
    or static var objects and so caching them means such side-effects will
    happen only once and not as many times as that method or function is
called.
    Furthermore, as Patrick mentioned in the PR, the argument doesn't need to
be
    just ADDR_EXPR of the heap or static var or its components, but it could be
    a CONSTRUCTOR that has the ADDR_EXPR embedded anywhere.
    And the incorrectly cached function doesn't need to modify the pointed vars
    or their components, but some caller could be changing them in between the
    call that was cached and the call that used the cached result.

    The following patch fixes it by setting *non_constant_args also when
    the argument contains somewhere such an ADDR_EXPR, either of a heap
    artificial var or component thereof, or of a static var currently being
    constructed (where for that it uses the same check as
    cxx_eval_store_expression, ctx->global->values.get (...); addresses of
    other static variables would be rejected by cxx_eval_store_expression
    and therefore it is ok to cache such calls).

    2021-04-08  Jakub Jelinek  <jakub@redhat.com>

            PR c++/99859
            * constexpr.c (addr_of_non_const_var): New function.
            (cxx_bind_parameters_in_call): Set *non_constant_args to true
            even if cp_walk_tree on arg with addr_of_non_const_var callback
            returns true.

            * g++.dg/cpp1y/constexpr-99859-1.C: New test.
            * g++.dg/cpp1y/constexpr-99859-2.C: New test.
            * g++.dg/cpp2a/constexpr-new18.C: New test.
            * g++.dg/cpp2a/constexpr-new19.C: New test.

  parent reply	other threads:[~2021-04-08 15:19 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31 22:54 [Bug c++/99859] New: " ldalessandro at gmail dot com
2021-03-31 23:15 ` [Bug c++/99859] " ldalessandro at gmail dot com
2021-04-01 10:29 ` jakub at gcc dot gnu.org
2021-04-01 14:15 ` jakub at gcc dot gnu.org
2021-04-07 11:39 ` jakub at gcc dot gnu.org
2021-04-07 12:05 ` ppalka at gcc dot gnu.org
2021-04-07 12:14 ` jakub at gcc dot gnu.org
2021-04-07 12:15 ` ppalka at gcc dot gnu.org
2021-04-07 12:24 ` jakub at gcc dot gnu.org
2021-04-07 12:45 ` ppalka at gcc dot gnu.org
2021-04-07 13:38 ` jakub at gcc dot gnu.org
2021-04-07 13:44 ` jakub at gcc dot gnu.org
2021-04-07 13:48 ` jakub at gcc dot gnu.org
2021-04-07 14:04 ` jakub at gcc dot gnu.org
2021-04-07 16:32 ` ppalka at gcc dot gnu.org
2021-04-07 17:33 ` jakub at gcc dot gnu.org
2021-04-08 15:19 ` cvs-commit at gcc dot gnu.org [this message]
2021-04-08 15:21 ` jakub at gcc dot gnu.org
2021-04-08 15:22 ` jakub at gcc dot gnu.org
2021-04-19  1:53 ` ppalka at gcc dot gnu.org
2021-04-20  9:45 ` cvs-commit at gcc dot gnu.org
2021-07-28 22:16 ` pinskia at gcc dot gnu.org
2021-08-28 21:17 ` pinskia at gcc dot gnu.org
2021-08-28 21:21 ` pinskia at gcc dot gnu.org
2022-02-02 17:29 ` redi 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-99859-4-Syqv9Q7aNd@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).