1) I wanted a lang-specific flag for my thread_local work, so I took the one away from __PRETTY_FUNCTION__, which really doesn't need it.

2) I didn't end up wanting to use a flag in DECL_LANG_SPECIFIC, but it
still makes sense to check for appropriate tree codes in DECL_FRIEND_P and DECL_ANTICIPATED.

3) DECL_NONTRIVIALLY_INITIALIZED_P currently means "has a user-written initializer" and it would be more useful to me if it actually meant "has non-trivial initialization" so that a non-trivial default constructor counts even if there is nothing written in the variable declaration. The one existing reader of this flag seems to agree with me.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 6c286ba0a085136d7efecd6d70d0cf96a4e8386a
Author: Jason Merrill <ja...@redhat.com>
Date:   Wed Sep 26 12:14:15 2012 -0400

    	* cp-tree.h (DECL_PRETTY_FUNCTION_P): Just look at the name.
    	* decl.c (cp_make_fname_decl): Adjust.

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 9298e3d..cefe92d 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -45,7 +45,6 @@ never after.
 
 /* Usage of TREE_LANG_FLAG_?:
    0: IDENTIFIER_MARKED (used by search routines).
-      DECL_PRETTY_FUNCTION_P (in VAR_DECL)
       C_MAYBE_CONST_EXPR_INT_OPERANDS (in C_MAYBE_CONST_EXPR, for C)
    1: C_DECLARED_LABEL_FLAG (in LABEL_DECL)
       STATEMENT_LIST_STMT_EXPR (in STATEMENT_LIST)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index f437022..cee8590 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -56,7 +56,6 @@ 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_PRETTY_FUNCTION_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)
@@ -2410,7 +2409,8 @@ struct GTY((variable_size)) lang_decl {
 /* Nonzero if this DECL is the __PRETTY_FUNCTION__ variable in a
    template function.  */
 #define DECL_PRETTY_FUNCTION_P(NODE) \
