Re: C++ PATCH to use VAR_P

2015-06-26 Thread Jason Merrill

OK.

Jason


C++ PATCH to use VAR_P

2015-06-26 Thread Marek Polacek
Since Gaby's cleanup in 2013 many uses of TREE_CODE (decl) == VAR_DECL
have crept back in.  This is another cleanup in this area.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2015-06-26  Marek Polacek  pola...@redhat.com

* call.c (set_up_extended_ref_temp): Use VAR_P.
* class.c: Use VAR_P throughout.
* constexpr.c (cxx_eval_constant_expression): Use VAR_P.
* cp-array-notation.c (make_triplet_val_inv): Likewise.
* decl.c: Use VAR_OR_FUNCTION_DECL_P or VAR_P
throughout.
* decl2.c: Likewise.
* error.c (dump_decl): Use VAR_P.
* mangle.c (decl_implicit_alias_p): Likewise.
* parser.c: Use VAR_P throughout.
* pt.c: Likewise.
* semantics.c: Likewise.
* vtable-class-hierarchy.c: Likewise.
* tree.c (handle_abi_tag_attribute): Use VAR_OR_FUNCTION_DECL_P.

diff --git gcc/cp/call.c gcc/cp/call.c
index 0e8840b..e5ed53b 100644
--- gcc/cp/call.c
+++ gcc/cp/call.c
@@ -9697,7 +9697,7 @@ set_up_extended_ref_temp (tree decl, tree expr, vectree, 
va_gc **cleanups,
 }
   /* Avoid -Wunused-variable warning (c++/38958).  */
   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
-   TREE_CODE (decl) == VAR_DECL)
+   VAR_P (decl))
 TREE_USED (decl) = DECL_READ_P (decl) = true;
 
   *initp = init;
diff --git gcc/cp/class.c gcc/cp/class.c
index f4e4f85..6c7fa99 100644
--- gcc/cp/class.c
+++ gcc/cp/class.c
@@ -1399,7 +1399,7 @@ check_tag (tree tag, tree id, tree *tp, abi_tag_data *p)
   p-t, tag, *tp))
inform (location_of (*tp), %qT declared here, *tp);
}
-  else if (TREE_CODE (p-t) == VAR_DECL)
+  else if (VAR_P (p-t))
{
  if (warning (OPT_Wabi_tag, %qD inherits the %E ABI tag 
   that %qT (used in its type) has, p-t, tag, *tp))
@@ -1588,7 +1588,7 @@ check_abi_tags (tree t, tree subob)
 void
 check_abi_tags (tree decl)
 {
-  if (TREE_CODE (decl) == VAR_DECL)
+  if (VAR_P (decl))
 check_abi_tags (decl, TREE_TYPE (decl));
   else if (TREE_CODE (decl) == FUNCTION_DECL
!mangle_return_type_p (decl))
@@ -3040,7 +3040,7 @@ finish_struct_anon_r (tree field, bool complain)
{
  /* We already complained about static data members in
 finish_static_data_member_decl.  */
- if (complain  TREE_CODE (elt) != VAR_DECL)
+ if (complain  !VAR_P (elt))
{
  if (is_union)
permerror (input_location,
diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
index 9cb45ea..4fce5e0 100644
--- gcc/cp/constexpr.c
+++ gcc/cp/constexpr.c
@@ -3033,7 +3033,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, 
tree t,
   if (TREE_CODE (r) == TARGET_EXPR
   TREE_CODE (TARGET_EXPR_INITIAL (r)) == CONSTRUCTOR)
r = TARGET_EXPR_INITIAL (r);
-  if (TREE_CODE (r) == VAR_DECL)
+  if (VAR_P (r))
if (tree *p = ctx-values-get (r))
  r = *p;
   if (DECL_P (r))
diff --git gcc/cp/cp-array-notation.c gcc/cp/cp-array-notation.c
index 3b8610f..4daa57c 100644
--- gcc/cp/cp-array-notation.c
+++ gcc/cp/cp-array-notation.c
@@ -87,7 +87,7 @@ make_triplet_val_inv (tree *value)
 {
   if (TREE_CODE (*value) != INTEGER_CST
TREE_CODE (*value) != PARM_DECL
-   TREE_CODE (*value) != VAR_DECL)
+   !VAR_P (*value))
 *value = get_temp_regvar (ptrdiff_type_node, *value);
 }
 
diff --git gcc/cp/decl.c gcc/cp/decl.c
index 1fa28b2..9594223 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -2476,14 +2476,15 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
newdecl_is_friend)
  {
 struct symtab_node *snode = NULL;
 
-if (TREE_CODE (newdecl) == VAR_DECL
-(TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl) || 
DECL_EXTERNAL (olddecl)))
+   if (VAR_P (newdecl)
+(TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
+   || DECL_EXTERNAL (olddecl)))
  snode = symtab_node::get (olddecl);
memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
(char *) newdecl + sizeof (struct tree_decl_common),
size - sizeof (struct tree_decl_common)
+ TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
-if (TREE_CODE (newdecl) == VAR_DECL)
+   if (VAR_P (newdecl))
  olddecl-decl_with_vis.symtab_node = snode;
  }
  break;
@@ -2496,8 +2497,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
newdecl_is_friend)
}
 }
 
