public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53829] New: Trivial static initializers are created for initialization with result of trivial static inline functions
@ 2012-07-02  6:26 mh+gcc at glandium dot org
  2012-07-02  7:10 ` [Bug c++/53829] " jakub at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: mh+gcc at glandium dot org @ 2012-07-02  6:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53829

             Bug #: 53829
           Summary: Trivial static initializers are created for
                    initialization with result of trivial static inline
                    functions
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mh+gcc@glandium.org


The most trivial example of the behaviour is this:

#include <stdint.h>
static inline uint64_t foo() { return 42; }
uint64_t f = foo();

G++ generates the following:
    .file    "test.cc"
    .section    .text.startup,"ax",@progbits
    .p2align 4,,15
    .type    _GLOBAL__sub_I_f, @function
_GLOBAL__sub_I_f:
.LFB2:
    .cfi_startproc
    movq    $42, f(%rip)
    ret
    .cfi_endproc
.LFE2:
    .size    _GLOBAL__sub_I_f, .-_GLOBAL__sub_I_f
    .section    .init_array,"aw"
    .align 8
    .quad    _GLOBAL__sub_I_f
    .globl    f
    .bss
    .align 8
    .type    f, @object
    .size    f, 8
f:
    .zero    8
    .ident    "GCC: (Debian 4.7.1-2) 4.7.1"
    .section    .note.GNU-stack,"",@progbits

For reference, clang++ generates the following:

    .file    "test.cc"
    .type    f,@object               # @f
    .data
    .globl    f
    .align    8
f:
    .quad    42                      # 0x2a
    .size    f, 8


    .section    ".note.GNU-stack","",@progbits

There are cases where g++ is able to generate code like clang++, but I can't
find one just now.


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

* [Bug c++/53829] Trivial static initializers are created for initialization with result of trivial static inline functions
  2012-07-02  6:26 [Bug c++/53829] New: Trivial static initializers are created for initialization with result of trivial static inline functions mh+gcc at glandium dot org
@ 2012-07-02  7:10 ` jakub at gcc dot gnu.org
  2012-07-02  7:12 ` pinskia at gcc dot gnu.org
  2012-07-02 10:15 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-07-02  7:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53829

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-07-02
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-07-02 07:09:58 UTC ---
With -std=c++11 and constexpr on the static inline it is already compiled into
the expected form.  For -O0 it shouldn't be optimized into that without
constexpr, but as an optimization it would be nice if non-constexpr marked
trivial functions could be as an optimization handled like constexpr ones in
some cases (in particular when deciding if an initializer can be output as
simple constant).  Jason?


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

* [Bug c++/53829] Trivial static initializers are created for initialization with result of trivial static inline functions
  2012-07-02  6:26 [Bug c++/53829] New: Trivial static initializers are created for initialization with result of trivial static inline functions mh+gcc at glandium dot org
  2012-07-02  7:10 ` [Bug c++/53829] " jakub at gcc dot gnu.org
@ 2012-07-02  7:12 ` pinskia at gcc dot gnu.org
  2012-07-02 10:15 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-07-02  7:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53829

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-07-02 07:12:27 UTC ---
This is basically the same as PR 4131.

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


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

* [Bug c++/53829] Trivial static initializers are created for initialization with result of trivial static inline functions
  2012-07-02  6:26 [Bug c++/53829] New: Trivial static initializers are created for initialization with result of trivial static inline functions mh+gcc at glandium dot org
  2012-07-02  7:10 ` [Bug c++/53829] " jakub at gcc dot gnu.org
  2012-07-02  7:12 ` pinskia at gcc dot gnu.org
@ 2012-07-02 10:15 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-07-02 10:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53829

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-07-02 10:15:35 UTC ---
I guess we'd need to do some discovery of potential constexpr functions (that
aren't marked that way though), use some bit other than
DECL_DECLARED_CONSTEXPR_P for those, pass some flag from maybe_constant_value
down to potential_constant_expression and cxx_eval_outermost_constant_expr
(in addition to allow_non_constant or perhaps as enum instead of bool of
allow_non_constant) and with optimize treat also !DECL_DECLARED_CONSTEXPR_P &&
DECL_CONSTEXPR_LIKE_P calls.  Or is maybe_constant_value ever used to decide if
a C++ program is valid or not?


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

end of thread, other threads:[~2012-07-02 10:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-02  6:26 [Bug c++/53829] New: Trivial static initializers are created for initialization with result of trivial static inline functions mh+gcc at glandium dot org
2012-07-02  7:10 ` [Bug c++/53829] " jakub at gcc dot gnu.org
2012-07-02  7:12 ` pinskia at gcc dot gnu.org
2012-07-02 10:15 ` 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).