public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109268] New: Guard variable still provided for static constinit variable
@ 2023-03-24  0:48 barry.revzin at gmail dot com
  2023-03-24  0:50 ` [Bug c++/109268] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: barry.revzin at gmail dot com @ 2023-03-24  0:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109268
           Summary: Guard variable still provided for static constinit
                    variable
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

This program: 

struct X {
    constexpr X() { }
    constexpr ~X() { }
};

int main()
{
    static constinit X data;
}

compiled on gcc trunk with -std=c++2b -O3 emits:

X::~X() [base object destructor]:
        ret
main:
        movzx   eax, BYTE PTR guard variable for main::data[rip]
        test    al, al
        je      .L14
        xor     eax, eax
        ret
.L14:
        push    rcx
        mov     edi, OFFSET FLAT:guard variable for main::data
        call    __cxa_guard_acquire
        test    eax, eax
        jne     .L15
.L5:
        xor     eax, eax
        pop     rdx
        ret
.L15:
        mov     edx, OFFSET FLAT:__dso_handle
        mov     esi, OFFSET FLAT:_ZZ4mainE4data
        mov     edi, OFFSET FLAT:_ZN1XD1Ev
        call    __cxa_atexit
        mov     edi, OFFSET FLAT:guard variable for main::data
        call    __cxa_guard_release
        jmp     .L5

But data is constant-initialized (enforced by constinit), so there shouldn't be
a need for a guard variable in this context? clang does not generate one in
this case.

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

* [Bug c++/109268] Guard variable still provided for static constinit variable
  2023-03-24  0:48 [Bug c++/109268] New: Guard variable still provided for static constinit variable barry.revzin at gmail dot com
@ 2023-03-24  0:50 ` pinskia at gcc dot gnu.org
  2023-03-24  0:54 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-24  0:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |missed-optimization

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

* [Bug c++/109268] Guard variable still provided for static constinit variable
  2023-03-24  0:48 [Bug c++/109268] New: Guard variable still provided for static constinit variable barry.revzin at gmail dot com
  2023-03-24  0:50 ` [Bug c++/109268] " pinskia at gcc dot gnu.org
@ 2023-03-24  0:54 ` pinskia at gcc dot gnu.org
  2023-03-24 11:54 ` [Bug c++/109268] Guard variable still provided for static constinit variable with an empty destructor jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-24  0:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=19661

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is the deconstructor which is causing the need for the guard variable.
Very much related to PR 19661 .

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

* [Bug c++/109268] Guard variable still provided for static constinit variable with an empty destructor
  2023-03-24  0:48 [Bug c++/109268] New: Guard variable still provided for static constinit variable barry.revzin at gmail dot com
  2023-03-24  0:50 ` [Bug c++/109268] " pinskia at gcc dot gnu.org
  2023-03-24  0:54 ` pinskia at gcc dot gnu.org
@ 2023-03-24 11:54 ` jakub at gcc dot gnu.org
  2024-03-16 22:37 ` pinskia at gcc dot gnu.org
  2024-03-16 23:18 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-24 11:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Agreed, the constinit is irrelevant.
As for constexpr dtors generally, even those can have important side-effects,
and even for the case where the ctor is also constexpr and the var has constant
expression initializer, so to me this looks like dup of PR19661.
We'd need to track in some extra bit if the dtor does something non-trivial and
propagate it from dtors of the elements/bases.
struct X {
  constexpr X () : p (nullptr) {}
  constexpr ~X () { delete p; }
  int *p;
};
int
main ()
{
  static constinit X data;
  data.p = new int;
}

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

* [Bug c++/109268] Guard variable still provided for static constinit variable with an empty destructor
  2023-03-24  0:48 [Bug c++/109268] New: Guard variable still provided for static constinit variable barry.revzin at gmail dot com
                   ` (2 preceding siblings ...)
  2023-03-24 11:54 ` [Bug c++/109268] Guard variable still provided for static constinit variable with an empty destructor jakub at gcc dot gnu.org
@ 2024-03-16 22:37 ` pinskia at gcc dot gnu.org
  2024-03-16 23:18 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-16 22:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-03-16
             Status|UNCONFIRMED                 |NEW

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I have a patch which fixes PR 19661 except it does not fix this one fully.

I will also note LLVM also still does the guard variable here too even with the
removal of the __cxa_atexit call.

We need another way to remove the empty code between
__cxa_guard_acquire/__cxa_guard_release .

  <bb 3> [local count: 354334800]:
  _2 = __cxa_guard_acquire (&_ZGVZ1fvE4data);
  if (_2 != 0)
    goto <bb 4>; [33.00%]
  else
    goto <bb 5>; [67.00%]

  <bb 4> [local count: 116930483]:
  # DEBUG this => &data
  # DEBUG INLINE_ENTRY __ct 
  data ={v} {CLOBBER(bob)};
  # DEBUG this => NULL
  __cxa_guard_release (&_ZGVZ1fvE4data);

  <bb 5> [local count: 1073741824]:

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

* [Bug c++/109268] Guard variable still provided for static constinit variable with an empty destructor
  2023-03-24  0:48 [Bug c++/109268] New: Guard variable still provided for static constinit variable barry.revzin at gmail dot com
                   ` (3 preceding siblings ...)
  2024-03-16 22:37 ` pinskia at gcc dot gnu.org
@ 2024-03-16 23:18 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-16 23:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-03-16
             Status|UNCONFIRMED                 |NEW
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I have a patch which fixes PR 19661 except it does not fix this one fully.

I will also note LLVM also still does the guard variable here too even with the
removal of the __cxa_atexit call.

We need another way to remove the empty code between
__cxa_guard_acquire/__cxa_guard_release .

  <bb 3> [local count: 354334800]:
  _2 = __cxa_guard_acquire (&_ZGVZ1fvE4data);
  if (_2 != 0)
    goto <bb 4>; [33.00%]
  else
    goto <bb 5>; [67.00%]

  <bb 4> [local count: 116930483]:
  # DEBUG this => &data
  # DEBUG INLINE_ENTRY __ct 
  data ={v} {CLOBBER(bob)};
  # DEBUG this => NULL
  __cxa_guard_release (&_ZGVZ1fvE4data);

  <bb 5> [local count: 1073741824]:

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup in the end.

*** This bug has been marked as a duplicate of bug 84411 ***

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

end of thread, other threads:[~2024-03-16 23:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24  0:48 [Bug c++/109268] New: Guard variable still provided for static constinit variable barry.revzin at gmail dot com
2023-03-24  0:50 ` [Bug c++/109268] " pinskia at gcc dot gnu.org
2023-03-24  0:54 ` pinskia at gcc dot gnu.org
2023-03-24 11:54 ` [Bug c++/109268] Guard variable still provided for static constinit variable with an empty destructor jakub at gcc dot gnu.org
2024-03-16 22:37 ` pinskia at gcc dot gnu.org
2024-03-16 23:18 ` 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).