-  (TREE_LANG_FLAG_0 (VAR_DECL_CHECK (NODE)))
+  (DECL_NAME (NODE) \
+   && !strcmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__PRETTY_FUNCTION__"))
 
 /* The _TYPE context in which this _DECL appears.  This field holds the
    class where a virtual function instance is actually defined.  */
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 078b148..d4c78e1 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -3829,7 +3829,6 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
 
   /* As we're using pushdecl_with_scope, we must set the context.  */
   DECL_CONTEXT (decl) = current_function_decl;
-  DECL_PRETTY_FUNCTION_P (decl) = type_dep;
 
   TREE_STATIC (decl) = 1;
   TREE_READONLY (decl) = 1;
commit 21960ac8d1debe452eef3776fe2d638fa55dbe52
Author: Jason Merrill <ja...@redhat.com>
Date:   Wed Sep 26 12:19:21 2012 -0400

    	* cp-tree.h (TYPE_FUNCTION_OR_TEMPLATE_DECL_CHECK): New.
    	(DECL_FRIEND_P, DECL_ANTICIPATED): Use it.
    	(TYPE_FUNCTION_OR_TEMPLATE_DECL_P): New.
    	* name-lookup.c (hidden_name_p): Use it.

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index cee8590..e4f3761 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -202,6 +202,13 @@ c-common.h, not after.
 #define VAR_OR_FUNCTION_DECL_CHECK(NODE) \
   TREE_CHECK2(NODE,VAR_DECL,FUNCTION_DECL)
 
+#define TYPE_FUNCTION_OR_TEMPLATE_DECL_CHECK(NODE) \
+  TREE_CHECK3(NODE,TYPE_DECL,TEMPLATE_DECL,FUNCTION_DECL)
+
+#define TYPE_FUNCTION_OR_TEMPLATE_DECL_P(NODE) \
+  (TREE_CODE (NODE) == TYPE_DECL || TREE_CODE (NODE) == TEMPLATE_DECL \
+   || TREE_CODE (NODE) == FUNCTION_DECL)
+
 #define VAR_FUNCTION_OR_PARM_DECL_CHECK(NODE) \
   TREE_CHECK3(NODE,VAR_DECL,FUNCTION_DECL,PARM_DECL)
 
@@ -1875,8 +1882,8 @@ struct GTY(()) lang_decl_base {
   unsigned initialized_in_class : 1;	   /* var or fn */
   unsigned repo_available_p : 1;	   /* var or fn */
   unsigned threadprivate_or_deleted_p : 1; /* var or fn */
-  unsigned anticipated_p : 1;		   /* fn or type */
-  unsigned friend_attr : 1;		   /* fn or type */
+  unsigned anticipated_p : 1;		   /* fn, type or template */
+  unsigned friend_attr : 1;		   /* fn, type or template */
   unsigned template_conv_p : 1;		   /* var or template */
   unsigned odr_used : 1;		   /* var or fn */
   unsigned u2sel : 1;
@@ -2293,7 +2300,9 @@ struct GTY((variable_size)) lang_decl {
 
 /* Nonzero for DECL means that this decl is just a friend declaration,
    and should not be added to the list of members for this class.  */
-#define DECL_FRIEND_P(NODE) (DECL_LANG_SPECIFIC (NODE)->u.base.friend_attr)
+#define DECL_FRIEND_P(NODE) \
+  (DECL_LANG_SPECIFIC (TYPE_FUNCTION_OR_TEMPLATE_DECL_CHECK (NODE)) \
+   ->u.base.friend_attr)
 
 /* A TREE_LIST of the types which have befriended this FUNCTION_DECL.  */
 #define DECL_BEFRIENDING_CLASSES(NODE) \
@@ -3101,7 +3110,8 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
    declared inside a class.  In the latter case DECL_HIDDEN_FRIEND_P
    will be set.  */
 #define DECL_ANTICIPATED(NODE) \
-  (DECL_LANG_SPECIFIC (DECL_COMMON_CHECK (NODE))->u.base.anticipated_p)
+  (DECL_LANG_SPECIFIC (TYPE_FUNCTION_OR_TEMPLATE_DECL_CHECK (NODE)) \
+   ->u.base.anticipated_p)
 
 /* Nonzero if NODE is a FUNCTION_DECL which was declared as a friend
    within a class but has not been declared in the surrounding scope.
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index e4e9827..cd328b3 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -4174,6 +4174,7 @@ hidden_name_p (tree val)
 {
   if (DECL_P (val)
       && DECL_LANG_SPECIFIC (val)
+      && TYPE_FUNCTION_OR_TEMPLATE_DECL_P (val)
       && DECL_ANTICIPATED (val))
     return true;
   return false;
commit 2574183057d9bc473146de7e7daad0a393e3da66
Author: Jason Merrill <ja...@redhat.com>
Date:   Mon Oct 1 09:36:09 2012 -0400

    	* decl.c (check_initializer): Set DECL_NONTRIVIALLY_INITIALIZED_P
    	for a constructor call.
    	(decl_jump_unsafe): So don't bother checking
    	type_has_nontrivial_default_init.
    	* call.c (set_up_extended_ref_temp): Set
    	DECL_NONTRIVIALLY_INITIALIZED_P.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 6f7e346..d0492d8 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8792,6 +8792,9 @@ set_up_extended_ref_temp (tree decl, tree expr, VEC(tree,gc) **cleanups,
   TARGET_EXPR_INITIAL (expr)
     = extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups);
 
+  /* Any reference temp has a non-trivial initializer.  */
+  DECL_NONTRIVIALLY_INITIALIZED_P (var) = true;
+
   /* If the initializer is constant, put it in DECL_INITIAL so we get
      static initialization and use in constant expressions.  */
   init = maybe_constant_init (expr);
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index e4f3761..bfe7ad7 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2271,12 +2271,13 @@ struct GTY((variable_size)) lang_decl {
 
 /* Nonzero for a VAR_DECL means that the variable's initialization (if
    any) has been processed.  (In general, DECL_INITIALIZED_P is
-   !DECL_EXTERN, but static data members may be initialized even if
+   !DECL_EXTERNAL, but static data members may be initialized even if
    not defined.)  */
 #define DECL_INITIALIZED_P(NODE) \
    (TREE_LANG_FLAG_1 (VAR_DECL_CHECK (NODE)))
 
-/* Nonzero for a VAR_DECL iff an explicit initializer was provided.  */
+/* Nonzero for a VAR_DECL iff an explicit initializer was provided
+   or a non-trivial constructor is called.  */
 #define DECL_NONTRIVIALLY_INITIALIZED_P(NODE)	\
    (TREE_LANG_FLAG_3 (VAR_DECL_CHECK (NODE)))
 
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d4c78e1..d0933ef 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2679,8 +2679,7 @@ decl_jump_unsafe (tree decl)
 
   type = strip_array_types (type);
 
-  if (type_has_nontrivial_default_init (TREE_TYPE (decl))
-      || DECL_NONTRIVIALLY_INITIALIZED_P (decl))
+  if (DECL_NONTRIVIALLY_INITIALIZED_P (decl))
     return 2;
 
   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
@@ -5581,6 +5580,11 @@ check_initializer (tree decl, tree init, int flags, VEC(tree,gc) **cleanups)
 	{
 	  init_code = build_aggr_init_full_exprs (decl, init, flags);
 
+	  /* A constructor call is a non-trivial initializer even if
+	     it isn't explicitly written.  */
+	  if (TREE_SIDE_EFFECTS (init_code))
+	    DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
+
 	  /* If this is a constexpr initializer, expand_default_init will
 	     have returned an INIT_EXPR rather than a CALL_EXPR.  In that
 	     case, pull the initializer back out and pass it down into

Reply via email to