public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99677] New: [[gnu::const]] attribute does not prevent dead global variable gets emitted.
@ 2021-03-20  3:24 unlvsur at live dot com
  2021-03-20  3:41 ` [Bug c++/99677] " unlvsur at live dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: unlvsur at live dot com @ 2021-03-20  3:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99677
           Summary: [[gnu::const]] attribute does not prevent dead global
                    variable gets emitted.
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: unlvsur at live dot com
  Target Milestone: ---

https://godbolt.org/z/Toncas

The code tries to import functions from DLLs in the global.

Clang does not generate the nt_create_file function pointer, GCC does. Even at
-O0, clang emits no code. It only emits code any function actually uses it.

That is super annoying for Windows since we have no way to invoke Windows NT
syscalls without emitting dead code with GCC.

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

* [Bug c++/99677] [[gnu::const]] attribute does not prevent dead global variable gets emitted.
  2021-03-20  3:24 [Bug c++/99677] New: [[gnu::const]] attribute does not prevent dead global variable gets emitted unlvsur at live dot com
@ 2021-03-20  3:41 ` unlvsur at live dot com
  2021-03-20  3:46 ` unlvsur at live dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: unlvsur at live dot com @ 2021-03-20  3:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from cqwrteur <unlvsur at live dot com> ---
Here is the GCC. it emits code of dead global variables
https://godbolt.org/z/oWddaf

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

* [Bug c++/99677] [[gnu::const]] attribute does not prevent dead global variable gets emitted.
  2021-03-20  3:24 [Bug c++/99677] New: [[gnu::const]] attribute does not prevent dead global variable gets emitted unlvsur at live dot com
  2021-03-20  3:41 ` [Bug c++/99677] " unlvsur at live dot com
@ 2021-03-20  3:46 ` unlvsur at live dot com
  2021-03-20  3:53 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: unlvsur at live dot com @ 2021-03-20  3:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from cqwrteur <unlvsur at live dot com> ---
Even with [[gnu::pure]] clang does not emit code either.
https://godbolt.org/z/e4sG6r

We can see it emits code only when we do not mark the functions are pure.
https://godbolt.org/z/s3cEK3

That is not the case for GCC.

[[gnu::pure]] is a GCC attribute but clang does things better. So sad :(

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

* [Bug c++/99677] [[gnu::const]] attribute does not prevent dead global variable gets emitted.
  2021-03-20  3:24 [Bug c++/99677] New: [[gnu::const]] attribute does not prevent dead global variable gets emitted unlvsur at live dot com
  2021-03-20  3:41 ` [Bug c++/99677] " unlvsur at live dot com
  2021-03-20  3:46 ` unlvsur at live dot com
@ 2021-03-20  3:53 ` pinskia at gcc dot gnu.org
  2021-03-20  6:13 ` unlvsur at live dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-20  3:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this is a dup of bug 99456.

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

* [Bug c++/99677] [[gnu::const]] attribute does not prevent dead global variable gets emitted.
  2021-03-20  3:24 [Bug c++/99677] New: [[gnu::const]] attribute does not prevent dead global variable gets emitted unlvsur at live dot com
                   ` (2 preceding siblings ...)
  2021-03-20  3:53 ` pinskia at gcc dot gnu.org
@ 2021-03-20  6:13 ` unlvsur at live dot com
  2021-03-22  8:57 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: unlvsur at live dot com @ 2021-03-20  6:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from cqwrteur <unlvsur at live dot com> ---
(In reply to Andrew Pinski from comment #3)
> I think this is a dup of bug 99456.

I do not think so because this has nothing to do with constexpr.

better @jakub to see whether he has some solutions.

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

* [Bug c++/99677] [[gnu::const]] attribute does not prevent dead global variable gets emitted.
  2021-03-20  3:24 [Bug c++/99677] New: [[gnu::const]] attribute does not prevent dead global variable gets emitted unlvsur at live dot com
                   ` (3 preceding siblings ...)
  2021-03-20  6:13 ` unlvsur at live dot com
@ 2021-03-22  8:57 ` rguenth at gcc dot gnu.org
  2021-03-22  9:06 ` unlvsur at live dot com
  2021-03-22  9:10 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-03-22  8:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think Andrew is correct.  Note we can't elide "unused" not statically
initialized variables (since the initialization is seen as use).

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

* [Bug c++/99677] [[gnu::const]] attribute does not prevent dead global variable gets emitted.
  2021-03-20  3:24 [Bug c++/99677] New: [[gnu::const]] attribute does not prevent dead global variable gets emitted unlvsur at live dot com
                   ` (4 preceding siblings ...)
  2021-03-22  8:57 ` rguenth at gcc dot gnu.org
@ 2021-03-22  9:06 ` unlvsur at live dot com
  2021-03-22  9:10 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: unlvsur at live dot com @ 2021-03-22  9:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from cqwrteur <unlvsur at live dot com> ---
(In reply to Richard Biener from comment #5)
> I think Andrew is correct.  Note we can't elide "unused" not statically
> initialized variables (since the initialization is seen as use).

but here the result is always the same from importing functions from ntdll.dll
or kernel32.dll

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

* [Bug c++/99677] [[gnu::const]] attribute does not prevent dead global variable gets emitted.
  2021-03-20  3:24 [Bug c++/99677] New: [[gnu::const]] attribute does not prevent dead global variable gets emitted unlvsur at live dot com
                   ` (5 preceding siblings ...)
  2021-03-22  9:06 ` unlvsur at live dot com
@ 2021-03-22  9:10 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-22  9:10 UTC (permalink / raw)
  To: gcc-bugs

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

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 #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
As the functions aren't constexpr, they aren't even considered during C++ FE
constexpr processing.  gnu::const means something completely different.
I bet we optimize away static const variables only written (even with
non-constant initializers) and never address taken or otherwise used, this PR
seems to ask to handle inline const (with the C++ FE specific behavior for
them) in such cases too.
I'm not sure it is valid if the vars are odr-used somewhere and the odr-uses
are later optimized away, I think emitting the inline vars in that case is part
of the ABI.  And the not odr-used cases which are only used by their
initialization is yet another question.

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

end of thread, other threads:[~2021-03-22  9:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-20  3:24 [Bug c++/99677] New: [[gnu::const]] attribute does not prevent dead global variable gets emitted unlvsur at live dot com
2021-03-20  3:41 ` [Bug c++/99677] " unlvsur at live dot com
2021-03-20  3:46 ` unlvsur at live dot com
2021-03-20  3:53 ` pinskia at gcc dot gnu.org
2021-03-20  6:13 ` unlvsur at live dot com
2021-03-22  8:57 ` rguenth at gcc dot gnu.org
2021-03-22  9:06 ` unlvsur at live dot com
2021-03-22  9:10 ` jakub 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).