]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa/92606 - properly handle no_icf attribute for variables
authorRichard Biener <rguenther@suse.de>
Mon, 11 Dec 2023 09:08:24 +0000 (10:08 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 12 Dec 2023 14:25:24 +0000 (15:25 +0100)
The following adds no_icf handling for variables where the attribute
was rejected.  It also fixes the check for no_icf by checking both
the source and the targets decl.

PR ipa/92606
gcc/c-family/
* c-attribs.cc (handle_noicf_attribute): Also allow the
attribute on global variables.

gcc/
* ipa-icf.cc (sem_item_optimizer::merge_classes): Check
both source and alias for the no_icf attribute.
* doc/extend.texi (no_icf): Document variable attribute.

gcc/c-family/c-attribs.cc
gcc/doc/extend.texi
gcc/ipa-icf.cc

index 854e987dc79b6f0853f4898b0642e44a0f932cfa..a3671fe3a572b71777aa5284f127e082a83dd4d9 100644 (file)
@@ -1649,7 +1649,8 @@ handle_noicf_attribute (tree *node, tree name,
                        tree ARG_UNUSED (args),
                        int ARG_UNUSED (flags), bool *no_add_attrs)
 {
-  if (TREE_CODE (*node) != FUNCTION_DECL)
+  if (TREE_CODE (*node) != FUNCTION_DECL
+      && (TREE_CODE (*node) != VAR_DECL || !is_global_var (*node)))
     {
       warning (OPT_Wattributes, "%qE attribute ignored", name);
       *no_add_attrs = true;
index e8b5e771f7a08fa31f242720a351926b25b86804..f0c789f6cb4acca63290f2abe3d4d2c4e6f7afff 100644 (file)
@@ -8152,6 +8152,11 @@ script to place the sections with the @code{.persistent} prefix in the
 right location.  Specifically, some type of non-volatile, writeable
 memory is required.
 
+@cindex @code{no_icf} variable attribute
+@item no_icf
+This variable attribute prevents a variable from being merged with another
+equivalent variable.
+
 @cindex @code{objc_nullability} variable attribute
 @item objc_nullability (@var{nullability kind}) @r{(Objective-C and Objective-C++ only)}
 This attribute applies to pointer variables only.  It allows marking the
index 81232d5706e1e8eaf4671e0e9e501528ce1bb193..e27536d73a960c9740653a2553a170792c757309 100644 (file)
@@ -3422,7 +3422,8 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count,
                                 alias->node->dump_asm_name ());
              }
 
-           if (lookup_attribute ("no_icf", DECL_ATTRIBUTES (alias->decl)))
+           if (lookup_attribute ("no_icf", DECL_ATTRIBUTES (alias->decl))
+               || lookup_attribute ("no_icf", DECL_ATTRIBUTES (source->decl)))
              {
                if (dump_enabled_p ())
                  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,