-  if (TREE_CODE (newdecl) == FUNCTION_DECL
-  || TREE_CODE (newdecl) == VAR_DECL)
+  if (VAR_OR_FUNCTION_DECL_P (newdecl))
 {
   if (DECL_EXTERNAL (olddecl)
  || TREE_PUBLIC (olddecl)
@@ -2522,7 +2522,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
newdecl_is_friend)
}
}
 
-  if (TREE_CODE (newdecl) == VAR_DECL
+  if (VAR_P (newdecl)
   

C PATCH to use VAR_P

2015-06-24 Thread Marek Polacek
Similarly to what Gaby did in 2013 for C++
(https://gcc.gnu.org/ml/gcc-patches/2013-03/msg01271.html), this patch
makes the c/ and c-family/ code use VAR_P rather than

  TREE_CODE (t) == VAR_DECL

(This is on top of the previous patch with is_global_var.)

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2015-06-24  Marek Polacek  pola...@redhat.com

* array-notation-common.c: Use VAR_P throughout.
* c-ada-spec.c: Likewise.
* c-common.c: Likewise.
* c-format.c: Likewise.
* c-gimplify.c: Likewise.
* c-omp.c: Likewise.
* c-pragma.c: Likewise.
* c-pretty-print.c: Likewise.
* cilk.c: Likewise.

* c-array-notation.c: Use VAR_P throughout.
* c-decl.c: Likewise.
* c-objc-common.c: Likewise.
* c-parser.c: Likewise.
* c-typeck.c: Likewise.

diff --git gcc/c-family/array-notation-common.c 
gcc/c-family/array-notation-common.c
index d60ec3f..f517424 100644
--- gcc/c-family/array-notation-common.c
+++ gcc/c-family/array-notation-common.c
@@ -231,7 +231,7 @@ find_rank (location_t loc, tree orig_expr, tree expr, bool 
ignore_builtin_fn,
   || TREE_CODE (ii_tree) == INDIRECT_REF)
ii_tree = TREE_OPERAND (ii_tree, 0);
  else if (TREE_CODE (ii_tree) == PARM_DECL
-  || TREE_CODE (ii_tree) == VAR_DECL)
+  || VAR_P (ii_tree))
break;
  else
gcc_unreachable ();
diff --git gcc/c-family/c-ada-spec.c gcc/c-family/c-ada-spec.c
index ab29f86..ef3c5e3 100644
--- gcc/c-family/c-ada-spec.c
+++ gcc/c-family/c-ada-spec.c
@@ -2826,7 +2826,7 @@ print_ada_declaration (pretty_printer *buffer, tree t, 
tree type, int spc)
 }
   else
 {
-  if (TREE_CODE (t) == VAR_DECL
+  if (VAR_P (t)
   decl_name
   *IDENTIFIER_POINTER (decl_name) == '_')
return 0;
diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index d315854..d7ccf0e 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -1620,7 +1620,7 @@ decl_constant_value_for_optimization (tree exp)
 gcc_unreachable ();
 
   if (!optimize
-  || TREE_CODE (exp) != VAR_DECL
+  || !VAR_P (exp)
   || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
   || DECL_MODE (exp) == BLKmode)
 return exp;
@@ -6952,7 +6952,7 @@ handle_nocommon_attribute (tree *node, tree name,
   tree ARG_UNUSED (args),
   int ARG_UNUSED (flags), bool *no_add_attrs)
 {
-  if (TREE_CODE (*node) == VAR_DECL)
+  if (VAR_P (*node))
 DECL_COMMON (*node) = 0;
   else
 {
@@ -6970,7 +6970,7 @@ static tree
 handle_common_attribute (tree *node, tree name, tree ARG_UNUSED (args),
 int ARG_UNUSED (flags), bool *no_add_attrs)
 {
-  if (TREE_CODE (*node) == VAR_DECL)
+  if (VAR_P (*node))
 DECL_COMMON (*node) = 1;
   else
 {
@@ -7349,12 +7349,12 @@ handle_used_attribute (tree *pnode, tree name, tree 
ARG_UNUSED (args),
   tree node = *pnode;
 
   if (TREE_CODE (node) == FUNCTION_DECL
-  || (TREE_CODE (node) == VAR_DECL  TREE_STATIC (node))
+  || (VAR_P (node)  TREE_STATIC (node))
   || (TREE_CODE (node) == TYPE_DECL))
 {
   TREE_USED (node) = 1;
   DECL_PRESERVE_P (node) = 1;
-  if (TREE_CODE (node) == VAR_DECL)
+  if (VAR_P (node))
DECL_READ_P (node) = 1;
 }
   else
@@ -7378,14 +7378,13 @@ handle_unused_attribute (tree *node, tree name, tree 
ARG_UNUSED (args),
   tree decl = *node;
 
   if (TREE_CODE (decl) == PARM_DECL
- || TREE_CODE (decl) == VAR_DECL
+ || VAR_P (decl)
  || TREE_CODE (decl) == FUNCTION_DECL
  || TREE_CODE (decl) == LABEL_DECL
  || TREE_CODE (decl) == TYPE_DECL)
{
  TREE_USED (decl) = 1;
- if (TREE_CODE (decl) == VAR_DECL
- || TREE_CODE (decl) == PARM_DECL)
+ if (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
DECL_READ_P (decl) = 1;
}
   else
@@ -7913,7 +7912,7 @@ handle_section_attribute (tree *node, tree ARG_UNUSED 
(name), tree args,
   goto fail;
 }
 
-  if (TREE_CODE (decl) == VAR_DECL
+  if (VAR_P (decl)
current_function_decl != NULL_TREE
!TREE_STATIC (decl))
 {
@@ -7932,7 +7931,7 @@ handle_section_attribute (tree *node, tree ARG_UNUSED 
(name), tree args,
   goto fail;
 }
 
-  if (TREE_CODE (decl) == VAR_DECL
+  if (VAR_P (decl)
!targetm.have_tls  targetm.emutls.tmpl_section
DECL_THREAD_LOCAL_P (decl))
 {
@@ -8223,7 +8222,7 @@ handle_alias_ifunc_attribute (bool is_alias, tree *node, 
tree name, tree args,
   tree decl = *node;
 
   if (TREE_CODE (decl) != FUNCTION_DECL
-   (!is_alias || TREE_CODE (decl) != VAR_DECL))
+   (!is_alias || !VAR_P (decl)))
 {
   warning (OPT_Wattributes, %qE attribute ignored, name);
   *no_add_attrs = true;
@@ -8518,7 +8517,7 @@ c_determine_visibility (tree decl)
  

Re: C PATCH to use VAR_P

2015-06-24 Thread Uros Bizjak
Hello!

 Similarly to what Gaby did in 2013 for C++
 (https://gcc.gnu.org/ml/gcc-patches/2013-03/msg01271.html), this patch
 makes the c/ and c-family/ code use VAR_P rather than

   TREE_CODE (t) == VAR_DECL

 (This is on top of the previous patch with is_global_var.)

You could also use VAR_OR_FUNCTION_DECL, e.g. in the part below.

Uros.

@@ -7378,14 +7378,13 @@ handle_unused_attribute (tree *node, tree
name, tree ARG_UNUSED (args),
   tree decl = *node;

   if (TREE_CODE (decl) == PARM_DECL
-  || TREE_CODE (decl) == VAR_DECL
+  || VAR_P (decl)
   || TREE_CODE (decl) == FUNCTION_DECL
   || TREE_CODE (decl) == LABEL_DECL
   || TREE_CODE (decl) == TYPE_DECL)


Re: C PATCH to use VAR_P

2015-06-24 Thread Marek Polacek
On Wed, Jun 24, 2015 at 02:37:30PM +0200, Uros Bizjak wrote:
 Hello!
 
  Similarly to what Gaby did in 2013 for C++
  (https://gcc.gnu.org/ml/gcc-patches/2013-03/msg01271.html), this patch
  makes the c/ and c-family/ code use VAR_P rather than
 
TREE_CODE (t) == VAR_DECL
 
  (This is on top of the previous patch with is_global_var.)
 
 You could also use VAR_OR_FUNCTION_DECL, e.g. in the part below.
 
Sure, I thought I had dealt with VAR_OR_FUNCTION_DECL_P in
https://gcc.gnu.org/ml/gcc-patches/2015-05/msg01797.html, but
I must have missed this.  Thanks,


Marek


Re: C PATCH to use VAR_P

2015-06-24 Thread Jeff Law

On 06/24/2015 06:45 AM, Marek Polacek wrote:

On Wed, Jun 24, 2015 at 02:37:30PM +0200, Uros Bizjak wrote:

Hello!


Similarly to what Gaby did in 2013 for C++
(https://gcc.gnu.org/ml/gcc-patches/2013-03/msg01271.html), this patch
makes the c/ and c-family/ code use VAR_P rather than

   TREE_CODE (t) == VAR_DECL

(This is on top of the previous patch with is_global_var.)


You could also use VAR_OR_FUNCTION_DECL, e.g. in the part below.


Sure, I thought I had dealt with VAR_OR_FUNCTION_DECL_P in
https://gcc.gnu.org/ml/gcc-patches/2015-05/msg01797.html, but
I must have missed this.  Thanks,

Consider that follow-up approved as well.
jeff


Re: C PATCH to use VAR_P

2015-06-24 Thread Jeff Law

On 06/24/2015 06:25 AM, Marek Polacek wrote:

Similarly to what Gaby did in 2013 for C++
(https://gcc.gnu.org/ml/gcc-patches/2013-03/msg01271.html), this patch
makes the c/ and c-family/ code use VAR_P rather than

   TREE_CODE (t) == VAR_DECL

(This is on top of the previous patch with is_global_var.)

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2015-06-24  Marek Polacek  pola...@redhat.com

* array-notation-common.c: Use VAR_P throughout.
* c-ada-spec.c: Likewise.
* c-common.c: Likewise.
* c-format.c: Likewise.
* c-gimplify.c: Likewise.
* c-omp.c: Likewise.
* c-pragma.c: Likewise.
* c-pretty-print.c: Likewise.
* cilk.c: Likewise.

* c-array-notation.c: Use VAR_P throughout.
* c-decl.c: Likewise.
* c-objc-common.c: Likewise.
* c-parser.c: Likewise.
* c-typeck.c: Likewise.
I spot checked mostly for VAR_P vs !VAR_P correctness and everything 
looked correct.  OK for the trunk.  Consider any follow-ups to use VAR_P 
in a similar way pre-approved.


jeff