public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99507] New: Can't return static address from immediate function
@ 2021-03-10  6:33 johelegp at gmail dot com
  2021-03-10 13:32 ` [Bug c++/99507] " jakub at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: johelegp at gmail dot com @ 2021-03-10  6:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99507
           Summary: Can't return static address from immediate function
           Product: gcc
           Version: 11.0
               URL: https://godbolt.org/z/vnPToT
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
                CC: johelegp at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/vnPToT.
```C++
constexpr int i{0};
consteval const int& iref() { return i; }
[[maybe_unused]] constexpr const int* a{&iref()};
```

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/99507] Can't return static address from immediate function
  2021-03-10  6:33 [Bug c++/99507] New: Can't return static address from immediate function johelegp at gmail dot com
@ 2021-03-10 13:32 ` jakub at gcc dot gnu.org
  2021-03-12  9:12 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-10 13:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-03-10
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 50351
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50351&action=edit
gcc11-pr99507.patch

Untested fix.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/99507] Can't return static address from immediate function
  2021-03-10  6:33 [Bug c++/99507] New: Can't return static address from immediate function johelegp at gmail dot com
  2021-03-10 13:32 ` [Bug c++/99507] " jakub at gcc dot gnu.org
@ 2021-03-12  9:12 ` cvs-commit at gcc dot gnu.org
  2021-03-12  9:13 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-12  9:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 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:425afe1f0c907e6469cef1672160c9c95177e71a

commit r11-7645-g425afe1f0c907e6469cef1672160c9c95177e71a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Mar 12 10:11:24 2021 +0100

    c++: Fix up calls to immediate functions returning reference [PR99507]

    build_cxx_call calls convert_from_reference at the end, so if an immediate
    function returns a reference, we were constant evaluating not just that
    call, but that call wrapped in an INDIRECT_REF.  That unfortunately means
    it can constant evaluate to something non-addressable, so if code later
    needs to take its address it will fail.

    The following patch fixes that by undoing the convert_from_reference
    wrapping for the cxx_constant_value evaluation and readdding it ad the end.

    2021-03-12  Jakub Jelinek  <jakub@redhat.com>

            PR c++/99507
            * call.c (build_over_call): For immediate evaluation of functions
            that return references, undo convert_from_reference effects before
            calling cxx_constant_value and call convert_from_reference
            afterwards.

            * g++.dg/cpp2a/consteval19.C: New test.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/99507] Can't return static address from immediate function
  2021-03-10  6:33 [Bug c++/99507] New: Can't return static address from immediate function johelegp at gmail dot com
  2021-03-10 13:32 ` [Bug c++/99507] " jakub at gcc dot gnu.org
  2021-03-12  9:12 ` cvs-commit at gcc dot gnu.org
@ 2021-03-12  9:13 ` jakub at gcc dot gnu.org
  2021-03-19 23:30 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-12  9:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk so far.  Should be backported to 10 later.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/99507] Can't return static address from immediate function
  2021-03-10  6:33 [Bug c++/99507] New: Can't return static address from immediate function johelegp at gmail dot com
                   ` (2 preceding siblings ...)
  2021-03-12  9:13 ` jakub at gcc dot gnu.org
@ 2021-03-19 23:30 ` cvs-commit at gcc dot gnu.org
  2021-08-28 22:39 ` johelegp at gmail dot com
  2021-08-28 22:43 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-19 23:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:3ef0d71f64408b527169a740ea7dc5f4d169b0b6

commit r10-9484-g3ef0d71f64408b527169a740ea7dc5f4d169b0b6
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Mar 12 10:11:24 2021 +0100

    c++: Fix up calls to immediate functions returning reference [PR99507]

    build_cxx_call calls convert_from_reference at the end, so if an immediate
    function returns a reference, we were constant evaluating not just that
    call, but that call wrapped in an INDIRECT_REF.  That unfortunately means
    it can constant evaluate to something non-addressable, so if code later
    needs to take its address it will fail.

    The following patch fixes that by undoing the convert_from_reference
    wrapping for the cxx_constant_value evaluation and readdding it ad the end.

    2021-03-12  Jakub Jelinek  <jakub@redhat.com>

            PR c++/99507
            * call.c (build_over_call): For immediate evaluation of functions
            that return references, undo convert_from_reference effects before
            calling cxx_constant_value and call convert_from_reference
            afterwards.

            * g++.dg/cpp2a/consteval19.C: New test.

    (cherry picked from commit 425afe1f0c907e6469cef1672160c9c95177e71a)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/99507] Can't return static address from immediate function
  2021-03-10  6:33 [Bug c++/99507] New: Can't return static address from immediate function johelegp at gmail dot com
                   ` (3 preceding siblings ...)
  2021-03-19 23:30 ` cvs-commit at gcc dot gnu.org
@ 2021-08-28 22:39 ` johelegp at gmail dot com
  2021-08-28 22:43 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: johelegp at gmail dot com @ 2021-08-28 22:39 UTC (permalink / raw)
  To: gcc-bugs

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

Johel Ernesto Guerrero Peña <johelegp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to work|                            |10.3.0, 11.1.0
         Resolution|---                         |FIXED
      Known to fail|                            |10.2.0

--- Comment #5 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
Thank you.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/99507] Can't return static address from immediate function
  2021-03-10  6:33 [Bug c++/99507] New: Can't return static address from immediate function johelegp at gmail dot com
                   ` (4 preceding siblings ...)
  2021-08-28 22:39 ` johelegp at gmail dot com
@ 2021-08-28 22:43 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-28 22:43 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-28 22:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10  6:33 [Bug c++/99507] New: Can't return static address from immediate function johelegp at gmail dot com
2021-03-10 13:32 ` [Bug c++/99507] " jakub at gcc dot gnu.org
2021-03-12  9:12 ` cvs-commit at gcc dot gnu.org
2021-03-12  9:13 ` jakub at gcc dot gnu.org
2021-03-19 23:30 ` cvs-commit at gcc dot gnu.org
2021-08-28 22:39 ` johelegp at gmail dot com
2021-08-28 22:43 ` pinskia at gcc dot gnu.org

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).