sgallagh / rpms / gcc

Forked from rpms/gcc 3 years ago
Clone
68a50d6
2021-10-11  Jakub Jelinek  <jakub@redhat.com>
68a50d6
68a50d6
	PR c++/102642
68a50d6
	* name-lookup.c (push_local_extern_decl_alias): Don't call
68a50d6
	set_decl_tls_model on error_mark_node.
68a50d6
	* parser.c (cp_parser_omp_declare_target): Likewise.
68a50d6
68a50d6
	* g++.dg/tls/pr102642.C: New test.
68a50d6
68a50d6
--- gcc/cp/name-lookup.c.jj	2021-10-01 10:30:07.674588541 +0200
68a50d6
+++ gcc/cp/name-lookup.c	2021-10-11 12:43:39.261051228 +0200
68a50d6
@@ -3474,7 +3474,9 @@ push_local_extern_decl_alias (tree decl)
68a50d6
 	  push_nested_namespace (ns);
68a50d6
 	  alias = do_pushdecl (alias, /* hiding= */true);
68a50d6
 	  pop_nested_namespace (ns);
68a50d6
-	  if (VAR_P (decl) && CP_DECL_THREAD_LOCAL_P (decl))
68a50d6
+	  if (VAR_P (decl)
68a50d6
+	      && CP_DECL_THREAD_LOCAL_P (decl)
68a50d6
+	      && alias != error_mark_node)
68a50d6
 	    set_decl_tls_model (alias, DECL_TLS_MODEL (decl));
68a50d6
 	}
68a50d6
     }
68a50d6
--- gcc/cp/parser.c.jj	2021-10-09 10:14:24.043098112 +0200
68a50d6
+++ gcc/cp/parser.c	2021-10-11 12:47:21.220874667 +0200
68a50d6
@@ -45665,7 +45666,8 @@ cp_parser_omp_declare_target (cp_parser
68a50d6
       if (VAR_OR_FUNCTION_DECL_P (t)
68a50d6
 	  && DECL_LOCAL_DECL_P (t)
68a50d6
 	  && DECL_LANG_SPECIFIC (t)
68a50d6
-	  && DECL_LOCAL_DECL_ALIAS (t))
68a50d6
+	  && DECL_LOCAL_DECL_ALIAS (t)
68a50d6
+	  && DECL_LOCAL_DECL_ALIAS (t) != error_mark_node)
68a50d6
 	handle_omp_declare_target_clause (c, DECL_LOCAL_DECL_ALIAS (t),
68a50d6
 					  device_type);
68a50d6
     }
68a50d6
--- gcc/testsuite/g++.dg/tls/pr102642.C.jj	2021-10-11 13:00:35.889503002 +0200
68a50d6
+++ gcc/testsuite/g++.dg/tls/pr102642.C	2021-10-11 13:00:20.388724721 +0200
68a50d6
@@ -0,0 +1,10 @@
68a50d6
+// PR c++/102642
68a50d6
+// { dg-do compile { target c++11 } }
68a50d6
+
68a50d6
+thread_local int *z;		// { dg-message "previous declaration" }
68a50d6
+
68a50d6
+void
68a50d6
+foo ()
68a50d6
+{
68a50d6
+  extern thread_local int z;	// { dg-error "conflicting declaration" }
68a50d6
+}