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]
Other format: [Raw text]

[PATCH] Fixup handling of zero-precision integer types


These two patches try to fix handling of zero-precision integer
types (created by struct { int : 0; };).  Currently they get
assigned TYPE_MIN/MAX_VALUEs but clearly a zero-precision
integer type does not have a single valid value.  Of course
for these nothing should look at TYPE_MIN/MAX_VALUE you'd think ...
Clearly you are wrong.  See the patch below which bootstrapped
and tested on x86_64-unknown-linux-gnu for all languages
in the attempt to apply the 2nd patch (still testing).

Objections?

Thanks,
Richard.


Index: gcc/stor-layout.c
===================================================================
--- gcc/stor-layout.c	(revision 203744)
+++ gcc/stor-layout.c	(working copy)
@@ -2054,7 +2054,7 @@ layout_type (tree type)
 
     case BOOLEAN_TYPE:  /* Used for Java, Pascal, and Chill.  */
       if (TYPE_PRECISION (type) == 0)
-	TYPE_PRECISION (type) = 1; /* default to one byte/boolean.  */
+	gcc_unreachable ();
 
       /* ... fall through ...  */
 
@@ -2062,7 +2062,7 @@ layout_type (tree type)
     case ENUMERAL_TYPE:
       if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
 	  && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
-	TYPE_UNSIGNED (type) = 1;
+	gcc_assert (TYPE_UNSIGNED (type));
 
       SET_TYPE_MODE (type,
 		     smallest_mode_for_size (TYPE_PRECISION (type), MODE_INT));



2013-10-17  Richard Biener  <rguenther@suse.de>

	* stor-layout.c (layout_type): Do not change TYPE_PRECISION
	or TYPE_UNSIGNED of integral types.
	(set_min_and_max_values_for_integral_type): Leave TYPE_MIN/MAX_VALUE
	NULL_TREE for zero-precision integral types.

Index: gcc/stor-layout.c
===================================================================
--- gcc/stor-layout.c	(revision 203744)
+++ gcc/stor-layout.c	(working copy)
@@ -2052,18 +2052,9 @@ layout_type (tree type)
 	 of the language-specific code.  */
       gcc_unreachable ();
 
-    case BOOLEAN_TYPE:  /* Used for Java, Pascal, and Chill.  */
-      if (TYPE_PRECISION (type) == 0)
-	TYPE_PRECISION (type) = 1; /* default to one byte/boolean.  */
-
-      /* ... fall through ...  */
-
+    case BOOLEAN_TYPE:
     case INTEGER_TYPE:
     case ENUMERAL_TYPE:
-      if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
-	  && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
-	TYPE_UNSIGNED (type) = 1;
-
       SET_TYPE_MODE (type,
 		     smallest_mode_for_size (TYPE_PRECISION (type), MODE_INT));
       TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
@@ -2520,6 +2511,12 @@ set_min_and_max_values_for_integral_type
   tree min_value;
   tree max_value;
 
+  /* For bitfields with zero width we end up creating integer types
+     with zero precision.  Don't assign any minimum/maximum values
+     to those types, they don't have any valid value.  */
+  if (precision < 1)
+    return;
+
   if (is_unsigned)
     {
       min_value = build_int_cst (type, 0);


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