diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-10 08:25:17 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-10 08:25:17 +0000 |
commit | d640c29f86f8993c04dd9ea0fb673fab0714739b (patch) | |
tree | 614c0136821a4b0cc1d908634346cf7b2b65ca18 /gcc/cp | |
parent | b95e3f379ca88868cf3b683362c321c81a5b943f (diff) | |
download | gcc-d640c29f86f8993c04dd9ea0fb673fab0714739b.tar.gz |
2012-10-10 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 192289 using svnmerge.py
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@192291 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 76 | ||||
-rw-r--r-- | gcc/cp/Make-lang.in | 6 | ||||
-rw-r--r-- | gcc/cp/call.c | 22 | ||||
-rw-r--r-- | gcc/cp/class.c | 18 | ||||
-rw-r--r-- | gcc/cp/cp-gimplify.c | 11 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 14 | ||||
-rw-r--r-- | gcc/cp/decl.c | 190 | ||||
-rw-r--r-- | gcc/cp/decl.h | 2 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 257 | ||||
-rw-r--r-- | gcc/cp/mangle.c | 59 | ||||
-rw-r--r-- | gcc/cp/parser.c | 120 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 23 | ||||
-rw-r--r-- | gcc/cp/tree.c | 17 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 53 |
14 files changed, 712 insertions, 156 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 660a2199c8f..68ebb96a7c3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,79 @@ +2012-10-10 Dehao Chen <dehao@google.com> + + * cp-gimplify.c (cp_genericize_r): Set location for TRY expr. + +2012-10-09 Lawrence Crowl <crowl@google.com> + + * Make-lang.in (class.o): Add dependence on hash-table.h. + (tree.o): Likewise. + (semantics.o): Likewise. + * class.c (fixed_type_or_null): Change to new type-safe hash table. + * tree.c (verify_stmt_tree): Likewise. + (verify_stmt_tree_r): Likewise. + * semantics.c (struct nrv_data): Likewise. + +2012-10-09 Paolo Carlini <paolo.carlini@oracle.com> + + PR c++/54194 + * typeck.c (build_x_binary_op): Update warn_about_parentheses call. + * parser.c (cp_parser_binary_expression): Use SET_EXPR_LOCATION + on current.lhs. + +2012-10-09 Marc Glisse <marc.glisse@inria.fr> + + PR c++/54427 + * typeck.c (cp_build_binary_op): Handle mixed scalar-vector + operations. + [LSHIFT_EXPR, RSHIFT_EXPR]: Likewise. + +2012-10-08 Jakub Jelinek <jakub@redhat.com> + + PR c++/54858 + * tree.c (cp_tree_equal): Handle FIELD_DECL. + +2012-10-08 Jason Merrill <jason@redhat.com> + + Allow dynamic initialization of thread_locals. + * decl.c: Define tls_aggregates. + (expand_static_init): Remove sorry. Add to tls_aggregates. + * cp-tree.h: Declare tls_aggregates. + * call.c (set_up_extended_ref_temp): Add to tls_aggregates. + * decl2.c (var_needs_tls_wrapper): New. + (var_defined_without_dynamic_init): New. + (get_tls_init_fn, get_tls_wrapper_fn): New. + (generate_tls_wrapper, handle_tls_init): New. + (cp_write_global_declarations): Call handle_tls_init and + enerate_tls_wrapper. + * mangle.c (write_guarded_var_name): Split out from.. + (mangle_guard_variable): ...here. + (mangle_tls_init_fn, mangle_tls_wrapper_fn): Use it. + (decl_tls_wrapper_p): New. + * semantics.c (finish_id_expression): Replace use of thread_local + variable with a call to its wrapper. + + * decl.c (get_thread_atexit_node): New. + (register_dtor_fn): Use it for TLS. + + Partial implementation of C++11 thread_local. + * decl.c (cp_finish_decl): Remove errors about non-trivial + initialization and destruction of TLS variables. + (register_dtor_fn): Add sorry about TLS variables. + (expand_static_init): Add sorry about non-local TLS variables, + or error with __thread. + Don't emit thread-safety guards for local TLS variables. + (grokdeclarator): thread_local in a function implies static. + * decl.h: Adjust prototype. + * decl2.c (get_guard): Copy DECL_TLS_MODEL. + * parser.c (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) + (set_and_check_decl_spec_loc): Take the token rather than the location. + Distinguish between __thread and thread_local. + (cp_parser_set_storage_class): Don't complain about thread_local before + extern/static. + (token_is__thread): New. + * call.c (make_temporary_var_for_ref_to_temp): Handle TLS. + * cp-tree.h (DECL_GNU_TLS_P): New. + (cp_decl_specifier_seq): Add gnu_thread_keyword_p. + 2012-10-08 Dodji Seketeli <dodji@redhat.com> PR c++/53528 C++11 attribute support diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index 7b1d4e644cd..812f3cb5c7e 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -293,7 +293,7 @@ cp/typeck.o: cp/typeck.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \ c-family/c-objc.h cp/class.o: cp/class.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h \ $(TARGET_H) convert.h $(CGRAPH_H) dumpfile.h gt-cp-class.h \ - $(SPLAY_TREE_H) pointer-set.h + $(SPLAY_TREE_H) pointer-set.h $(HASH_TABLE_H) cp/call.o: cp/call.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h \ $(DIAGNOSTIC_CORE_H) intl.h gt-cp-call.h convert.h $(TARGET_H) langhooks.h \ $(TIMEVAR_H) c-family/c-objc.h @@ -309,7 +309,7 @@ cp/search.o: cp/search.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h \ intl.h cp/tree.o: cp/tree.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \ $(TREE_INLINE_H) $(REAL_H) gt-cp-tree.h \ - $(TARGET_H) debug.h $(CGRAPH_H) $(SPLAY_TREE_H) $(GIMPLE_H) + $(TARGET_H) debug.h $(CGRAPH_H) $(SPLAY_TREE_H) $(GIMPLE_H) $(HASH_TABLE_H) cp/ptree.o: cp/ptree.c $(CXX_TREE_H) $(TM_H) cp/rtti.o: cp/rtti.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) convert.h \ $(TARGET_H) $(C_PRAGMA_H) gt-cp-rtti.h intl.h @@ -327,7 +327,7 @@ cp/repo.o: cp/repo.c $(CXX_TREE_H) $(TM_H) toplev.h $(DIAGNOSTIC_CORE_H) \ cp/semantics.o: cp/semantics.c $(CXX_TREE_H) $(TM_H) toplev.h \ $(FLAGS_H) $(RTL_H) $(TIMEVAR_H) \ $(TREE_INLINE_H) $(CGRAPH_H) $(TARGET_H) $(C_COMMON_H) $(GIMPLE_H) \ - bitmap.h gt-cp-semantics.h c-family/c-objc.h + bitmap.h gt-cp-semantics.h c-family/c-objc.h $(HASH_TABLE_H) cp/dump.o: cp/dump.c $(CXX_TREE_H) $(TM_H) $(TREE_DUMP_H) cp/optimize.o: cp/optimize.c $(CXX_TREE_H) $(TM_H) \ input.h $(PARAMS_H) debug.h $(TREE_INLINE_H) $(GIMPLE_H) \ diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f58dc8a52e0..3351a585f2b 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -8719,9 +8719,9 @@ perform_direct_initialization_if_possible (tree type, The next several functions are involved in this lifetime extension. */ -/* DECL is a VAR_DECL whose type is a REFERENCE_TYPE. The reference - is being bound to a temporary. Create and return a new VAR_DECL - with the indicated TYPE; this variable will store the value to +/* DECL is a VAR_DECL or FIELD_DECL whose type is a REFERENCE_TYPE. The + reference is being bound to a temporary. Create and return a new + VAR_DECL with the indicated TYPE; this variable will store the value to which the reference is bound. */ tree @@ -8733,13 +8733,15 @@ make_temporary_var_for_ref_to_temp (tree decl, tree type) var = create_temporary_var (type); /* Register the variable. */ - if (TREE_STATIC (decl)) + if (TREE_CODE (decl) == VAR_DECL + && (TREE_STATIC (decl) || 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) = 1; + TREE_STATIC (var) = TREE_STATIC (decl); + DECL_TLS_MODEL (var) = DECL_TLS_MODEL (decl); name = mangle_ref_init_variable (decl); DECL_NAME (var) = name; SET_DECL_ASSEMBLER_NAME (var, name); @@ -8858,8 +8860,14 @@ set_up_extended_ref_temp (tree decl, tree expr, VEC(tree,gc) **cleanups, { rest_of_decl_compilation (var, /*toplev=*/1, at_eof); if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) - static_aggregates = tree_cons (NULL_TREE, var, - static_aggregates); + { + if (DECL_THREAD_LOCAL_P (var)) + tls_aggregates = tree_cons (NULL_TREE, var, + tls_aggregates); + else + static_aggregates = tree_cons (NULL_TREE, var, + static_aggregates); + } } *initp = init; diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 8de142347f4..0e77b81c85b 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see #include "dumpfile.h" #include "splay-tree.h" #include "pointer-set.h" +#include "hash-table.h" /* The number of nested classes being processed. If we are not in the scope of any class, this is zero. */ @@ -6465,12 +6466,9 @@ fixed_type_or_null (tree instance, int *nonnull, int *cdtorp) else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE) { /* We only need one hash table because it is always left empty. */ - static htab_t ht; - if (!ht) - ht = htab_create (37, - htab_hash_pointer, - htab_eq_pointer, - /*htab_del=*/NULL); + static hash_table <pointer_hash <tree_node> > ht; + if (!ht.is_created ()) + ht.create (37); /* Reference variables should be references to objects. */ if (nonnull) @@ -6482,15 +6480,15 @@ fixed_type_or_null (tree instance, int *nonnull, int *cdtorp) if (TREE_CODE (instance) == VAR_DECL && DECL_INITIAL (instance) && !type_dependent_expression_p_push (DECL_INITIAL (instance)) - && !htab_find (ht, instance)) + && !ht.find (instance)) { tree type; - void **slot; + tree_node **slot; - slot = htab_find_slot (ht, instance, INSERT); + slot = ht.find_slot (instance, INSERT); *slot = instance; type = RECUR (DECL_INITIAL (instance)); - htab_remove_elt (ht, instance); + ht.remove_elt (instance); return type; } diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 6178993fe89..f715e963c49 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -948,11 +948,12 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) to lower this construct before scanning it, so we need to lower these before doing anything else. */ else if (TREE_CODE (stmt) == CLEANUP_STMT) - *stmt_p = build2 (CLEANUP_EH_ONLY (stmt) ? TRY_CATCH_EXPR - : TRY_FINALLY_EXPR, - void_type_node, - CLEANUP_BODY (stmt), - CLEANUP_EXPR (stmt)); + *stmt_p = build2_loc (EXPR_LOCATION (stmt), + CLEANUP_EH_ONLY (stmt) ? TRY_CATCH_EXPR + : TRY_FINALLY_EXPR, + void_type_node, + CLEANUP_BODY (stmt), + CLEANUP_EXPR (stmt)); else if (TREE_CODE (stmt) == IF_STMT) { diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a1d44240189..370f07230f0 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -56,6 +56,7 @@ c-common.h, not after. 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) KOENIG_LOOKUP_P (in CALL_EXPR) STATEMENT_LIST_NO_SCOPE (in STATEMENT_LIST). EXPR_STMT_STMT_EXPR_RESULT (in EXPR_STMT) @@ -2425,6 +2426,11 @@ struct GTY((variable_size)) lang_decl { (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) \ + (TREE_LANG_FLAG_0 (VAR_DECL_CHECK (NODE))) + /* The _TYPE context in which this _DECL appears. This field holds the class where a virtual function instance is actually defined. */ #define DECL_CLASS_CONTEXT(NODE) \ @@ -4379,6 +4385,8 @@ extern int at_eof; in the TREE_VALUE slot and the initializer is stored in the TREE_PURPOSE slot. */ extern GTY(()) tree static_aggregates; +/* Likewise, for thread local storage. */ +extern GTY(()) tree tls_aggregates; enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, TYPENAME_FLAG }; @@ -4732,6 +4740,8 @@ typedef struct cp_decl_specifier_seq { BOOL_BITFIELD explicit_int128_p : 1; /* True iff "char" was explicitly provided. */ BOOL_BITFIELD explicit_char_p : 1; + /* True iff ds_thread is set for __thread, not thread_local. */ + BOOL_BITFIELD gnu_thread_keyword_p : 1; } cp_decl_specifier_seq; /* The various kinds of declarators. */ @@ -5189,6 +5199,7 @@ extern tree cp_build_parm_decl (tree, tree); extern tree get_guard (tree); extern tree get_guard_cond (tree); extern tree set_guard (tree); +extern tree get_tls_wrapper_fn (tree); extern void mark_needed (tree); extern bool decl_needed_p (tree); extern void note_vague_linkage_fn (tree); @@ -5984,6 +5995,9 @@ extern tree mangle_ctor_vtbl_for_type (tree, tree); extern tree mangle_thunk (tree, int, tree, tree); extern tree mangle_conv_op_name_for_type (tree); extern tree mangle_guard_variable (tree); +extern tree mangle_tls_init_fn (tree); +extern tree mangle_tls_wrapper_fn (tree); +extern bool decl_tls_wrapper_p (tree); extern tree mangle_ref_init_variable (tree); /* in dump.c */ diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 2848ad5b7be..0b936ea1a8b 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -169,6 +169,9 @@ tree global_scope_name; in the TREE_PURPOSE slot. */ tree static_aggregates; +/* Like static_aggregates, but for thread_local variables. */ +tree tls_aggregates; + /* -- end of C++ */ /* A node for the integer constant 2. */ @@ -6227,13 +6230,6 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (TREE_CODE (decl) == VAR_DECL) { - /* Only variables with trivial initialization and destruction can - have thread-local storage. */ - if (DECL_THREAD_LOCAL_P (decl) - && (type_has_nontrivial_default_init (TREE_TYPE (decl)) - || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))) - error ("%qD cannot be thread-local because it has non-trivial " - "type %qT", decl, TREE_TYPE (decl)); /* If this is a local variable that will need a mangled name, register it now. We must do this before processing the initializer for the variable, since the initialization might @@ -6279,13 +6275,6 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, } cleanups = make_tree_vector (); init = check_initializer (decl, init, flags, &cleanups); - /* Thread-local storage cannot be dynamically initialized. */ - if (DECL_THREAD_LOCAL_P (decl) && init) - { - error ("%qD is thread-local and so cannot be dynamically " - "initialized", decl); - init = NULL_TREE; - } /* Check that the initializer for a static data member was a constant. Although we check in the parser that the @@ -6589,6 +6578,24 @@ get_atexit_node (void) return atexit_node; } +/* Like get_atexit_node, but for thread-local cleanups. */ + +static tree +get_thread_atexit_node (void) +{ + /* The declaration for `__cxa_thread_atexit' is: + + int __cxa_thread_atexit (void (*)(void *), void *, void *) */ + tree fn_type = build_function_type_list (integer_type_node, + get_atexit_fn_ptr_type (), + ptr_type_node, ptr_type_node, + NULL_TREE); + + /* Now, build the function declaration. */ + tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type); + return decay_conversion (atexit_fndecl, tf_warning_or_error); +} + /* Returns the __dso_handle VAR_DECL. */ static tree @@ -6680,23 +6687,27 @@ tree register_dtor_fn (tree decl) { tree cleanup; + tree addr; tree compound_stmt; tree fcall; tree type; - bool use_dtor; - tree arg0, arg1 = NULL_TREE, arg2 = NULL_TREE; + bool ob_parm, dso_parm, use_dtor; + tree arg0, arg1, arg2; + tree atex_node; type = TREE_TYPE (decl); if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)) return void_zero_node; - /* If we're using "__cxa_atexit" (or "__aeabi_atexit"), and DECL is - a class object, we can just pass the destructor to - "__cxa_atexit"; we don't have to build a temporary function to do - the cleanup. */ - use_dtor = (flag_use_cxa_atexit - && !targetm.cxx.use_atexit_for_cxa_atexit () - && CLASS_TYPE_P (type)); + /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or + "__aeabi_atexit"), and DECL is a class object, we can just pass the + destructor to "__cxa_atexit"; we don't have to build a temporary + function to do the cleanup. */ + ob_parm = (DECL_THREAD_LOCAL_P (decl) + || (flag_use_cxa_atexit + && !targetm.cxx.use_atexit_for_cxa_atexit ())); + dso_parm = ob_parm; + use_dtor = ob_parm && CLASS_TYPE_P (type); if (use_dtor) { int idx; @@ -6737,35 +6748,45 @@ register_dtor_fn (tree decl) /* Call atexit with the cleanup function. */ mark_used (cleanup); cleanup = build_address (cleanup); - if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ()) + + if (DECL_THREAD_LOCAL_P (decl)) + atex_node = get_thread_atexit_node (); + else + atex_node = get_atexit_node (); + + if (use_dtor) { - tree addr; + /* We must convert CLEANUP to the type that "__cxa_atexit" + expects. */ + cleanup = build_nop (get_atexit_fn_ptr_type (), cleanup); + /* "__cxa_atexit" will pass the address of DECL to the + cleanup function. */ + mark_used (decl); + addr = build_address (decl); + /* The declared type of the parameter to "__cxa_atexit" is + "void *". For plain "T*", we could just let the + machinery in cp_build_function_call convert it -- but if the + type is "cv-qualified T *", then we need to convert it + before passing it in, to avoid spurious errors. */ + addr = build_nop (ptr_type_node, addr); + } + else if (ob_parm) + /* Since the cleanup functions we build ignore the address + they're given, there's no reason to pass the actual address + in, and, in general, it's cheaper to pass NULL than any + other value. */ + addr = null_pointer_node; + + if (dso_parm) + arg2 = cp_build_addr_expr (get_dso_handle_node (), + tf_warning_or_error); + else + arg2 = NULL_TREE; - if (use_dtor) - { - /* We must convert CLEANUP to the type that "__cxa_atexit" - expects. */ - cleanup = build_nop (get_atexit_fn_ptr_type (), cleanup); - /* "__cxa_atexit" will pass the address of DECL to the - cleanup function. */ - mark_used (decl); - addr = build_address (decl); - /* The declared type of the parameter to "__cxa_atexit" is - "void *". For plain "T*", we could just let the - machinery in cp_build_function_call convert it -- but if the - type is "cv-qualified T *", then we need to convert it - before passing it in, to avoid spurious errors. */ - addr = build_nop (ptr_type_node, addr); - } - else - /* Since the cleanup functions we build ignore the address - they're given, there's no reason to pass the actual address - in, and, in general, it's cheaper to pass NULL than any - other value. */ - addr = null_pointer_node; - arg2 = cp_build_addr_expr (get_dso_handle_node (), - tf_warning_or_error); - if (targetm.cxx.use_aeabi_atexit ()) + if (ob_parm) + { + if (!DECL_THREAD_LOCAL_P (decl) + && targetm.cxx.use_aeabi_atexit ()) { arg1 = cleanup; arg0 = addr; @@ -6777,8 +6798,11 @@ register_dtor_fn (tree decl) } } else - arg0 = cleanup; - return cp_build_function_call_nary (get_atexit_node (), tf_warning_or_error, + { + arg0 = cleanup; + arg1 = NULL_TREE; + } + return cp_build_function_call_nary (atex_node, tf_warning_or_error, arg0, arg1, arg2, NULL_TREE); } @@ -6797,6 +6821,26 @@ expand_static_init (tree decl, tree init) && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl))) return; + if (DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl) + && !DECL_FUNCTION_SCOPE_P (decl)) + { + if (init) + error ("non-local variable %qD declared %<__thread%> " + "needs dynamic initialization", decl); + else + error ("non-local variable %qD declared %<__thread%> " + "has a non-trivial destructor", decl); + static bool informed; + if (!informed) + { + inform (DECL_SOURCE_LOCATION (decl), + "C++11 %<thread_local%> allows dynamic initialization " + "and destruction"); + informed = true; + } + return; + } + if (DECL_FUNCTION_SCOPE_P (decl)) { /* Emit code to perform this initialization but once. */ @@ -6804,6 +6848,9 @@ expand_static_init (tree decl, tree init) tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE; tree guard, guard_addr; 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)); /* Emit code to perform this initialization but once. This code looks like: @@ -6842,7 +6889,7 @@ expand_static_init (tree decl, tree init) /* This optimization isn't safe on targets with relaxed memory consistency. On such targets we force synchronization in __cxa_guard_acquire. */ - if (!targetm.relaxed_ordering || !flag_threadsafe_statics) + if (!targetm.relaxed_ordering || !thread_guard) { /* Begin the conditional initialization. */ if_stmt = begin_if_stmt (); @@ -6850,7 +6897,7 @@ expand_static_init (tree decl, tree init) then_clause = begin_compound_stmt (BCS_NO_SCOPE); } - if (flag_threadsafe_statics) + if (thread_guard) { tree vfntype = NULL_TREE; tree acquire_name, release_name, abort_name; @@ -6908,20 +6955,22 @@ expand_static_init (tree decl, tree init) finish_expr_stmt (init); - if (flag_threadsafe_statics) + if (thread_guard) { finish_compound_stmt (inner_then_clause); finish_then_clause (inner_if_stmt); finish_if_stmt (inner_if_stmt); } - if (!targetm.relaxed_ordering || !flag_threadsafe_statics) + if (!targetm.relaxed_ordering || !thread_guard) { finish_compound_stmt (then_clause); finish_then_clause (if_stmt); finish_if_stmt (if_stmt); } } + else if (DECL_THREAD_LOCAL_P (decl)) + tls_aggregates = tree_cons (init, decl, tls_aggregates); else static_aggregates = tree_cons (init, decl, static_aggregates); } @@ -7732,7 +7781,11 @@ grokvardecl (tree type, } if (decl_spec_seq_has_spec_p (declspecs, ds_thread)) - DECL_TLS_MODEL (decl) = decl_default_tls_model (decl); + { + DECL_TLS_MODEL (decl) = decl_default_tls_model (decl); + if (declspecs->gnu_thread_keyword_p) + DECL_GNU_TLS_P (decl) = true; + } /* If the type of the decl has no linkage, make sure that we'll notice that in mark_used. */ @@ -8462,7 +8515,7 @@ check_var_type (tree identifier, tree type) tree grokdeclarator (const cp_declarator *declarator, - const cp_decl_specifier_seq *declspecs, + cp_decl_specifier_seq *declspecs, enum decl_context decl_context, int initialized, tree* attrlist) @@ -9176,9 +9229,15 @@ grokdeclarator (const cp_declarator *declarator, && storage_class != sc_extern && storage_class != sc_static) { - error ("function-scope %qs implicitly auto and declared %<__thread%>", - name); - thread_p = false; + if (declspecs->gnu_thread_keyword_p) + pedwarn (input_location, 0, "function-scope %qs implicitly auto and " + "declared %<__thread%>", name); + + /* When thread_local is applied to a variable of block scope the + storage-class-specifier static is implied if it does not appear + explicitly. */ + storage_class = declspecs->storage_class = sc_static; + staticp = 1; } if (storage_class && friendp) @@ -10454,7 +10513,14 @@ grokdeclarator (const cp_declarator *declarator, else if (storage_class == sc_register) error ("storage class %<register%> invalid for function %qs", name); else if (thread_p) - error ("storage class %<__thread%> invalid for function %qs", name); + { + if (declspecs->gnu_thread_keyword_p) + error ("storage class %<__thread%> invalid for function %qs", + name); + else + error ("storage class %<thread_local%> invalid for function %qs", + name); + } if (virt_specifiers) error ("virt-specifiers in %qs not allowed outside a class definition", name); diff --git a/gcc/cp/decl.h b/gcc/cp/decl.h index a8a2b784c28..193df27c2f8 100644 --- a/gcc/cp/decl.h +++ b/gcc/cp/decl.h @@ -34,7 +34,7 @@ enum decl_context /* We need this in here to get the decl_context definition. */ extern tree grokdeclarator (const cp_declarator *, - const cp_decl_specifier_seq *, + cp_decl_specifier_seq *, enum decl_context, int, tree*); /* States indicating how grokdeclarator() should handle declspecs marked diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index aad3d0b26f7..688a72332ce 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -2696,6 +2696,7 @@ get_guard (tree decl) TREE_STATIC (guard) = TREE_STATIC (decl); DECL_COMMON (guard) = DECL_COMMON (decl); DECL_COMDAT (guard) = DECL_COMDAT (decl); + DECL_TLS_MODEL (guard) = DECL_TLS_MODEL (decl); if (DECL_ONE_ONLY (decl)) make_decl_one_only (guard, cxx_comdat_group (guard)); if (TREE_PUBLIC (decl)) @@ -2780,6 +2781,187 @@ set_guard (tree guard) tf_warning_or_error); } +/* Returns true iff we can tell that VAR does not have a dynamic + initializer. */ + +static bool +var_defined_without_dynamic_init (tree var) +{ + /* If it's defined in another TU, we can't tell. */ + if (DECL_EXTERNAL (var)) + return false; + /* If it has a non-trivial destructor, registering the destructor + counts as dynamic initialization. */ + if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (var))) + return false; + /* If it's in this TU, its initializer has been processed. */ + gcc_assert (DECL_INITIALIZED_P (var)); + /* If it has no initializer or a constant one, it's not dynamic. */ + return (!DECL_NONTRIVIALLY_INITIALIZED_P (var) + || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var)); +} + +/* Returns true iff VAR is a variable that needs uses to be + wrapped for possible dynamic initialization. */ + +static bool +var_needs_tls_wrapper (tree var) +{ + return (DECL_THREAD_LOCAL_P (var) + && !DECL_GNU_TLS_P (var) + && !DECL_FUNCTION_SCOPE_P (var) + && !var_defined_without_dynamic_init (var)); +} + +/* Get a FUNCTION_DECL for the init function for the thread_local + variable VAR. The init function will be an alias to the function + that initializes all the non-local TLS variables in the translation + unit. The init function is only used by the wrapper function. */ + +static tree +get_tls_init_fn (tree var) +{ + /* Only C++11 TLS vars need this init fn. */ + if (!var_needs_tls_wrapper (var)) + return NULL_TREE; + + tree sname = mangle_tls_init_fn (var); + tree fn = IDENTIFIER_GLOBAL_VALUE (sname); + if (!fn) + { + fn = build_lang_decl (FUNCTION_DECL, sname, + build_function_type (void_type_node, + void_list_node)); + SET_DECL_LANGUAGE (fn, lang_c); + TREE_PUBLIC (fn) = TREE_PUBLIC (var); + DECL_ARTIFICIAL (fn) = true; + DECL_COMDAT (fn) = DECL_COMDAT (var); + DECL_EXTERNAL (fn) = true; + if (DECL_ONE_ONLY (var)) + make_decl_one_only (fn, cxx_comdat_group (fn)); + if (TREE_PUBLIC (var)) + { + tree obtype = strip_array_types (non_reference (TREE_TYPE (var))); + /* If the variable might have static initialization, make the + init function a weak reference. */ + if ((!TYPE_NEEDS_CONSTRUCTING (obtype) + || TYPE_HAS_CONSTEXPR_CTOR (obtype)) + && TARGET_SUPPORTS_WEAK) + declare_weak (fn); + else + DECL_WEAK (fn) = DECL_WEAK (var); + } + DECL_VISIBILITY (fn) = DECL_VISIBILITY (var); + DECL_VISIBILITY_SPECIFIED (fn) = DECL_VISIBILITY_SPECIFIED (var); + DECL_DLLIMPORT_P (fn) = DECL_DLLIMPORT_P (var); + DECL_IGNORED_P (fn) = 1; + mark_used (fn); + + DECL_BEFRIENDING_CLASSES (fn) = var; + + SET_IDENTIFIER_GLOBAL_VALUE (sname, fn); + } + return fn; +} + +/* Get a FUNCTION_DECL for the init wrapper function for the thread_local + variable VAR. The wrapper function calls the init function (if any) for + VAR and then returns a reference to VAR. The wrapper function is used + in place of VAR everywhere VAR is mentioned. */ + +tree +get_tls_wrapper_fn (tree var) +{ + /* Only C++11 TLS vars need this wrapper fn. */ + if (!var_needs_tls_wrapper (var)) + return NULL_TREE; + + tree sname = mangle_tls_wrapper_fn (var); + tree fn = IDENTIFIER_GLOBAL_VALUE (sname); + if (!fn) + { + /* A named rvalue reference is an lvalue, so the wrapper should + always return an lvalue reference. */ + tree type = non_reference (TREE_TYPE (var)); + type = build_reference_type (type); + tree fntype = build_function_type (type, void_list_node); + fn = build_lang_decl (FUNCTION_DECL, sname, fntype); + SET_DECL_LANGUAGE (fn, lang_c); + TREE_PUBLIC (fn) = TREE_PUBLIC (var); + DECL_ARTIFICIAL (fn) = true; + DECL_IGNORED_P (fn) = 1; + /* The wrapper is inline and emitted everywhere var is used. */ + DECL_DECLARED_INLINE_P (fn) = true; + if (TREE_PUBLIC (var)) + { + comdat_linkage (fn); +#ifdef HAVE_GAS_HIDDEN + /* Make the wrapper bind locally; there's no reason to share + the wrapper between multiple shared objects. */ + DECL_VISIBILITY (fn) = VISIBILITY_INTERNAL; + DECL_VISIBILITY_SPECIFIED (fn) = true; +#endif + } + if (!TREE_PUBLIC (fn)) + DECL_INTERFACE_KNOWN (fn) = true; + mark_used (fn); + note_vague_linkage_fn (fn); + +#if 0 + /* We want CSE to commonize calls to the wrapper, but marking it as + pure is unsafe since it has side-effects. I guess we need a new + ECF flag even weaker than ECF_PURE. FIXME! */ + DECL_PURE_P (fn) = true; +#endif + + DECL_BEFRIENDING_CLASSES (fn) = var; + + SET_IDENTIFIER_GLOBAL_VALUE (sname, fn); + } + return fn; +} + +/* At EOF, generate the definition for the TLS wrapper function FN: + + T& var_wrapper() { + if (init_fn) init_fn(); + return var; + } */ + +static void +generate_tls_wrapper (tree fn) +{ + tree var = DECL_BEFRIENDING_CLASSES (fn); + + start_preparsed_function (fn, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED); + tree body = begin_function_body (); + /* Only call the init fn if there might be one. */ + if (tree init_fn = get_tls_init_fn (var)) + { + tree if_stmt = NULL_TREE; + /* If init_fn is a weakref, make sure it exists before calling. */ + if (lookup_attribute ("weak", DECL_ATTRIBUTES (init_fn))) + { + if_stmt = begin_if_stmt (); + tree addr = cp_build_addr_expr (init_fn, tf_warning_or_error); + tree cond = cp_build_binary_op (DECL_SOURCE_LOCATION (var), + NE_EXPR, addr, nullptr_node, + tf_warning_or_error); + finish_if_stmt_cond (cond, if_stmt); + } + finish_expr_stmt (build_cxx_call + (init_fn, 0, NULL, tf_warning_or_error)); + if (if_stmt) + { + finish_then_clause (if_stmt); + finish_if_stmt (if_stmt); + } + } + finish_return_stmt (convert_from_reference (var)); + finish_function_body (body); + expand_or_defer_fn (finish_function (0)); +} + /* Start the process of running a particular set of global constructors or destructors. Subroutine of do_[cd]tors. */ @@ -3667,6 +3849,75 @@ clear_decl_external (struct cgraph_node *node, void * /*data*/) return false; } +/* Build up the function to run dynamic initializers for thread_local + variables in this translation unit and alias the init functions for the + individual variables to it. */ + +static void +handle_tls_init (void) +{ + tree vars = prune_vars_needing_no_initialization (&tls_aggregates); + if (vars == NULL_TREE) + return; + + location_t loc = DECL_SOURCE_LOCATION (TREE_VALUE (vars)); + + #ifndef ASM_OUTPUT_DEF + /* This currently requires alias support. FIXME other targets could use + small thunks instead of aliases. */ + input_location = loc; + sorry ("dynamic initialization of non-function-local thread_local " + "variables not supported on this target"); + return; + #endif + + write_out_vars (vars); + + tree guard = build_decl (loc, VAR_DECL, get_identifier ("__tls_guard"), + boolean_type_node); + TREE_PUBLIC (guard) = false; + TREE_STATIC (guard) = true; + DECL_ARTIFICIAL (guard) = true; + DECL_IGNORED_P (guard) = true; + TREE_USED (guard) = true; + DECL_TLS_MODEL (guard) = decl_default_tls_model (guard); + pushdecl_top_level_and_finish (guard, NULL_TREE); + + tree fn = build_lang_decl (FUNCTION_DECL, + get_identifier ("__tls_init"), + build_function_type (void_type_node, + void_list_node)); + SET_DECL_LANGUAGE (fn, lang_c); + TREE_PUBLIC (fn) = false; + DECL_ARTIFICIAL (fn) = true; + mark_used (fn); + start_preparsed_function (fn, NULL_TREE, SF_PRE_PARSED); + tree body = begin_function_body (); + tree if_stmt = begin_if_stmt (); + tree cond = cp_build_unary_op (TRUTH_NOT_EXPR, guard, false, + tf_warning_or_error); + finish_if_stmt_cond (cond, if_stmt); + finish_expr_stmt (cp_build_modify_expr (guard, NOP_EXPR, boolean_true_node, + tf_warning_or_error)); + for (; vars; vars = TREE_CHAIN (vars)) + { + tree var = TREE_VALUE (vars); + tree init = TREE_PURPOSE (vars); + one_static_initialization_or_destruction (var, init, true); + + tree single_init_fn = get_tls_init_fn (var); + cgraph_node *alias + = cgraph_same_body_alias (cgraph_get_create_node (fn), + single_init_fn, fn); + gcc_assert (alias != NULL); + } + + finish_then_clause (if_stmt); + finish_if_stmt (if_stmt); + finish_function_body (body); + expand_or_defer_fn (finish_function (0)); +} + /* This routine is called at the end of compilation. Its job is to create all the code needed to initialize and destroy the global aggregates. We do the destruction @@ -3844,6 +4095,9 @@ cp_write_global_declarations (void) /* ??? was: locus.line++; */ } + /* Now do the same for thread_local variables. */ + handle_tls_init (); + /* Go through the set of inline functions whose bodies have not been emitted yet. If out-of-line copies of these functions are required, emit them. */ @@ -3868,6 +4122,9 @@ cp_write_global_declarations (void) reconsider = true; } + if (!DECL_INITIAL (decl) && decl_tls_wrapper_p (decl)) + generate_tls_wrapper (decl); + if (!DECL_SAVED_TREE (decl)) continue; diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index eee44a1bae2..f448932e6ea 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -3684,23 +3684,70 @@ mangle_conv_op_name_for_type (const tree type) return identifier; } -/* Return an identifier for the name of an initialization guard - variable for indicated VARIABLE. */ +/* Write out the appropriate string for this variable when generating + another mangled name based on this one. */ -tree -mangle_guard_variable (const tree variable) +static void +write_guarded_var_name (const tree variable) { - start_mangling (variable); - write_string ("_ZGV"); if (strncmp (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR", 4) == 0) /* The name of a guard variable for a reference temporary should refer to the reference, not the temporary. */ write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4); else write_name (variable, /*ignore_local_scope=*/0); +} + +/* Return an identifier for the name of an initialization guard + variable for indicated VARIABLE. */ + +tree +mangle_guard_variable (const tree variable) +{ + start_mangling (variable); + write_string ("_ZGV"); + write_guarded_var_name (variable); + return finish_mangling_get_identifier (/*warn=*/false); +} + +/* Return an identifier for the name of a thread_local initialization + function for VARIABLE. */ + +tree +mangle_tls_init_fn (const tree variable) +{ + start_mangling (variable); + write_string ("_ZTH"); + write_guarded_var_name (variable); + return finish_mangling_get_identifier (/*warn=*/false); +} + +/* Return an identifier for the name of a thread_local wrapper + function for VARIABLE. */ + +#define TLS_WRAPPER_PREFIX "_ZTW" + +tree +mangle_tls_wrapper_fn (const tree variable) +{ + start_mangling (variable); + write_string (TLS_WRAPPER_PREFIX); + write_guarded_var_name (variable); return finish_mangling_get_identifier (/*warn=*/false); } +/* Return true iff FN is a thread_local wrapper function. */ + +bool +decl_tls_wrapper_p (const tree fn) +{ + if (TREE_CODE (fn) != FUNCTION_DECL) + return false; + tree name = DECL_NAME (fn); + return strncmp (IDENTIFIER_POINTER (name), TLS_WRAPPER_PREFIX, + strlen (TLS_WRAPPER_PREFIX)) == 0; +} + /* Return an identifier for the name of a temporary variable used to initialize a static reference. This isn't part of the ABI, but we might as well call them something readable. */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 07f76e39ec6..e2b355a246f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -2248,12 +2248,12 @@ static tree cp_parser_trait_expr static bool cp_parser_declares_only_class_p (cp_parser *); static void cp_parser_set_storage_class - (cp_parser *, cp_decl_specifier_seq *, enum rid, location_t); + (cp_parser *, cp_decl_specifier_seq *, enum rid, cp_token *); static void cp_parser_set_decl_spec_type - (cp_decl_specifier_seq *, tree, location_t, bool); + (cp_decl_specifier_seq *, tree, cp_token *, bool); static void set_and_check_decl_spec_loc (cp_decl_specifier_seq *decl_specs, - cp_decl_spec ds, source_location location); + cp_decl_spec ds, cp_token *); static bool cp_parser_friend_p (const cp_decl_specifier_seq *); static void cp_parser_required_error @@ -7472,6 +7472,8 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p, rhs, rhs_type, &overload, tf_warning_or_error); current.lhs_type = current.tree_type; + if (EXPR_P (current.lhs)) + SET_EXPR_LOCATION (current.lhs, current.loc); /* If the binary operator required the use of an overloaded operator, then this expression cannot be an integral constant-expression. @@ -10821,7 +10823,7 @@ cp_parser_decl_specifier_seq (cp_parser* parser, /* Set the storage class anyway. */ cp_parser_set_storage_class (parser, decl_specs, RID_AUTO, - token->location); + token); } else /* C++0x auto type-specifier. */ @@ -10835,7 +10837,7 @@ cp_parser_decl_specifier_seq (cp_parser* parser, /* Consume the token. */ cp_lexer_consume_token (parser->lexer); cp_parser_set_storage_class (parser, decl_specs, token->keyword, - token->location); + token); break; case RID_THREAD: /* Consume the token. */ @@ -10855,7 +10857,7 @@ cp_parser_decl_specifier_seq (cp_parser* parser, error ("decl-specifier invalid in condition"); if (ds != ds_last) - set_and_check_decl_spec_loc (decl_specs, ds, token->location); + set_and_check_decl_spec_loc (decl_specs, ds, token); /* Constructors are a special case. The `S' in `S()' is not a decl-specifier; it is the beginning of the declarator. */ @@ -11004,7 +11006,7 @@ cp_parser_function_specifier_opt (cp_parser* parser, switch (token->keyword) { case RID_INLINE: - set_and_check_decl_spec_loc (decl_specs, ds_inline, token->location); + set_and_check_decl_spec_loc (decl_specs, ds_inline, token); break; case RID_VIRTUAL: @@ -11013,11 +11015,11 @@ cp_parser_function_specifier_opt (cp_parser* parser, A member function template shall not be virtual. */ if (PROCESSING_REAL_TEMPLATE_DECL_P ()) error_at (token->location, "templates may not be %<virtual%>"); - set_and_check_decl_spec_loc (decl_specs, ds_virtual, token->location); + set_and_check_decl_spec_loc (decl_specs, ds_virtual, token); break; case RID_EXPLICIT: - set_and_check_decl_spec_loc (decl_specs, ds_explicit, token->location); + set_and_check_decl_spec_loc (decl_specs, ds_explicit, token); break; default: @@ -13525,7 +13527,7 @@ cp_parser_type_specifier (cp_parser* parser, if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type_spec, - token->location, + token, /*type_definition_p=*/true); return type_spec; } @@ -13554,7 +13556,7 @@ cp_parser_type_specifier (cp_parser* parser, if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type_spec, - token->location, + token, /*type_definition_p=*/true); return type_spec; } @@ -13576,7 +13578,7 @@ cp_parser_type_specifier (cp_parser* parser, if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type_spec, - token->location, + token, /*type_definition_p=*/false); return type_spec; @@ -13612,7 +13614,7 @@ cp_parser_type_specifier (cp_parser* parser, { if (decl_specs) { - set_and_check_decl_spec_loc (decl_specs, ds, token->location); + set_and_check_decl_spec_loc (decl_specs, ds, token); decl_specs->any_specifiers_p = true; } return cp_lexer_consume_token (parser->lexer)->u.value; @@ -13703,7 +13705,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, type = boolean_type_node; break; case RID_SHORT: - set_and_check_decl_spec_loc (decl_specs, ds_short, token->location); + set_and_check_decl_spec_loc (decl_specs, ds_short, token); type = short_integer_type_node; break; case RID_INT: @@ -13720,15 +13722,15 @@ cp_parser_simple_type_specifier (cp_parser* parser, break; case RID_LONG: if (decl_specs) - set_and_check_decl_spec_loc (decl_specs, ds_long, token->location); + set_and_check_decl_spec_loc (decl_specs, ds_long, token); type = long_integer_type_node; break; case RID_SIGNED: - set_and_check_decl_spec_loc (decl_specs, ds_signed, token->location); + set_and_check_decl_spec_loc (decl_specs, ds_signed, token); type = integer_type_node; break; case RID_UNSIGNED: - set_and_check_decl_spec_loc (decl_specs, ds_unsigned, token->location); + set_and_check_decl_spec_loc (decl_specs, ds_unsigned, token); type = unsigned_type_node; break; case RID_FLOAT: @@ -13766,7 +13768,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, - token->location, + token, /*type_definition_p=*/false); return type; @@ -13775,7 +13777,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, type = cp_parser_trait_expr (parser, RID_UNDERLYING_TYPE); if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, - token->location, + token, /*type_definition_p=*/false); return type; @@ -13785,7 +13787,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, type = cp_parser_trait_expr (parser, token->keyword); if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, - token->location, + token, /*type_definition_p=*/false); return type; default: @@ -13800,7 +13802,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, type = token->u.value; if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, - token->location, + token, /*type_definition_p=*/false); cp_lexer_consume_token (parser->lexer); return type; @@ -13817,7 +13819,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, && token->keyword != RID_LONG)) cp_parser_set_decl_spec_type (decl_specs, type, - token->location, + token, /*type_definition_p=*/false); if (decl_specs) decl_specs->any_specifiers_p = true; @@ -13894,7 +13896,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, type = NULL_TREE; if (type && decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, - token->location, + token, /*type_definition_p=*/false); } @@ -15245,21 +15247,24 @@ static tree cp_parser_alias_declaration (cp_parser* parser) { tree id, type, decl, pushed_scope = NULL_TREE, attributes; - location_t id_location, using_location, attrs_location = 0; + location_t id_location; cp_declarator *declarator; cp_decl_specifier_seq decl_specs; bool member_p; const char *saved_message = NULL; /* Look for the `using' keyword. */ - using_location = cp_lexer_peek_token (parser->lexer)->location; - cp_parser_require_keyword (parser, RID_USING, RT_USING); + cp_token *using_token + = cp_parser_require_keyword (parser, RID_USING, RT_USING); + if (using_token == NULL) + return error_mark_node; + id_location = cp_lexer_peek_token (parser->lexer)->location; id = cp_parser_identifier (parser); if (id == error_mark_node) return error_mark_node; - attrs_location = cp_lexer_peek_token (parser->lexer)->location; + cp_token *attrs_token = cp_lexer_peek_token (parser->lexer); attributes = cp_parser_attributes_opt (parser); if (attributes == error_mark_node) return error_mark_node; @@ -15316,14 +15321,14 @@ cp_parser_alias_declaration (cp_parser* parser) decl_specs.attributes = attributes; set_and_check_decl_spec_loc (&decl_specs, ds_attribute, - attrs_location); + attrs_token); } set_and_check_decl_spec_loc (&decl_specs, ds_typedef, - using_location); + using_token); set_and_check_decl_spec_loc (&decl_specs, ds_alias, - using_location); + using_token); declarator = make_id_declarator (NULL_TREE, id, sfk_none); declarator->id_loc = id_location; @@ -22585,13 +22590,13 @@ static void cp_parser_set_storage_class (cp_parser *parser, cp_decl_specifier_seq *decl_specs, enum rid keyword, - location_t location) + cp_token *token) { cp_storage_class storage_class; if (parser->in_unbraced_linkage_specification_p) { - error_at (location, "invalid use of %qD in linkage specification", + error_at (token->location, "invalid use of %qD in linkage specification", ridpointers[keyword]); return; } @@ -22602,11 +22607,11 @@ cp_parser_set_storage_class (cp_parser *parser, } if ((keyword == RID_EXTERN || keyword == RID_STATIC) - && decl_spec_seq_has_spec_p (decl_specs, ds_thread)) + && decl_spec_seq_has_spec_p (decl_specs, ds_thread) + && decl_specs->gnu_thread_keyword_p) { - error_at (decl_specs->locations[ds_thread], + pedwarn (decl_specs->locations[ds_thread], 0, "%<__thread%> before %qD", ridpointers[keyword]); - decl_specs->locations[ds_thread] = 0; } switch (keyword) @@ -22630,7 +22635,7 @@ cp_parser_set_storage_class (cp_parser *parser, gcc_unreachable (); } decl_specs->storage_class = storage_class; - set_and_check_decl_spec_loc (decl_specs, ds_storage_class, location); + set_and_check_decl_spec_loc (decl_specs, ds_storage_class, token); /* A storage class specifier cannot be applied alongside a typedef specifier. If there is a typedef specifier present then set @@ -22646,7 +22651,7 @@ cp_parser_set_storage_class (cp_parser *parser, static void cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs, tree type_spec, - location_t location, + cp_token *token, bool type_definition_p) { decl_specs->any_specifiers_p = true; @@ -22671,12 +22676,12 @@ cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs, decl_specs->redefined_builtin_type = type_spec; set_and_check_decl_spec_loc (decl_specs, ds_redefined_builtin_type_spec, - location); + token); if (!decl_specs->type) { decl_specs->type = type_spec; decl_specs->type_definition_p = false; - set_and_check_decl_spec_loc (decl_specs,ds_type_spec, location); + set_and_check_decl_spec_loc (decl_specs,ds_type_spec, token); } } else if (decl_specs->type) @@ -22686,10 +22691,19 @@ cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs, decl_specs->type = type_spec; decl_specs->type_definition_p = type_definition_p; decl_specs->redefined_builtin_type = NULL_TREE; - set_and_check_decl_spec_loc (decl_specs, ds_type_spec, location); + set_and_check_decl_spec_loc (decl_specs, ds_type_spec, token); } } +/* True iff TOKEN is the GNU keyword __thread. */ + +static bool +token_is__thread (cp_token *token) +{ + gcc_assert (token->keyword == RID_THREAD); + return !strcmp (IDENTIFIER_POINTER (token->u.value), "__thread"); +} + /* Set the location for a declarator specifier and check if it is duplicated. @@ -22704,15 +22718,21 @@ cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs, static void set_and_check_decl_spec_loc (cp_decl_specifier_seq *decl_specs, - cp_decl_spec ds, source_location location) + cp_decl_spec ds, cp_token *token) { gcc_assert (ds < ds_last); if (decl_specs == NULL) return; + source_location location = token->location; + if (decl_specs->locations[ds] == 0) - decl_specs->locations[ds] = location; + { + decl_specs->locations[ds] = location; + if (ds == ds_thread) + decl_specs->gnu_thread_keyword_p = token_is__thread (token); + } else { if (ds == ds_long) @@ -22728,6 +22748,15 @@ set_and_check_decl_spec_loc (cp_decl_specifier_seq *decl_specs, "ISO C++ 1998 does not support %<long long%>"); } } + else if (ds == ds_thread) + { + bool gnu = token_is__thread (token); + if (gnu != decl_specs->gnu_thread_keyword_p) + error_at (location, + "both %<__thread%> and %<thread_local%> specified"); + else + error_at (location, "duplicate %qD", token->u.value); + } else { static const char *const decl_spec_names[] = { @@ -22745,8 +22774,7 @@ set_and_check_decl_spec_loc (cp_decl_specifier_seq *decl_specs, "typedef", "using", "constexpr", - "__complex", - "__thread" + "__complex" }; error_at (location, "duplicate %qs", decl_spec_names[ds]); @@ -24587,7 +24615,7 @@ cp_parser_objc_class_ivars (cp_parser* parser) declspecs.storage_class = sc_none; } - /* __thread. */ + /* thread_local. */ if (decl_spec_seq_has_spec_p (&declspecs, ds_thread)) { cp_parser_error (parser, "invalid type for instance variable"); @@ -25166,7 +25194,7 @@ cp_parser_objc_struct_declaration (cp_parser *parser) declspecs.storage_class = sc_none; } - /* __thread. */ + /* thread_local. */ if (decl_spec_seq_has_spec_p (&declspecs, ds_thread)) { cp_parser_error (parser, "invalid type for property"); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 7174927094c..4beed0073fb 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "target.h" #include "gimple.h" #include "bitmap.h" +#include "hash-table.h" /* There routines provide a modular interface to perform many parsing operations. They may therefore be used during actual parsing, or @@ -3270,7 +3271,17 @@ finish_id_expression (tree id_expression, *non_integral_constant_expression_p = true; } - if (scope) + tree wrap; + if (TREE_CODE (decl) == VAR_DECL + && !cp_unevaluated_operand + && DECL_THREAD_LOCAL_P (decl) + && (wrap = get_tls_wrapper_fn (decl))) + { + /* Replace an evaluated use of the thread_local variable with + a call to its wrapper. */ + decl = build_cxx_call (wrap, 0, NULL, tf_warning_or_error); + } + else if (scope) { decl = (adjust_result_of_qualified_name_lookup (decl, scope, current_nonlambda_class_type())); @@ -3827,7 +3838,7 @@ struct nrv_data { tree var; tree result; - htab_t visited; + hash_table <pointer_hash <tree_node> > visited; }; /* Helper function for walk_tree, used by finalize_nrv below. */ @@ -3836,7 +3847,7 @@ static tree finalize_nrv_r (tree* tp, int* walk_subtrees, void* data) { struct nrv_data *dp = (struct nrv_data *)data; - void **slot; + tree_node **slot; /* No need to walk into types. There wouldn't be any need to walk into non-statements, except that we have to consider STMT_EXPRs. */ @@ -3875,7 +3886,7 @@ finalize_nrv_r (tree* tp, int* walk_subtrees, void* data) /* Avoid walking into the same tree more than once. Unfortunately, we can't just use walk_tree_without duplicates because it would only call us for the first occurrence of dp->var in the function body. */ - slot = htab_find_slot (dp->visited, *tp, INSERT); + slot = dp->visited.find_slot (*tp, INSERT); if (*slot) *walk_subtrees = 0; else @@ -3907,9 +3918,9 @@ finalize_nrv (tree *tp, tree var, tree result) data.var = var; data.result = result; - data.visited = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL); + data.visited.create (37); cp_walk_tree (tp, finalize_nrv_r, &data, 0); - htab_delete (data.visited); + data.visited.dispose (); } /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */ diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index e1af378645a..a41337c2116 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -34,6 +34,7 @@ along with GCC; see the file COPYING3. If not see #include "cgraph.h" #include "splay-tree.h" #include "gimple.h" /* gimple_has_body_p */ +#include "hash-table.h" static tree bot_manip (tree *, int *, void *); static tree bot_replace (tree *, int *, void *); @@ -1918,17 +1919,18 @@ static tree verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data) { tree t = *tp; - htab_t *statements = (htab_t *) data; - void **slot; + hash_table <pointer_hash <tree_node> > *statements + = static_cast <hash_table <pointer_hash <tree_node> > *> (data); + tree_node **slot; if (!STATEMENT_CODE_P (TREE_CODE (t))) return NULL_TREE; /* If this statement is already present in the hash table, then there is a circularity in the statement tree. */ - gcc_assert (!htab_find (*statements, t)); + gcc_assert (!statements->find (t)); - slot = htab_find_slot (*statements, t, INSERT); + slot = statements->find_slot (t, INSERT); *slot = t; return NULL_TREE; @@ -1941,10 +1943,10 @@ verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data) void verify_stmt_tree (tree t) { - htab_t statements; - statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL); + hash_table <pointer_hash <tree_node> > statements; + statements.create (37); cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL); - htab_delete (statements); + statements.dispose (); } /* Check if the type T depends on a type with no linkage and if so, return @@ -2559,6 +2561,7 @@ cp_tree_equal (tree t1, tree t2) case VAR_DECL: case CONST_DECL: + case FIELD_DECL: case FUNCTION_DECL: case TEMPLATE_DECL: case IDENTIFIER_NODE: diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index ae4d0a44589..13e75ab9ebf 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -3680,7 +3680,8 @@ build_x_binary_op (location_t loc, enum tree_code code, tree arg1, && !error_operand_p (arg2) && (code != LSHIFT_EXPR || !CLASS_TYPE_P (TREE_TYPE (arg1)))) - warn_about_parentheses (code, arg1_code, orig_arg1, arg2_code, orig_arg2); + warn_about_parentheses (loc, code, arg1_code, orig_arg1, + arg2_code, orig_arg2); if (processing_template_decl && expr != error_mark_node) return build_min_non_dep (code, expr, orig_arg1, orig_arg2); @@ -3912,6 +3913,40 @@ cp_build_binary_op (location_t location, warning_at (loc, OPT_Wpointer_arith, "NULL used in arithmetic"); } + /* In case when one of the operands of the binary operation is + a vector and another is a scalar -- convert scalar to vector. */ + if ((code0 == VECTOR_TYPE) != (code1 == VECTOR_TYPE)) + { + enum stv_conv convert_flag = scalar_to_vector (location, code, op0, op1, + complain & tf_error); + + switch (convert_flag) + { + case stv_error: + return error_mark_node; + case stv_firstarg: + { + op0 = convert (TREE_TYPE (type1), op0); + op0 = build_vector_from_val (type1, op0); + type0 = TREE_TYPE (op0); + code0 = TREE_CODE (type0); + converted = 1; + break; + } + case stv_secondarg: + { + op1 = convert (TREE_TYPE (type0), op1); + op1 = build_vector_from_val (type0, op1); + type1 = TREE_TYPE (op1); + code1 = TREE_CODE (type1); + converted = 1; + break; + } + default: + break; + } + } + switch (code) { case MINUS_EXPR: @@ -4035,7 +4070,13 @@ cp_build_binary_op (location_t location, Also set SHORT_SHIFT if shifting rightward. */ case RSHIFT_EXPR: - if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE + if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE + && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE) + { + result_type = type0; + converted = 1; + } + else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE && TYPE_VECTOR_SUBPARTS (type0) == TYPE_VECTOR_SUBPARTS (type1)) @@ -4072,7 +4113,13 @@ cp_build_binary_op (location_t location, break; case LSHIFT_EXPR: - if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE + if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE + && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE) + { + result_type = type0; + converted = 1; + } + else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE && TYPE_VECTOR_SUBPARTS (type0) == TYPE_VECTOR_SUBPARTS (type1)) |