This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

(C++) patch for g++.brendan/bit-fields2.C


Applied.  We weren't diagnosing taking the address of a bitfield that fits
into one of the integer modes.

1998-10-16  Jason Merrill  <jason@yorick.cygnus.com>

	* cp-tree.h (DECL_C_BIT_FIELD, SET_DECL_C_BIT_FIELD): New macros.
	(struct lang_decl_flags): Add `bitfield'.
	* class.c (finish_struct_1): Use DECL_C_BIT_FIELD instead of
	DECL_BIT_FIELD.
	* decl2.c (grokbitfield, grok_alignof): Likewise.
	* init.c (build_offset_ref): Likewise.
	* typeck.c (build_component_addr, expr_sizeof): Likewise.
	* cvt.c (build_up_reference): Don't crash if taking the address
	returns error_mark_node.

Index: class.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/class.c,v
retrieving revision 1.92
diff -c -p -r1.92 class.c
*** class.c	1998/10/15 11:36:44	1.92
--- class.c	1998/10/16 10:31:21
*************** finish_struct_1 (t, warn_anon)
*** 3541,3552 ****
  	    }
  	}
  
!       /* We set DECL_BIT_FIELD tentatively in grokbitfield.
! 	 If the type and width are valid, we'll keep it set.
! 	 Otherwise, the flag is cleared.  */
!       if (DECL_BIT_FIELD (x))
  	{
- 	  DECL_BIT_FIELD (x) = 0;
  	  /* Invalid bit-field size done by grokfield.  */
  	  /* Detect invalid bit-field type.  */
  	  if (DECL_INITIAL (x)
--- 3541,3550 ----
  	    }
  	}
  
!       /* We set DECL_C_BIT_FIELD in grokbitfield.
! 	 If the type and width are valid, we'll also set DECL_BIT_FIELD.  */
!       if (DECL_C_BIT_FIELD (x))
  	{
  	  /* Invalid bit-field size done by grokfield.  */
  	  /* Detect invalid bit-field type.  */
  	  if (DECL_INITIAL (x)
*************** finish_struct_1 (t, warn_anon)
*** 3844,3856 ****
       C++: maybe we will support default field initialization some day...  */
  
    /* Delete all zero-width bit-fields from the front of the fieldlist */
!   while (fields && DECL_BIT_FIELD (fields)
  	 && DECL_INITIAL (fields))
      fields = TREE_CHAIN (fields);
    /* Delete all such fields from the rest of the fields.  */
    for (x = fields; x;)
      {
!       if (TREE_CHAIN (x) && DECL_BIT_FIELD (TREE_CHAIN (x))
  	  && DECL_INITIAL (TREE_CHAIN (x)))
  	TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
        else
--- 3842,3854 ----
       C++: maybe we will support default field initialization some day...  */
  
    /* Delete all zero-width bit-fields from the front of the fieldlist */
!   while (fields && DECL_C_BIT_FIELD (fields)
  	 && DECL_INITIAL (fields))
      fields = TREE_CHAIN (fields);
    /* Delete all such fields from the rest of the fields.  */
    for (x = fields; x;)
      {
!       if (TREE_CHAIN (x) && DECL_C_BIT_FIELD (TREE_CHAIN (x))
  	  && DECL_INITIAL (TREE_CHAIN (x)))
  	TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
        else
Index: cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.154
diff -c -p -r1.154 cp-tree.h
*** cp-tree.h	1998/10/15 19:43:47	1.154
--- cp-tree.h	1998/10/16 10:31:22
*************** struct lang_decl_flags
*** 1065,1071 ****
    unsigned not_really_extern : 1;
    unsigned comdat : 1;
    unsigned needs_final_overrider : 1;
!   unsigned dummy : 3;
  
    tree access;
    tree context;
--- 1065,1072 ----
    unsigned not_really_extern : 1;
    unsigned comdat : 1;
    unsigned needs_final_overrider : 1;
!   unsigned bitfield : 1;
!   unsigned dummy : 2;
  
    tree access;
    tree context;
*************** extern int flag_new_for_scope;
*** 1397,1402 ****
--- 1398,1409 ----
  
  /* Record whether a typedef for type `int' was actually `signed int'.  */
  #define C_TYPEDEF_EXPLICITLY_SIGNED(exp) DECL_LANG_FLAG_1 ((exp))
