]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix up push_local_extern_decl_alias error recovery [PR102642]
authorJakub Jelinek <jakub@redhat.com>
Wed, 20 Oct 2021 06:38:58 +0000 (08:38 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 20 Oct 2021 06:46:05 +0000 (08:46 +0200)
My recent push_local_extern_decl_alias change broke error-recovery,
do_pushdecl can return error_mark_node and set_decl_tls_model can't be
called on that.  There are other code paths that store error_mark_node
into DECL_LOCAL_DECL_ALIAS, with the intent to differentiate the cases
where we haven't yet tried to push it into the namespace scope (NULL)
and one where we have tried it but it failed (error_mark_node), but looking
around, there are other spots where we call functions or do processing
which doesn't tolerate error_mark_node.

So, the first hunk with the testcase fixes the testcase, the others
fix what I've spotted and the fix was easy to figure out (there are I think
3 other spots mainly for function multiversioning).

2021-10-20  Jakub Jelinek  <jakub@redhat.com>

PR c++/102642
* name-lookup.c (push_local_extern_decl_alias): Don't call
set_decl_tls_model on error_mark_node.
* decl.c (make_rtl_for_nonlocal_decl): Don't call
set_user_assembler_name on error_mark_node.
* parser.c (cp_parser_oacc_declare): Ignore DECL_LOCAL_DECL_ALIAS
if it is error_mark_node.
(cp_parser_omp_declare_target): Likewise.

* g++.dg/tls/pr102642.C: New test.

(cherry picked from commit 424945258d1778617b5d3d5273f6e1c10e718f80)

gcc/cp/decl.c
gcc/cp/name-lookup.c
gcc/cp/parser.c
gcc/testsuite/g++.dg/tls/pr102642.C [new file with mode: 0644]

index a3c06fdae8e70597043a4f59c4898c4551e544e7..3d605dc234021a125678de6cdfc6b08bb156d64b 100644 (file)
@@ -7240,7 +7240,8 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
                 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);
+             if (ns_decl != error_mark_node)
+               set_user_assembler_name (ns_decl, asmspec);
        }
     }
 
index ef9fdddc86e7a0f63bb56eec8df21f5502be5da8..c9ac3db4d98ed5b04991aa6ec9f9ebffb49981a9 100644 (file)
@@ -3477,7 +3477,9 @@ push_local_extern_decl_alias (tree decl)
          push_nested_namespace (ns);
          alias = do_pushdecl (alias, /* hiding= */true);
          pop_nested_namespace (ns);
-         if (VAR_P (decl) && CP_DECL_THREAD_LOCAL_P (decl))
+         if (VAR_P (decl)
+             && CP_DECL_THREAD_LOCAL_P (decl)
+             && alias != error_mark_node)
            set_decl_tls_model (alias, DECL_TLS_MODEL (decl));
        }
     }
index 40456a9dc5cf03b4296e9834a42c8b188a01a72d..030341640e9352b38d000e3f63fe9356f7f5adc0 100644 (file)
@@ -42359,7 +42359,8 @@ cp_parser_oacc_declare (cp_parser *parser, cp_token *pragma_tok)
               dependent local extern variable decls are as rare as
               hen's teeth.  */
            if (auto alias = DECL_LOCAL_DECL_ALIAS (decl))
-             decl = alias;
+             if (alias != error_mark_node)
+               decl = alias;
 
          if (OMP_CLAUSE_MAP_KIND (t) == GOMP_MAP_LINK)
            id = get_identifier ("omp declare target link");
@@ -43428,7 +43429,8 @@ cp_parser_omp_declare_target (cp_parser *parser, cp_token *pragma_tok)
       if (VAR_OR_FUNCTION_DECL_P (t)
          && DECL_LOCAL_DECL_P (t)
          && DECL_LANG_SPECIFIC (t)
-         && DECL_LOCAL_DECL_ALIAS (t))
+         && DECL_LOCAL_DECL_ALIAS (t)
+         && DECL_LOCAL_DECL_ALIAS (t) != error_mark_node)
        handle_omp_declare_target_clause (c, DECL_LOCAL_DECL_ALIAS (t),
                                          device_type);
     }
diff --git a/gcc/testsuite/g++.dg/tls/pr102642.C b/gcc/testsuite/g++.dg/tls/pr102642.C
new file mode 100644 (file)
index 0000000..e3236d3
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/102642
+// { dg-do compile { target c++11 } }
+
+thread_local int *z;           // { dg-message "previous declaration" }
+
+void
+foo ()
+{
+  extern thread_local int z;   // { dg-error "conflicting declaration" }
+}