public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/aoliva/heads/testme)] incremental sym_alias changes
Date: Fri,  1 Dec 2023 21:37:29 +0000 (GMT)	[thread overview]
Message-ID: <20231201213729.7B9CD385C6C4@sourceware.org> (raw)

https://gcc.gnu.org/g:27f2777fd67327638a100ee1310087841922194f

commit 27f2777fd67327638a100ee1310087841922194f
Author: Alexandre Oliva <oliva@gnu.org>
Date:   Fri Dec 1 15:48:44 2023 -0300

    incremental sym_alias changes

Diff:
---
 gcc/attribs.cc                                      |  6 ++++++
 gcc/c/c-decl.cc                                     |  5 +++++
 gcc/doc/extend.texi                                 |  2 +-
 gcc/symtab.cc                                       | 17 +++++++++++++++++
 .../c-c++-common/torture/attr-sym-alias-1.c         | 19 +++++++++++++++++++
 .../c-c++-common/torture/attr-sym-alias-2.c         | 21 +++++++++++++++------
 .../c-c++-common/torture/attr-sym-alias-3.c         |  7 -------
 gcc/testsuite/g++.dg/torture/attr-sym-alias-1.C     | 15 +++++++++++++++
 8 files changed, 78 insertions(+), 14 deletions(-)

diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index c75ca6974cb..6f3069d3adc 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -2667,6 +2667,11 @@ create_sym_alias_decl (tree decl, tree id)
   tree clone = copy_node (decl);
   DECL_ATTRIBUTES (clone) = remove_attribute (attr_str,
 					      DECL_ATTRIBUTES (decl));
+  /* Mark it as a "sym alias" for decl, an internal attribute that
+     enables symbol_table::insert_to_assembler_name_hash can recognize
+     sym_alias decls.  */
+  DECL_ATTRIBUTES (clone) = tree_cons (get_identifier ("sym alias"),
+				       decl, DECL_ATTRIBUTES (clone));
   SET_DECL_ASSEMBLER_NAME (clone, id);
   TREE_USED (id) = 1;
   TREE_USED (clone) = 1;
@@ -2681,6 +2686,7 @@ create_sym_alias_decl (tree decl, tree id)
   else
     cgraph_node::create_same_body_alias (clone, decl);
     // cgraph_node::create_alias (clone, decl);
+  clone->copy_visibility_from (decl);
 
   return clone;
 }
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index c5a7e56f4ec..098c525454a 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -5902,6 +5902,11 @@ finish_decl (tree decl, location_t init_loc, tree init,
 	    set_user_assembler_name (decl, asmspec);
 	}
 
+      /* Give attribute sym_alias a chance to make the symbol name
+	 available for aliasing, even for a static local variable.  */
+      if (VAR_P (decl) && is_global_var (decl))
+	varpool_node::get_create (decl);
+
       if (DECL_FILE_SCOPE_P (decl))
 	{
 	  if (DECL_INITIAL (decl) == NULL_TREE
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index f16571147d4..eff776a4bc8 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -4173,7 +4173,7 @@ declarations.
 Aliases introduced with this attribute, such as @samp{f_u64} in the
 example above, are assembly symbol names: they do not undergo C++ name
 mangling, and are not made visible in any scope in the source language.
-They can, however, can be named as alias targets.
+They can, however, be named as alias targets.
 
 This attribute requires assembler and object file support for aliases,
 and may not be available on all targets.
diff --git a/gcc/symtab.cc b/gcc/symtab.cc
index 43ba88d7939..08bb2eac6aa 100644
--- a/gcc/symtab.cc
+++ b/gcc/symtab.cc
@@ -187,6 +187,22 @@ symbol_table::insert_to_assembler_name_hash (symtab_node *node,
 	(*aslot)->previous_sharing_asm_name = node;
       *aslot = node;
 
+      /* Check for sym_alias name clashes.  In create_sym_alias_decl,
+	 we check for a preexisting definition using the same
+	 assembler_name, so here we check for a previously-defined
+	 sym_name, marked with a "sym name" pseudo-attribute that
+	 points back at the declaration for which it was created.  */
+      if (symtab_node *sym_node = node->next_sharing_asm_name)
+	if (lookup_attribute ("sym alias",
+			      DECL_ATTRIBUTES (sym_node->decl)))
+	  {
+	    error_at (DECL_SOURCE_LOCATION (node->decl),
+		      "duplicate symbol name %qE", decl);
+	    inform (DECL_SOURCE_LOCATION (sym_node->decl),
+		    "already used by %qD in a %qE attribute",
+		    sym_node->decl, get_identifier ("sym_alias"));
+	  }
+
       /* Update also possible inline clones sharing a decl.  */
       cnode = dyn_cast <cgraph_node *> (node);
       if (cnode && cnode->clones && with_clones)
@@ -1978,6 +1994,7 @@ symtab_node::remap_sym_alias_target (tree replaced, tree replacement)
       else
 	cgraph_node::create_same_body_alias (sym_node->decl, replacement);
 	// cgraph_node::create_alias (sym_node->decl, replacement);
+      sym_node->copy_visibility_from (replacement);
     }
 }
 
diff --git a/gcc/testsuite/c-c++-common/torture/attr-sym-alias-1.c b/gcc/testsuite/c-c++-common/torture/attr-sym-alias-1.c
index 61af50cb552..b0167786914 100644
--- a/gcc/testsuite/c-c++-common/torture/attr-sym-alias-1.c
+++ b/gcc/testsuite/c-c++-common/torture/attr-sym-alias-1.c
@@ -31,9 +31,28 @@ foo_c ()
 }
 
 
