Change staticp return type to tree

Richard Henderson rth@redhat.com
Fri Aug 27 01:05:00 GMT 2004


For a patch I'm working on, I need the object for which staticp
returned true.  So I've split this patch out first.


r~


        * tree.c (staticp): Return the static object. 
        * tree.h (staticp): Update decl.
        * langhooks.h (struct lang_hooks): Change staticp return type to tree.
        * langhooks.c (lhd_staticp): Return NULL_TREE.
        * langhooks-def.h (lhd_staticp): Update decl.
        * c-common.c (c_staticp): Return the static object.
        * c-common.h (c_staticp): Update decl.

Index: gcc/c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.559
diff -c -p -d -r1.559 c-common.c
*** gcc/c-common.c	26 Aug 2004 00:24:32 -0000	1.559
--- gcc/c-common.c	27 Aug 2004 00:24:42 -0000
*************** c_expand_expr (tree exp, rtx target, enu
*** 3828,3840 ****
  
  /* Hook used by staticp to handle language-specific tree codes.  */
  
! bool
  c_staticp (tree exp)
  {
!   if (TREE_CODE (exp) == COMPOUND_LITERAL_EXPR
!       && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp)))
!     return true;
!   return false;
  }
  
  
--- 3828,3839 ----
  
  /* Hook used by staticp to handle language-specific tree codes.  */
  
! tree
  c_staticp (tree exp)
  {
!   return (TREE_CODE (exp) == COMPOUND_LITERAL_EXPR
! 	  && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp))
! 	  ? exp : NULL);
  }
  
  