+ 
+ /* In a FIELD_DECL, nonzero if the decl was originally a bitfield.  */
+ #define DECL_C_BIT_FIELD(NODE) \
+   (DECL_LANG_SPECIFIC (NODE) && DECL_LANG_SPECIFIC (NODE)->decl_flags.bitfield)
+ #define SET_DECL_C_BIT_FIELD(NODE) \
+   (DECL_LANG_SPECIFIC (NODE)->decl_flags.bitfield = 1)
  
  /* Nonzero if the type T promotes to itself.
     ANSI C states explicitly the list of types that promote;
Index: cvt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cvt.c,v
retrieving revision 1.35
diff -c -p -r1.35 cvt.c
*** cvt.c	1998/10/09 10:32:01	1.35
--- cvt.c	1998/10/16 10:31:22
*************** build_up_reference (type, arg, flags)
*** 377,382 ****
--- 377,385 ----
       address, transform all occurrences of the register, into a memory
       reference we could win better.  */
    rval = build_unary_op (ADDR_EXPR, arg, 1);
+   if (rval == error_mark_node)
+     return error_mark_node;
+ 
    if ((flags & LOOKUP_PROTECT)
        && TYPE_MAIN_VARIANT (argtype) != TYPE_MAIN_VARIANT (target_type)
        && IS_AGGR_TYPE (argtype)
Index: decl2.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl2.c,v
retrieving revision 1.142
diff -c -p -r1.142 decl2.c
*** decl2.c	1998/10/10 09:24:06	1.142
--- decl2.c	1998/10/16 10:31:22
*************** grok_alignof (expr)
*** 1046,1052 ****
      return build_min (ALIGNOF_EXPR, sizetype, expr);
  
    if (TREE_CODE (expr) == COMPONENT_REF
!       && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
      error ("`__alignof__' applied to a bit-field");
  
    if (TREE_CODE (expr) == INDIRECT_REF)
--- 1046,1052 ----
      return build_min (ALIGNOF_EXPR, sizetype, expr);
  
    if (TREE_CODE (expr) == COMPONENT_REF
!       && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
      error ("`__alignof__' applied to a bit-field");
  
    if (TREE_CODE (expr) == INDIRECT_REF)
*************** grokbitfield (declarator, declspecs, wid
*** 1809,1815 ****
      {
        constant_expression_warning (width);
        DECL_INITIAL (value) = width;
!       DECL_BIT_FIELD (value) = 1;
      }
  
    DECL_IN_AGGR_P (value) = 1;
--- 1809,1815 ----
      {
        constant_expression_warning (width);
        DECL_INITIAL (value) = width;
!       SET_DECL_C_BIT_FIELD (value);
      }
  
    DECL_IN_AGGR_P (value) = 1;
Index: init.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/init.c,v
retrieving revision 1.68
diff -c -p -r1.68 init.c
*** init.c	1998/10/06 14:19:58	1.68
--- init.c	1998/10/16 10:31:23
*************** build_offset_ref (type, name)
*** 1686,1692 ****
        return convert_from_reference (t);
      }
  
!   if (TREE_CODE (t) == FIELD_DECL && DECL_BIT_FIELD (t))
      {
        cp_error ("illegal pointer to bit field `%D'", t);
        return error_mark_node;
--- 1686,1692 ----
        return convert_from_reference (t);
      }
  
!   if (TREE_CODE (t) == FIELD_DECL && DECL_C_BIT_FIELD (t))
      {
        cp_error ("illegal pointer to bit field `%D'", t);
        return error_mark_node;
Index: typeck.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/typeck.c,v
retrieving revision 1.115
diff -c -p -r1.115 typeck.c
*** typeck.c	1998/10/08 05:04:57	1.115
--- typeck.c	1998/10/16 10:31:25
*************** expr_sizeof (e)
*** 1538,1544 ****
      return build_min (SIZEOF_EXPR, sizetype, e);
  
    if (TREE_CODE (e) == COMPONENT_REF
!       && DECL_BIT_FIELD (TREE_OPERAND (e, 1)))
      error ("sizeof applied to a bit-field");
    /* ANSI says arrays and functions are converted inside comma.
       But we can't really convert them in build_compound_expr
--- 1538,1544 ----
      return build_min (SIZEOF_EXPR, sizetype, e);
  
    if (TREE_CODE (e) == COMPONENT_REF
!       && DECL_C_BIT_FIELD (TREE_OPERAND (e, 1)))
      error ("sizeof applied to a bit-field");
    /* ANSI says arrays and functions are converted inside comma.
       But we can't really convert them in build_compound_expr
*************** build_component_addr (arg, argtype, msg)
*** 4248,4254 ****
    tree basetype = decl_type_context (field);
    tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  
!   if (DECL_BIT_FIELD (field))
      {
        error (msg, IDENTIFIER_POINTER (DECL_NAME (field)));
        return error_mark_node;
--- 4248,4254 ----
    tree basetype = decl_type_context (field);
    tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  
!   if (DECL_C_BIT_FIELD (field))
      {
        error (msg, IDENTIFIER_POINTER (DECL_NAME (field)));
        return error_mark_node;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]