+void baf () {}
+
+void foo_x () {
+  extern void baf () __attribute__ ((__sym_alias__ ("FOO_BAF")));
+  extern void bad () /* ok, but not defined, so no alias issued.  */
+    __attribute__ ((__sym_alias__ ("FOO_BAD")));
+  extern void bar () __attribute__ ((__sym_alias__ ("FOO_BAR")));
+
+  static int x __attribute__ ((sym_alias ("FOO_x")));
+}
+
+void bar () {}
+
+extern int xr __attribute__ ((alias ("FOO_x")));
+
+
 /* { dg-final { scan-assembler "FOOBAR_A" } } */
 /* { dg-final { scan-assembler "FOOVAR_A" } } */
 /* { dg-final { scan-assembler "FOOBAR_B" } } */
 /* { dg-final { scan-assembler "FOOVAR_B" } } */
 /* { dg-final { scan-assembler "FOOBAR_C" } } */
 /* { dg-final { scan-assembler "FOOVAR_C" } } */
+/* { dg-final { scan-assembler "FOO_BAF" } } */
+/* { dg-final { scan-assembler "FOO_BAR" } } */
+/* { dg-final { scan-assembler-not "FOO_BAD" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/attr-sym-alias-2.c b/gcc/testsuite/c-c++-common/torture/attr-sym-alias-2.c
index 67dcd4fd7e1..f692a552606 100644
--- a/gcc/testsuite/c-c++-common/torture/attr-sym-alias-2.c
+++ b/gcc/testsuite/c-c++-common/torture/attr-sym-alias-2.c
@@ -7,16 +7,14 @@ struct s
 };
 
 void foo () {
-  extern void bar () __attribute__ ((__sym_alias__ ("FOO_BAR"))); /* ok */
+  extern void bar () __attribute__ ((__sym_alias__ ("FOO_BAR"))); /* Ok.  */
   int i __attribute__ ((sym_alias ("FOO_i"))); /* { dg-warning "ignored" } */
-  /* ??? X cannot be an alias target; should this be flagged? ... */
   static int x __attribute__ ((sym_alias ("FOO_x")));
   static int sx __attribute__ ((alias ("FOO_x"))); /* { dg-warning "ignored" } */
   extern int xx __attribute__ ((alias ("FOO_x"))); /* { dg-warning "ignored" } */
+  extern int y __attribute__ ((sym_alias ("FOO_y"))); /* Ok.  */
 }
 
-/* ??? ... or should XR be accepted?  */
-extern int xr __attribute__ ((alias ("FOO_x"))); /* { dg-error "undefined" "" { xfail c++ } } */
 int dr __attribute__ ((alias ("FOO_x"))); /* { dg-error "defined both" } */
 
 
@@ -40,7 +38,7 @@ int l __attribute__ ((sym_alias ("L_fn")));
 extern "C"
 #endif
 void
-L_fn () /* { dg-error "duplicate" "" { xfail *-*-* } } */
+L_fn () /* { dg-error "duplicate" "" } */
 {
 }
 
@@ -53,7 +51,7 @@ m ()
 {
 }
 