Index: gcc/c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.256
diff -c -p -d -r1.256 c-common.h
*** gcc/c-common.h	12 Aug 2004 04:09:53 -0000	1.256
--- gcc/c-common.h	27 Aug 2004 00:24:42 -0000
*************** extern int vector_types_convertible_p (t
*** 840,846 ****
  
  extern rtx c_expand_expr (tree, rtx, enum machine_mode, int, rtx *);
  
! extern bool c_staticp (tree);
  
  extern int c_common_unsafe_for_reeval (tree);
  
--- 840,846 ----
  
  extern rtx c_expand_expr (tree, rtx, enum machine_mode, int, rtx *);
  
! extern tree c_staticp (tree);
  
  extern int c_common_unsafe_for_reeval (tree);
  
Index: gcc/langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.91
diff -c -p -d -r1.91 langhooks-def.h
*** gcc/langhooks-def.h	19 Aug 2004 21:34:23 -0000	1.91
--- gcc/langhooks-def.h	27 Aug 2004 00:24:42 -0000
*************** extern tree lhd_return_null_tree_v (void
*** 50,56 ****
  extern tree lhd_return_null_tree (tree);
  extern tree lhd_do_nothing_iii_return_null_tree (int, int, int);
  extern int lhd_safe_from_p (rtx, tree);
! extern bool lhd_staticp (tree);
  extern void lhd_print_tree_nothing (FILE *, tree, int);
  extern const char *lhd_decl_printable_name (tree, int);
  extern int lhd_types_compatible_p (tree, tree);
--- 50,56 ----
  extern tree lhd_return_null_tree (tree);
  extern tree lhd_do_nothing_iii_return_null_tree (int, int, int);
  extern int lhd_safe_from_p (rtx, tree);
! extern tree lhd_staticp (tree);
  extern void lhd_print_tree_nothing (FILE *, tree, int);
  extern const char *lhd_decl_printable_name (tree, int);
  extern int lhd_types_compatible_p (tree, tree);
Index: gcc/langhooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.c,v
retrieving revision 1.71
diff -c -p -d -r1.71 langhooks.c
*** gcc/langhooks.c	28 Jul 2004 23:44:45 -0000	1.71
--- gcc/langhooks.c	27 Aug 2004 00:24:42 -0000
*************** lhd_safe_from_p (rtx ARG_UNUSED (x), tre
*** 125,134 ****
  
  /* Called from staticp.  */
  
! bool
  lhd_staticp (tree ARG_UNUSED (exp))
  {
!   return false;
  }
  
  /* Called from check_global_declarations.  */
--- 125,134 ----
  
  /* Called from staticp.  */
  
! tree
  lhd_staticp (tree ARG_UNUSED (exp))
  {
!   return NULL;
  }
  
  /* Called from check_global_declarations.  */
Index: gcc/langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.98
diff -c -p -d -r1.98 langhooks.h
*** gcc/langhooks.h	19 Aug 2004 21:34:23 -0000	1.98
--- gcc/langhooks.h	27 Aug 2004 00:24:42 -0000
*************** struct lang_hooks
*** 299,305 ****
    bool (*mark_addressable) (tree);
  
    /* Hook called by staticp for language-specific tree codes.  */
!   bool (*staticp) (tree);
  
    /* Replace the DECL_LANG_SPECIFIC data, which may be NULL, of the
       DECL_NODE with a newly GC-allocated copy.  */
--- 299,305 ----
    bool (*mark_addressable) (tree);
  
    /* Hook called by staticp for language-specific tree codes.  */
!   tree (*staticp) (tree);
  
    /* Replace the DECL_LANG_SPECIFIC data, which may be NULL, of the
       DECL_NODE with a newly GC-allocated copy.  */
Index: gcc/tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.415
diff -c -p -d -r1.415 tree.c
*** gcc/tree.c	25 Aug 2004 09:51:32 -0000	1.415
--- gcc/tree.c	27 Aug 2004 00:24:42 -0000
*************** array_type_nelts (tree type)
*** 1366,1372 ****
  /* Return true if arg is static -- a reference to an object in
     static storage.  This is not the same as the C meaning of `static'.  */
  
! bool
  staticp (tree arg)
  {
    switch (TREE_CODE (arg))
--- 1366,1372 ----
  /* Return true if arg is static -- a reference to an object in
     static storage.  This is not the same as the C meaning of `static'.  */
  
! tree
  staticp (tree arg)
  {
    switch (TREE_CODE (arg))
*************** staticp (tree arg)
*** 1375,1393 ****
        /* Nested functions aren't static, since taking their address
  	 involves a trampoline.  */
        return ((decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg))
! 	      && ! DECL_NON_ADDR_CONST_P (arg));
  
      case VAR_DECL:
        return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
  	      && ! DECL_THREAD_LOCAL (arg)
! 	      && ! DECL_NON_ADDR_CONST_P (arg));
  
      case CONSTRUCTOR:
!       return TREE_STATIC (arg);
  
      case LABEL_DECL:
      case STRING_CST:
!       return true;
  
      case COMPONENT_REF:
        /* If the thing being referenced is not a field, then it is
--- 1375,1395 ----
        /* Nested functions aren't static, since taking their address
  	 involves a trampoline.  */
        return ((decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg))
! 	      && ! DECL_NON_ADDR_CONST_P (arg)
! 	      ? arg : NULL);
  
      case VAR_DECL:
        return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
  	      && ! DECL_THREAD_LOCAL (arg)
! 	      && ! DECL_NON_ADDR_CONST_P (arg)
! 	      ? arg : NULL);
  
      case CONSTRUCTOR:
!       return TREE_STATIC (arg) ? arg : NULL;
  
      case LABEL_DECL:
      case STRING_CST:
!       return arg;
  
      case COMPONENT_REF:
        /* If the thing being referenced is not a field, then it is
*************** staticp (tree arg)
*** 1398,1417 ****
        /* If we are referencing a bitfield, we can't evaluate an
  	 ADDR_EXPR at compile time and so it isn't a constant.  */
        if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
! 	return false;
  
        return staticp (TREE_OPERAND (arg, 0));
  
      case BIT_FIELD_REF:
!       return false;
  
- #if 0
-        /* This case is technically correct, but results in setting
- 	  TREE_CONSTANT on ADDR_EXPRs that cannot be evaluated at
- 	  compile time.  */
      case INDIRECT_REF:
!       return TREE_CONSTANT (TREE_OPERAND (arg, 0));
! #endif
  
      case ARRAY_REF:
      case ARRAY_RANGE_REF:
--- 1400,1414 ----
        /* If we are referencing a bitfield, we can't evaluate an
  	 ADDR_EXPR at compile time and so it isn't a constant.  */
        if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
! 	return NULL;
  
        return staticp (TREE_OPERAND (arg, 0));
  
      case BIT_FIELD_REF:
!       return NULL;
  
      case INDIRECT_REF:
!       return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
  
      case ARRAY_REF:
      case ARRAY_RANGE_REF:
*************** staticp (tree arg)
*** 1426,1432 ****
  	  >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
  	return lang_hooks.staticp (arg);
        else
! 	return false;
      }
  }
  
--- 1423,1429 ----
  	  >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
  	return lang_hooks.staticp (arg);
        else
! 	return NULL;
      }
  }
  
Index: gcc/tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.604
diff -c -p -d -r1.604 tree.h
*** gcc/tree.h	25 Aug 2004 09:51:34 -0000	1.604
--- gcc/tree.h	27 Aug 2004 00:24:43 -0000
*************** extern int integer_pow2p (tree);
*** 3184,3193 ****
  
  extern int integer_nonzerop (tree);
  
! /* staticp (tree x) is true if X is a reference to data allocated
!    at a fixed address in memory.  */
  
! extern bool staticp (tree);
  
  /* save_expr (EXP) returns an expression equivalent to EXP
     but it can be used multiple times within context CTX
--- 3184,3193 ----
  
  extern int integer_nonzerop (tree);
  
! /* staticp (tree x) is nonzero if X is a reference to data allocated
!    at a fixed address in memory.  Returns the outermost data.  */
  
! extern tree staticp (tree);
  
  /* save_expr (EXP) returns an expression equivalent to EXP
     but it can be used multiple times within context CTX



More information about the Gcc-patches mailing list