On 12/5/19 8:13 AM, Martin Liška wrote:
On 12/5/19 2:03 PM, Jan Hubicka wrote:
Hi.

As mentioned in the PR, there are classes in cgraph.h that are
not PODs and are initialized with ggc_alloc_cleared. So that I'm suggesting
to use proper constructors. I added ggc_new function that can be used
at different locations as well.

I'm attaching optimized dump file with how ctor expansion looks like.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?

index 9c086fedaef..b7dea696782 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -109,6 +109,23 @@ struct GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
 public:
   friend class symbol_table;

+  /* Default constructor.  */
+  symtab_node (symtab_type t)

Since it takes an argument the above is not the default ctor.
It can be made one by providing a default argument for t, such
as NULL_TREE if that's valid.

I don't know the details of how these things are defined now
(POD vs non-POD) or how they're used (where POD is expected)
but having been bitten a bunch of times recently by various
GCC container templates making assumptions about their
elements being PODs, it seems worth pointing it out here.
If without this change symtab_node is a POD, adding one
could cause problems.  Same for the other structs.

+ : type (t), resolution (LDPR_UNKNOWN), definition (false), alias (false), + transparent_alias (false), weakref (false), cpp_implicit_alias (false),
+      symver (false), analyzed (false), writeonly (false),
+      refuse_visibility_changes (false), externally_visible (false),
+      no_reorder (false), force_output (false), forced_by_abi (false),
+      unique_name (false), implicit_section (false), body_removed (false),
+      used_from_other_partition (false), in_other_partition (false),
+      address_taken (false), in_init_priority_hash (false),
+ need_lto_streaming (false), offloadable (false), ifunc_resolver (false),
+      order (false), next_sharing_asm_name (NULL),
+ previous_sharing_asm_name (NULL), same_comdat_group (NULL), ref_list (),
+      alias_target (NULL), lto_file_data (NULL), aux (NULL),
+      x_comdat_group (NULL_TREE), x_section (NULL)
+  {}

This is a matter of personal preference but for whatever it's
worth, I like using default zero initialization for zero-
initialized members, e.g.,

  definition (), alias (), ... alias_target (), ...

Besides being less verbose it has the advantage that changing
the type of the member doesn't need to require changing its
initializer.  (An argument for the more verbose form might
be that it makes the initial value immediately clear.)

Martin

Reply via email to