-int M_var; /* { dg-error "duplicate" "" { xfail *-*-* } } */
+int M_var; /* { dg-error "duplicate" "" } */
 
 
 void __attribute__ ((sym_alias ("N_sym")))
@@ -88,3 +86,14 @@ void __attribute__ ((sym_alias ("Q_sym")))
 q_fn2 () /* { dg-error "duplicate" } */
 {
 }
+
+int __attribute__ ((sym_alias ("R_var")))
+R_var; /* { dg-error "duplicate" } */
+
+#ifdef __cplusplus
+extern "C"
+#endif
+void __attribute__ ((sym_alias ("S_fn")))
+S_fn () /* { dg-error "duplicate" } */
+{
+}
diff --git a/gcc/testsuite/c-c++-common/torture/attr-sym-alias-3.c b/gcc/testsuite/c-c++-common/torture/attr-sym-alias-3.c
index 0052485a30a..52f8fb76496 100644
--- a/gcc/testsuite/c-c++-common/torture/attr-sym-alias-3.c
+++ b/gcc/testsuite/c-c++-common/torture/attr-sym-alias-3.c
@@ -10,13 +10,6 @@ foo_a ()
   void foo_a () __attribute__ ((__sym_alias__ ("FOOBAR_A")));
 }
 
-#if 0 // __cplusplus
-/* Without this declaration before the local declaration below, the
-   attributes of the local declaration do not get propagated to the
-   (global) namespace scope.  */
-extern int var_b;
-#endif
-
 void
 foo_b ()
 {
diff --git a/gcc/testsuite/g++.dg/torture/attr-sym-alias-1.C b/gcc/testsuite/g++.dg/torture/attr-sym-alias-1.C
index 579eda1a473..83d1936d275 100644
--- a/gcc/testsuite/g++.dg/torture/attr-sym-alias-1.C
+++ b/gcc/testsuite/g++.dg/torture/attr-sym-alias-1.C
@@ -45,6 +45,18 @@ namespace c {
   }
 }
 
+#include <typeinfo>
+
+namespace d {
+  namespace {
+    class __attribute__ ((__sym_alias__ ("FOOCLS_D"))) foo {};
+  }
+
+  extern std::type_info __attribute__ ((__alias__ ("FOOCLS_D"))) foo_d_typeinfo;
+}
+
+extern std::type_info __attribute__ ((__alias__ ("FOOCLS_C"))) foo_c_typeinfo;
+
 /* { dg-final { scan-assembler "FOOCLS_A" } } */
 /* { dg-final { scan-assembler "FOOCLS_A_Dupe" } } */
 /* { dg-final { scan-assembler "FOOBAR_A" } } */
@@ -70,3 +82,6 @@ namespace c {
 /* { dg-final { scan-assembler "FOODTR_C_Base" } } */
 /* { dg-final { scan-assembler "FOODTR_C_Del" } } */
 /* { dg-final { scan-assembler "FOOVAR_C" } } */
+/* { dg-final { scan-assembler "FOOCLS_D" } } */
+/* { dg-final { scan-assembler "foo_d_typeinfo" } } */
+/* { dg-final { scan-assembler "foo_c_typeinfo" } } */

             reply	other threads:[~2023-12-01 21:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-01 21:37 Alexandre Oliva [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-12-05 21:51 Alexandre Oliva
2023-12-05 19:30 Alexandre Oliva
2023-12-03  1:46 Alexandre Oliva
2023-12-02 17:48 Alexandre Oliva
2023-12-01 23:48 Alexandre Oliva
2023-12-01 23:42 Alexandre Oliva
2023-12-01 23:40 Alexandre Oliva
2023-12-01 23:13 Alexandre Oliva
2023-12-01 23:11 Alexandre Oliva
2023-12-01 23:07 Alexandre Oliva
2023-12-01 22:24 Alexandre Oliva
2023-12-01 22:19 Alexandre Oliva
2023-12-01 21:51 Alexandre Oliva
2023-12-01 21:45 Alexandre Oliva
2023-12-01 21:41 Alexandre Oliva
2023-12-01 21:07 Alexandre Oliva
2023-12-01 20:52 Alexandre Oliva
2023-12-01 20:47 Alexandre Oliva
2023-12-01 20:43 Alexandre Oliva

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=20231201213729.7B9CD385C6C4@sourceware.org \
    --to=aoliva@gcc.gnu.org \
    --cc=gcc-cvs@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).