diff mbox

[Ada,C,C++] sizetypes no longer sign-extend

Message ID alpine.LNX.2.00.1109021623470.2130@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener Sept. 2, 2011, 2:31 p.m. UTC
On Fri, 2 Sep 2011, Richard Guenther wrote:

> 
> This patch makes us no longer treat unsigned sizetypes as sign-extending
> which has caused trouble in the past (see the tree-ssa-ccp.c workarounds
> removed below).
> 
> Most frontend specific changes below deal with the fact that overflow
> behavior, as reported from size_binop, changes as unsigned sizetypes
> now no longer overflow at SSIZETYPE_MAX but at USIZETYPE_MAX.  Diagnostics
> expect warnings when overflow at half of the address-space occurs,
> and Ada needs to pay special attention to its "negative" offsets,
> all host_integerp (..., 1) checks have to be adjusted.
> 
> The patch bootstraps ok on x86_64-unknown-linux-gnu with all languages
> enabled and tests with the following FAILs with {,-m32}:
> 
> Running target unix//-m32
> FAIL: g++.dg/tree-ssa/pr19807.C scan-tree-dump-times optimized "\\+ 
> 0x0f*;" 1
> 
> still need to figure out how to properly quote that regexp for TCL
> scanning for the various (sizetype)-1U printings ...
> 
> Running target unix/{,-m32}
> FAIL: gcc.dg/pr42611.c  (test for errors, line 17)
> FAIL: gcc.dg/pr42611.c (test for excess errors)
> 
> another missed overflow check, looking at it now
> 
> Running target unix/
> FAIL: gnat.dg/array11.adb  (test for warnings, line 12)
> FAIL: gnat.dg/object_overflow.adb  (test for warnings, line 8)
> 
> Running target unix//-m32
> FAIL: gnat.dg/array11.adb  (test for warnings, line 12)
> FAIL: gnat.dg/frame_overflow.adb  (test for errors, line 17)
> FAIL: gnat.dg/frame_overflow.adb  (test for errors, line 24)
> FAIL: gnat.dg/object_overflow.adb  (test for warnings, line 8)
> 
> probably similar, I pushed back Ada diagnostic tests for now,
> but will look at them after resolving the above remaining FAIL.

gnat.dg/array11.adb and gnat.dg/object_overflow.adb are fixed
by the following.  Not sure what type to test TYPE_UNSIGNED on
though.  Possibly needs adjustment in c-comment.c:complete_array_type
to use ssize_int (-1) for the array[] = {...} case.

Comments?

Thanks,
Richard.
diff mbox

Patch

Index: trunk/gcc/stor-layout.c
===================================================================
--- trunk.orig/gcc/stor-layout.c	2011-09-02 16:23:33.000000000 +0200
+++ trunk/gcc/stor-layout.c	2011-09-02 16:19:12.000000000 +0200
@@ -1959,16 +1959,14 @@  layout_type (tree type)
 	    if (integer_zerop (element_size))
 	      length = size_zero_node;
 
-	    /* The computation should happen in the original type so
+	    /* The computation should happen in the original signedness so
 	       that (possible) negative values are handled appropriately.  */
 	    else
 	      length
 		= fold_convert (sizetype,
-				fold_build2 (PLUS_EXPR, TREE_TYPE (lb),
-					     build_int_cst (TREE_TYPE (lb), 1),
-					     fold_build2 (MINUS_EXPR,
-							  TREE_TYPE (lb),
-							  ub, lb)));
+				size_binop (PLUS_EXPR,
+					    build_int_cst (TREE_TYPE (lb), 1),
+					    size_binop (MINUS_EXPR, ub, lb)));
 
 	    TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
 					   fold_convert (bitsizetype,
Index: trunk/gcc/ada/gcc-interface/utils.c
===================================================================
--- trunk.orig/gcc/ada/gcc-interface/utils.c	2011-09-02 16:23:33.000000000 +0200
+++ trunk/gcc/ada/gcc-interface/utils.c	2011-09-02 16:22:20.000000000 +0200
@@ -1248,7 +1248,7 @@  copy_type (tree type)
   return new_type;
 }
 
-/* Return a subtype of sizetype with range MIN to MAX and whose
+/* Return a subtype of [s]sizetype with range MIN to MAX and whose
    TYPE_INDEX_TYPE is INDEX.  GNAT_NODE is used for the position
    of the associated TYPE_DECL.  */
 
@@ -1256,7 +1256,8 @@  tree
 create_index_type (tree min, tree max, tree index, Node_Id gnat_node)
 {
   /* First build a type for the desired range.  */
-  tree type = build_nonshared_range_type (sizetype, min, max);
+  tree type = build_nonshared_range_type (TYPE_UNSIGNED (index)
+					  ? sizetype : ssizetype, min, max);
 
   /* Then set the index type.  */
   SET_TYPE_INDEX_TYPE (type, index);