]> gcc.gnu.org Git - gcc.git/commitdiff
c++: Propagate assembler name from local-externs [PR 99508]
authorNathan Sidwell <nathan@acm.org>
Wed, 10 Mar 2021 15:39:51 +0000 (07:39 -0800)
committerNathan Sidwell <nathan@acm.org>
Wed, 10 Mar 2021 15:50:32 +0000 (07:50 -0800)
This is another place where our one-true-decl representation breaks
down.  The fix here propagates the assembly name to the ns-scope
alias.  that fixes the reported problem but changes the behaviour when
the user has explicitly declared the entity in its namespace.
However, we didn't handle that case 'correctly' anyway before.
Previously we'd also ignore the explicitly specified assembler name,
now we propagate it.  It's not clear to me what the desired semantics
would be in decorating just one of the local extern declarations this
way.  I don't think we can really do better without propagating this
aliasing property into the middle end (which is also needed for some
constexpr handling, see PR97306).  I tried that before and it turned
into a rat-hole.

PR c++/99508
gcc/cp/
* decl.c (make_rtl_for_nonlocal_decl): Propagate local-extern's
assembler name to the ns alias.
gcc/testsuite/
* g++.dg/ext/pr99508.C: New.

gcc/cp/decl.c
gcc/testsuite/g++.dg/ext/pr99508.C [new file with mode: 0644]

index 1742e286d9f66b8e0111bcb79a31d5e2814c551a..9c7f6e59bbb78a5fed1699d075662c6b4e1a0ef9 100644 (file)
@@ -7157,6 +7157,13 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
              && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
            set_builtin_user_assembler_name (decl, asmspec);
          set_user_assembler_name (decl, asmspec);
+         if (DECL_LOCAL_DECL_P (decl))
+           if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
+             /* We have to propagate the name to the ns-alias.
+                This is horrible, as we're affecting a
+                possibly-shared decl.  Again, a one-true-decl
+                model breaks down.  */
+             set_user_assembler_name (ns_decl, asmspec);
        }
     }
 
diff --git a/gcc/testsuite/g++.dg/ext/pr99508.C b/gcc/testsuite/g++.dg/ext/pr99508.C
new file mode 100644 (file)
index 0000000..201a287
--- /dev/null
@@ -0,0 +1,20 @@
+// PR 99508, local exerns with aliased names
+// { dg-do link }
+int foo()
+{
+  void bar() asm ("bar_assembler");
+  extern unsigned buzz asm("buzz_assembler");
+  bar();
+  return buzz;
+}
+
+void ALIASbar () asm ("bar_assembler");
+void ALIASbar ()
+{
+}
+
+unsigned ALIASbuz asm ("buzz_assembler") = 5;
+
+int main ()
+{
+}
This page took 0.086721 seconds and 5 git commands to generate.