+2015-06-30 Jason Merrill <jason@redhat.com>
+
+ PR debug/66653
+ * cp-tree.h (CP_DECL_THREAD_LOCAL_P): New.
+ (DECL_GNU_TLS_P): Use DECL_LANG_SPECIFIC field.
+ (SET_DECL_GNU_TLS_P): New.
+ * call.c (make_temporary_var_for_ref_to_temp): Use
+ CP_DECL_THREAD_LOCAL_P.
+ (set_up_extended_ref_temp): Likewise.
+ * decl.c (duplicate_decls, expand_static_init): Likewise.
+ (redeclaration_error_message, grokvardecl): Likewise.
+ (start_decl, register_dtor_fn, grokdeclarator): Likewise.
+ * decl2.c (get_guard, var_needs_tls_wrapper): Likewise.
+ (handle_tls_init): Likewise.
+ * pt.c (tsubst_decl, tsubst_copy_and_build): Likewise.
+ * semantics.c (finish_id_expression): Likewise.
+ (handle_omp_array_sections_1, finish_omp_clauses): Likewise.
+ (finish_omp_threadprivate): Likewise.
+ * tree.c (decl_storage_duration): Likewise.
+ * cp-gimplify.c (omp_var_to_track): Likewise.
+ (cp_genericize_r): Check that it matches DECL_THREAD_LOCAL_P.
+ * lex.c (retrofit_lang_decl): Return if DECL_LANG_SPECIFIC is
+ already set.
+
2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net>
Implement N4197 - Adding u8 character literals
/* Register the variable. */
if (VAR_P (decl)
- && (TREE_STATIC (decl) || DECL_THREAD_LOCAL_P (decl)))
+ && (TREE_STATIC (decl) || CP_DECL_THREAD_LOCAL_P (decl)))
{
/* Namespace-scope or local static; give it a mangled name. */
/* FIXME share comdat with decl? */
tree name;
TREE_STATIC (var) = TREE_STATIC (decl);
+ CP_DECL_THREAD_LOCAL_P (var) = CP_DECL_THREAD_LOCAL_P (decl);
set_decl_tls_model (var, DECL_TLS_MODEL (decl));
name = mangle_ref_init_variable (decl);
DECL_NAME (var) = name;
rest_of_decl_compilation (var, /*toplev=*/1, at_eof);
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
{
- if (DECL_THREAD_LOCAL_P (var))
+ if (CP_DECL_THREAD_LOCAL_P (var))
tls_aggregates = tree_cons (NULL_TREE, var,
tls_aggregates);
else
type = TREE_TYPE (type);
if (type == error_mark_node || !CLASS_TYPE_P (type))
return false;
- if (VAR_P (decl) && DECL_THREAD_LOCAL_P (decl))
+ if (VAR_P (decl) && CP_DECL_THREAD_LOCAL_P (decl))
return false;
if (cxx_omp_predetermined_sharing (decl) != OMP_CLAUSE_DEFAULT_UNSPECIFIED)
return false;
*stmt_p = build1 (NOP_EXPR, void_type_node, integer_zero_node);
*walk_subtrees = 0;
}
+ else if (TREE_CODE (stmt) == DECL_EXPR)
+ {
+ tree d = DECL_EXPR_DECL (stmt);
+ if (TREE_CODE (d) == VAR_DECL)
+ gcc_assert (CP_DECL_THREAD_LOCAL_P (d) == DECL_THREAD_LOCAL_P (d));
+ }
else if (TREE_CODE (stmt) == OMP_PARALLEL || TREE_CODE (stmt) == OMP_TASK)
{
struct cp_genericize_omp_taskreg omp_ctx;
AGGR_INIT_VIA_CTOR_P (in AGGR_INIT_EXPR)
PTRMEM_OK_P (in ADDR_EXPR, OFFSET_REF, SCOPE_REF)
PAREN_STRING_LITERAL (in STRING_CST)
- DECL_GNU_TLS_P (in VAR_DECL)
+ CP_DECL_THREAD_LOCAL_P (in VAR_DECL)
KOENIG_LOOKUP_P (in CALL_EXPR)
STATEMENT_LIST_NO_SCOPE (in STATEMENT_LIST).
EXPR_STMT_STMT_EXPR_RESULT (in EXPR_STMT)
unsigned repo_available_p : 1; /* var or fn */
unsigned threadprivate_or_deleted_p : 1; /* var or fn */
unsigned anticipated_p : 1; /* fn, type or template */
- unsigned friend_attr : 1; /* fn, type or template */
+ unsigned friend_or_tls : 1; /* var, fn, type or template */
unsigned template_conv_p : 1; /* var or template */
unsigned odr_used : 1; /* var or fn */
unsigned u2sel : 1;
and should not be added to the list of members for this class. */
#define DECL_FRIEND_P(NODE) \
(DECL_LANG_SPECIFIC (TYPE_FUNCTION_OR_TEMPLATE_DECL_CHECK (NODE)) \
- ->u.base.friend_attr)
+ ->u.base.friend_or_tls)
+
+/* Nonzero if the thread-local variable was declared with __thread as
+ opposed to thread_local. */
+#define DECL_GNU_TLS_P(NODE) \
+ (DECL_LANG_SPECIFIC (VAR_DECL_CHECK (NODE)) \
+ && DECL_LANG_SPECIFIC (NODE)->u.base.friend_or_tls)
+#define SET_DECL_GNU_TLS_P(NODE) \
+ (retrofit_lang_decl (VAR_DECL_CHECK (NODE)), \
+ DECL_LANG_SPECIFIC (NODE)->u.base.friend_or_tls = true)
/* A TREE_LIST of the types which have befriended this FUNCTION_DECL. */
#define DECL_BEFRIENDING_CLASSES(NODE) \
(DECL_NAME (NODE) \
&& !strcmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__PRETTY_FUNCTION__"))
-/* Nonzero if the thread-local variable was declared with __thread
- as opposed to thread_local. */
-#define DECL_GNU_TLS_P(NODE) \
+/* Nonzero if the variable was declared to be thread-local.
+ We need a special C++ version of this test because the middle-end
+ DECL_THREAD_LOCAL_P uses the symtab, so we can't use it for
+ templates. */
+#define CP_DECL_THREAD_LOCAL_P(NODE) \
(TREE_LANG_FLAG_0 (VAR_DECL_CHECK (NODE)))
/* The _TYPE context in which this _DECL appears. This field holds the
}
if (VAR_P (newdecl)
- && DECL_THREAD_LOCAL_P (newdecl))
- set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
+ && CP_DECL_THREAD_LOCAL_P (newdecl))
+ {
+ CP_DECL_THREAD_LOCAL_P (olddecl) = true;
+ if (!processing_template_decl)
+ set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
+ }
}
DECL_UID (olddecl) = olddecl_uid;
return NULL;
}
else if (VAR_P (newdecl)
- && DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)
+ && CP_DECL_THREAD_LOCAL_P (newdecl) != CP_DECL_THREAD_LOCAL_P (olddecl)
&& (! DECL_LANG_SPECIFIC (olddecl)
|| ! CP_DECL_THREADPRIVATE_P (olddecl)
- || DECL_THREAD_LOCAL_P (newdecl)))
+ || CP_DECL_THREAD_LOCAL_P (newdecl)))
{
/* Only variables can be thread-local, and all declarations must
agree on this property. */
- if (DECL_THREAD_LOCAL_P (newdecl))
+ if (CP_DECL_THREAD_LOCAL_P (newdecl))
return G_("thread-local declaration of %q#D follows "
"non-thread-local declaration");
else
&& DECL_DECLARED_CONSTEXPR_P (current_function_decl))
{
bool ok = false;
- if (DECL_THREAD_LOCAL_P (decl))
+ if (CP_DECL_THREAD_LOCAL_P (decl))
error ("%qD declared %<thread_local%> in %<constexpr%> function",
decl);
else if (TREE_STATIC (decl))
function to do the cleanup. */
dso_parm = (flag_use_cxa_atexit
&& !targetm.cxx.use_atexit_for_cxa_atexit ());
- ob_parm = (DECL_THREAD_LOCAL_P (decl) || dso_parm);
+ ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
use_dtor = ob_parm && CLASS_TYPE_P (type);
if (use_dtor)
{
mark_used (cleanup);
cleanup = build_address (cleanup);
- if (DECL_THREAD_LOCAL_P (decl))
+ if (CP_DECL_THREAD_LOCAL_P (decl))
atex_node = get_thread_atexit_node ();
else
atex_node = get_atexit_node ();
if (ob_parm)
{
- if (!DECL_THREAD_LOCAL_P (decl)
+ if (!CP_DECL_THREAD_LOCAL_P (decl)
&& targetm.cxx.use_aeabi_atexit ())
{
arg1 = cleanup;
return;
}
- if (DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
+ if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
&& !DECL_FUNCTION_SCOPE_P (decl))
{
if (init)
tree flag, begin;
/* We don't need thread-safety code for thread-local vars. */
bool thread_guard = (flag_threadsafe_statics
- && !DECL_THREAD_LOCAL_P (decl));
+ && !CP_DECL_THREAD_LOCAL_P (decl));
/* Emit code to perform this initialization but once. This code
looks like:
finish_then_clause (if_stmt);
finish_if_stmt (if_stmt);
}
- else if (DECL_THREAD_LOCAL_P (decl))
+ else if (CP_DECL_THREAD_LOCAL_P (decl))
tls_aggregates = tree_cons (init, decl, tls_aggregates);
else
static_aggregates = tree_cons (init, decl, static_aggregates);
if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
{
if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
- set_decl_tls_model (decl, decl_default_tls_model (decl));
+ {
+ CP_DECL_THREAD_LOCAL_P (decl) = true;
+ if (!processing_template_decl)
+ set_decl_tls_model (decl, decl_default_tls_model (decl));
+ }
if (declspecs->gnu_thread_keyword_p)
- DECL_GNU_TLS_P (decl) = true;
+ SET_DECL_GNU_TLS_P (decl);
}
/* If the type of the decl has no linkage, make sure that we'll
if (thread_p)
{
- set_decl_tls_model (decl, decl_default_tls_model (decl));
+ CP_DECL_THREAD_LOCAL_P (decl) = true;
+ if (!processing_template_decl)
+ set_decl_tls_model (decl, decl_default_tls_model (decl));
if (declspecs->gnu_thread_keyword_p)
- DECL_GNU_TLS_P (decl) = true;
+ SET_DECL_GNU_TLS_P (decl);
}
if (constexpr_p && !initialized)
TREE_STATIC (guard) = TREE_STATIC (decl);
DECL_COMMON (guard) = DECL_COMMON (decl);
DECL_COMDAT (guard) = DECL_COMDAT (decl);
+ CP_DECL_THREAD_LOCAL_P (guard) = CP_DECL_THREAD_LOCAL_P (decl);
set_decl_tls_model (guard, DECL_TLS_MODEL (decl));
if (DECL_ONE_ONLY (decl))
make_decl_one_only (guard, cxx_comdat_group (guard));
var_needs_tls_wrapper (tree var)
{
return (!error_operand_p (var)
- && DECL_THREAD_LOCAL_P (var)
+ && CP_DECL_THREAD_LOCAL_P (var)
&& !DECL_GNU_TLS_P (var)
&& !DECL_FUNCTION_SCOPE_P (var)
&& !var_defined_without_dynamic_init (var));
DECL_ARTIFICIAL (guard) = true;
DECL_IGNORED_P (guard) = true;
TREE_USED (guard) = true;
+ CP_DECL_THREAD_LOCAL_P (guard) = true;
set_decl_tls_model (guard, decl_default_tls_model (guard));
pushdecl_top_level_and_finish (guard, NULL_TREE);
size_t size;
int sel;
+ if (DECL_LANG_SPECIFIC (t))
+ return;
+
if (TREE_CODE (t) == FUNCTION_DECL)
sel = 1, size = sizeof (struct lang_decl_fn);
else if (TREE_CODE (t) == NAMESPACE_DECL)
}
SET_DECL_VALUE_EXPR (r, ve);
}
- if (TREE_STATIC (r) || DECL_EXTERNAL (r))
- set_decl_tls_model (r, decl_tls_model (t));
+ if (CP_DECL_THREAD_LOCAL_P (r)
+ && !processing_template_decl)
+ set_decl_tls_model (r, decl_default_tls_model (r));
}
else if (DECL_SELF_REFERENCE_P (t))
SET_DECL_SELF_REFERENCE_P (r);
&& !processing_template_decl
&& !cp_unevaluated_operand
&& (TREE_STATIC (r) || DECL_EXTERNAL (r))
- && DECL_THREAD_LOCAL_P (r))
+ && CP_DECL_THREAD_LOCAL_P (r))
{
if (tree wrap = get_tls_wrapper_fn (r))
/* Replace an evaluated use of the thread_local variable with
&& !cp_unevaluated_operand
&& !processing_template_decl
&& (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
- && DECL_THREAD_LOCAL_P (decl)
+ && CP_DECL_THREAD_LOCAL_P (decl)
&& (wrap = get_tls_wrapper_fn (decl)))
{
/* Replace an evaluated use of the thread_local variable with
return error_mark_node;
}
else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
- && VAR_P (t) && DECL_THREAD_LOCAL_P (t))
+ && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
{
error_at (OMP_CLAUSE_LOCATION (c),
"%qD is threadprivate variable in %qs clause", t,
omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
remove = true;
}
- else if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
+ else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
{
error ("%qD is threadprivate variable in %qs clause", t,
omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
break;
case OMP_CLAUSE_COPYIN:
- if (!VAR_P (t) || !DECL_THREAD_LOCAL_P (t))
+ if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
{
error ("%qE must be %<threadprivate%> for %<copyin%>", t);
remove = true;
{
const char *share_name = NULL;
- if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
+ if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
share_name = "threadprivate";
else switch (cxx_omp_predetermined_sharing (t))
{
DECL_LANG_SPECIFIC (v)->u.base.u2sel = 1;
}
- if (! DECL_THREAD_LOCAL_P (v))
+ if (! CP_DECL_THREAD_LOCAL_P (v))
{
+ CP_DECL_THREAD_LOCAL_P (v) = true;
set_decl_tls_model (v, decl_default_tls_model (v));
/* If rtl has been already set for this var, call
make_decl_rtl once again, so that encode_section_info
if (!TREE_STATIC (decl)
&& !DECL_EXTERNAL (decl))
return dk_auto;
- if (DECL_THREAD_LOCAL_P (decl))
+ if (CP_DECL_THREAD_LOCAL_P (decl))
return dk_thread;
return dk_static;
}
--- /dev/null
+// PR c++/66653
+// { dg-options "-gdwarf" }
+
+template <typename T> class A
+{
+ static __thread T a;
+};