public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/98364] [modules] unnneded global constructors are emitted for a module
Date: Sat, 01 Jan 2022 05:48:24 +0000	[thread overview]
Message-ID: <bug-98364-4-U9qYBWMFrx@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98364-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
            Summary|[modules] global            |[modules] unnneded global
                   |constructor emission        |constructors are emitted
                   |                            |for a module
           Severity|normal                      |enhancement

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed:
;; Function (static initializers for hello.cc) (_ZGIW5helloEv)
;; enabled by -tree-original


{
  static bool __in_chrg;

    static bool __in_chrg;
  if (__in_chrg)
    {
      return;
    }
  <<cleanup_point <<< Unknown tree: expr_stmt
  (void) (__in_chrg = 1) >>>>>;
}


In main-hello.cc.005t.original.

The code comes from start_objects in cp/decl2.c:


  if (module_init > 0)
    {
      // 'static bool __in_chrg = false;
      // if (__inchrg) return;
      // __inchrg = true
      tree var = build_lang_decl (VAR_DECL, in_charge_identifier,
                                  boolean_type_node);
      DECL_CONTEXT (var) = fndecl;
      DECL_ARTIFICIAL (var) = true;
      TREE_STATIC (var) = true;
      pushdecl (var);
      cp_finish_decl (var, NULL_TREE, false, NULL_TREE, 0);

      tree if_stmt = begin_if_stmt ();
      finish_if_stmt_cond (var, if_stmt);
      finish_return_stmt (NULL_TREE);
      finish_then_clause (if_stmt);
      finish_if_stmt (if_stmt);

      tree assign = build2 (MODIFY_EXPR, boolean_type_node,
                            var, boolean_true_node);
      TREE_SIDE_EFFECTS (assign) = true;
      finish_expr_stmt (assign);
    }
  if (module_init)
    module_add_import_initializers ();

Maybe if there are no initializers, maybe we should not create the global init.

  parent reply	other threads:[~2022-01-01  5:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
2020-12-18 13:40 ` [Bug c++/98364] C++20 module global constructor emission nathan at gcc dot gnu.org
2020-12-21 18:41 ` nathan at gcc dot gnu.org
2020-12-21 18:44 ` unlvsur at live dot com
2020-12-21 18:44 ` unlvsur at live dot com
2020-12-21 18:45 ` unlvsur at live dot com
2020-12-21 18:51 ` unlvsur at live dot com
2020-12-21 18:53 ` unlvsur at live dot com
2022-01-01  5:48 ` pinskia at gcc dot gnu.org [this message]
2024-03-07 20:09 ` [Bug c++/98364] [modules] unnneded global constructors are emitted for a module ppalka 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-98364-4-U9qYBWMFrx@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).