1170
1213
+ Also_Big := Signed_Over_8 (Neg_Half); -- Rounds down by 4.6(33).
1171
1214
+ Assert(Also_Big = -3);
1216
Index: gcc/testsuite/gnat.dg/unchecked_convert2.adb
1217
===================================================================
1218
--- gcc/testsuite/gnat.dg/unchecked_convert2.adb (.../tags/gcc_4_3_2_release) (revision 0)
1219
+++ gcc/testsuite/gnat.dg/unchecked_convert2.adb (.../branches/gcc-4_3-branch) (revision 141004)
1223
+with Ada.Unchecked_Conversion;
1224
+with Ada.Streams; use Ada.Streams;
1225
+with Ada.Text_IO; use Ada.Text_IO;
1227
+procedure Unchecked_Convert2 is
1229
+ subtype Day_Number is Integer range 0 .. 31;
1231
+ subtype Byte_Array_Of_Integer is Stream_Element_Array
1232
+ (1 .. Integer'Size / Stream_Element_Array'Component_Size);
1234
+ function To_Byte_Array is
1235
+ new Ada.Unchecked_Conversion (Integer, Byte_Array_Of_Integer);
1237
+ Day_Now : Day_Number;
1238
+ Pragma Volatile (Day_Now);
1240
+ Arr : Stream_Element_Array (1 .. 12) := (others => 16#ff#);
1242
+ procedure Test (Arr : Stream_Element_Array) is
1244
+ if Arr(5) /= 0 or Arr(6) /= 0 or Arr(7) /= 0 or Arr(8) /= 0 then
1245
+ raise Program_Error;
1251
+ Arr (5 .. 8) := To_Byte_Array (Day_Now);
1253
+ Arr (1) := 16#ff#;
1254
+end Unchecked_Convert2;
1255
Index: gcc/testsuite/gnat.dg/loop_optimization4_pkg.adb
1256
===================================================================
1257
--- gcc/testsuite/gnat.dg/loop_optimization4_pkg.adb (.../tags/gcc_4_3_2_release) (revision 0)
1258
+++ gcc/testsuite/gnat.dg/loop_optimization4_pkg.adb (.../branches/gcc-4_3-branch) (revision 141004)
1260
+package body Loop_Optimization4_Pkg is
1262
+ procedure Add (Phrase : String) is
1264
+ if Debug_Buffer_Len = Max_Debug_Buffer_Len then
1267
+ for I in Phrase'Range loop
1268
+ Debug_Buffer_Len := Debug_Buffer_Len + 1;
1269
+ Debug_Buffer (Debug_Buffer_Len) := Phrase (I);
1270
+ if Debug_Buffer_Len = Max_Debug_Buffer_Len then
1276
+end Loop_Optimization4_Pkg;
1277
Index: gcc/testsuite/gnat.dg/loop_optimization4_pkg.ads
1278
===================================================================
1279
--- gcc/testsuite/gnat.dg/loop_optimization4_pkg.ads (.../tags/gcc_4_3_2_release) (revision 0)
1280
+++ gcc/testsuite/gnat.dg/loop_optimization4_pkg.ads (.../branches/gcc-4_3-branch) (revision 141004)
1282
+package Loop_Optimization4_Pkg is
1284
+ Max_Debug_Buffer_Len : Natural := 8 * 1024;
1285
+ Debug_Buffer : String (1 .. Max_Debug_Buffer_Len);
1286
+ Debug_Buffer_Len : Natural range 0 .. Max_Debug_Buffer_Len;
1288
+ procedure Add (Phrase : String);
1290
+end Loop_Optimization4_Pkg;
1173
1291
Index: gcc/testsuite/gcc.dg/pragma-init-fini.c
1174
1292
===================================================================
1175
--- gcc/testsuite/gcc.dg/pragma-init-fini.c (.../tags/gcc_4_3_2_release) (revision 140854)
1176
+++ gcc/testsuite/gcc.dg/pragma-init-fini.c (.../branches/gcc-4_3-branch) (revision 140854)
1293
--- gcc/testsuite/gcc.dg/pragma-init-fini.c (.../tags/gcc_4_3_2_release) (revision 141004)
1294
+++ gcc/testsuite/gcc.dg/pragma-init-fini.c (.../branches/gcc-4_3-branch) (revision 141004)
1177
1295
@@ -4,13 +4,13 @@
1179
1297
extern void abort ();
3687
3980
case DW_OP_const1u:
3688
3981
result = read_1u (op_ptr);
3983
Index: gcc/ada/ChangeLog
3984
===================================================================
3985
--- gcc/ada/ChangeLog (.../tags/gcc_4_3_2_release) (revision 141004)
3986
+++ gcc/ada/ChangeLog (.../branches/gcc-4_3-branch) (revision 141004)
3988
+2008-10-06 Eric Botcazou <ebotcazou@adacore.com>
3990
+ * utils.c (can_fold_for_view_convert_p): New predicate.
3991
+ (unchecked_convert): Use it to disable problematic folding with
3992
+ VIEW_CONVERT_EXPR in the general case. Always disable it for the
3993
+ special VIEW_CONVERT_EXPR built for integral types and cope with
3994
+ its addressability issues by preserving the first conversion.
3996
2008-08-27 Release Manager
3998
* GCC 4.3.2 released.
3999
Index: gcc/ada/utils.c
4000
===================================================================
4001
--- gcc/ada/utils.c (.../tags/gcc_4_3_2_release) (revision 141004)
4002
+++ gcc/ada/utils.c (.../branches/gcc-4_3-branch) (revision 141004)
4003
@@ -3824,9 +3824,73 @@
4007
+/* Return true if EXPR is an expression that can be folded as an operand
4008
+ of a VIEW_CONVERT_EXPR. See the head comment of unchecked_convert for
4012
+can_fold_for_view_convert_p (tree expr)
4016
+ /* The folder will fold NOP_EXPRs between integral types with the same
4017
+ precision (in the middle-end's sense). We cannot allow it if the
4018
+ types don't have the same precision in the Ada sense as well. */
4019
+ if (TREE_CODE (expr) != NOP_EXPR)
4022
+ t1 = TREE_TYPE (expr);
4023
+ t2 = TREE_TYPE (TREE_OPERAND (expr, 0));
4025
+ /* Defer to the folder for non-integral conversions. */
4026
+ if (!(INTEGRAL_TYPE_P (t1) && INTEGRAL_TYPE_P (t2)))
4029
+ /* Only fold conversions that preserve both precisions. */
4030
+ if (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
4031
+ && operand_equal_p (rm_size (t1), rm_size (t2), 0))
4037
/* Return an expression that does an unchecked conversion of EXPR to TYPE.
4038
- If NOTRUNC_P is true, truncation operations should be suppressed. */
4039
+ If NOTRUNC_P is true, truncation operations should be suppressed.
4041
+ Special care is required with (source or target) integral types whose
4042
+ precision is not equal to their size, to make sure we fetch or assign
4043
+ the value bits whose location might depend on the endianness, e.g.
4045
+ Rmsize : constant := 8;
4046
+ subtype Int is Integer range 0 .. 2 ** Rmsize - 1;
4048
+ type Bit_Array is array (1 .. Rmsize) of Boolean;
4049
+ pragma Pack (Bit_Array);
4051
+ function To_Bit_Array is new Unchecked_Conversion (Int, Bit_Array);
4053
+ Value : Int := 2#1000_0001#;
4054
+ Vbits : Bit_Array := To_Bit_Array (Value);
4056
+ we expect the 8 bits at Vbits'Address to always contain Value, while
4057
+ their original location depends on the endianness, at Value'Address
4058
+ on a little-endian architecture but not on a big-endian one.
4060
+ ??? There is a problematic discrepancy between what is called precision
4061
+ here (and more generally throughout gigi) for integral types and what is
4062
+ called precision in the middle-end. In the former case it's the RM size
4063
+ as given by TYPE_RM_SIZE (or rm_size) whereas it's TYPE_PRECISION in the
4064
+ latter case, the hitch being that they are not equal when they matter,
4065
+ that is when the number of value bits is not equal to the type's size:
4066
+ TYPE_RM_SIZE does give the number of value bits but TYPE_PRECISION is set
4067
+ to the size. The sole exception are BOOLEAN_TYPEs for which both are 1.
4069
+ The consequence is that gigi must duplicate code bridging the gap between
4070
+ the type's size and its precision that exists for TYPE_PRECISION in the
4071
+ middle-end, because the latter knows nothing about TYPE_RM_SIZE, and be
4072
+ wary of transformations applied in the middle-end based on TYPE_PRECISION
4073
+ because this value doesn't reflect the actual precision for Ada. */
4076
unchecked_convert (tree type, tree expr, bool notrunc_p)
4078
@@ -3852,14 +3916,10 @@
4079
&& TYPE_JUSTIFIED_MODULAR_P (etype))))
4080
|| TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
4082
- tree rtype = type;
4083
- bool final_unchecked = false;
4085
if (TREE_CODE (etype) == INTEGER_TYPE
4086
&& TYPE_BIASED_REPRESENTATION_P (etype))
4088
tree ntype = copy_type (etype);
4090
TYPE_BIASED_REPRESENTATION_P (ntype) = 0;
4091
TYPE_MAIN_VARIANT (ntype) = ntype;
4092
expr = build1 (NOP_EXPR, ntype, expr);
4093
@@ -3868,15 +3928,18 @@
4094
if (TREE_CODE (type) == INTEGER_TYPE
4095
&& TYPE_BIASED_REPRESENTATION_P (type))
4097
- rtype = copy_type (type);
4098
+ tree rtype = copy_type (type);
4099
TYPE_BIASED_REPRESENTATION_P (rtype) = 0;
4100
TYPE_MAIN_VARIANT (rtype) = rtype;
4101
+ expr = convert (rtype, expr);
4102
+ expr = build1 (NOP_EXPR, type, expr);
4105
- /* We have another special case: if we are unchecked converting subtype
4106
- into a base type, we need to ensure that VRP doesn't propagate range
4107
- information since this conversion may be done precisely to validate
4108
- that the object is within the range it is supposed to have. */
4109
+ /* We have another special case: if we are unchecked converting either
4110
+ a subtype or a type with limited range into a base type, we need to
4111
+ ensure that VRP doesn't propagate range information because this
4112
+ conversion may be done precisely to validate that the object is
4113
+ within the range it is supposed to have. */
4114
else if (TREE_CODE (expr) != INTEGER_CST
4115
&& TREE_CODE (type) == INTEGER_TYPE && !TREE_TYPE (type)
4116
&& ((TREE_CODE (etype) == INTEGER_TYPE && TREE_TYPE (etype))
4117
@@ -3887,26 +3950,34 @@
4118
in order not to be deemed an useless type conversion, it must
4119
be from subtype to base type.
4121
+ Therefore we first do the bulk of the conversion to a subtype of
4122
+ the final type. And this conversion must itself not be deemed
4123
+ useless if the source type is not a subtype because, otherwise,
4124
+ the final VIEW_CONVERT_EXPR will be deemed so as well. That's
4125
+ why we toggle the unsigned flag in this conversion, which is
4126
+ harmless since the final conversion is only a reinterpretation
4127
+ of the bit pattern.
4129
??? This may raise addressability and/or aliasing issues because
4130
VIEW_CONVERT_EXPR gets gimplified as an lvalue, thus causing the
4131
address of its operand to be taken if it is deemed addressable
4132
and not already in GIMPLE form. */
4133
- rtype = gnat_type_for_mode (TYPE_MODE (type), TYPE_UNSIGNED (type));
4135
+ = gnat_type_for_mode (TYPE_MODE (type), !TYPE_UNSIGNED (etype));
4136
rtype = copy_type (rtype);
4137
TYPE_MAIN_VARIANT (rtype) = rtype;
4138
TREE_TYPE (rtype) = type;
4139
- final_unchecked = true;
4140
+ expr = convert (rtype, expr);
4141
+ expr = build1 (VIEW_CONVERT_EXPR, type, expr);
4144
- expr = convert (rtype, expr);
4145
- if (type != rtype)
4146
- expr = fold_build1 (final_unchecked ? VIEW_CONVERT_EXPR : NOP_EXPR,
4149
+ expr = convert (type, expr);
4152
- /* If we are converting TO an integral type whose precision is not the
4153
- same as its size, first unchecked convert to a record that contains
4154
- an object of the output type. Then extract the field. */
4155
+ /* If we are converting to an integral type whose precision is not equal
4156
+ to its size, first unchecked convert to a record that contains an
4157
+ object of the output type. Then extract the field. */
4158
else if (INTEGRAL_TYPE_P (type) && TYPE_RM_SIZE (type)
4159
&& 0 != compare_tree_int (TYPE_RM_SIZE (type),
4160
GET_MODE_BITSIZE (TYPE_MODE (type))))
4161
@@ -3922,8 +3993,8 @@
4162
expr = build_component_ref (expr, NULL_TREE, field, 0);
4165
- /* Similarly for integral input type whose precision is not equal to its
4167
+ /* Similarly if we are converting from an integral type whose precision
4168
+ is not equal to its size. */
4169
else if (INTEGRAL_TYPE_P (etype) && TYPE_RM_SIZE (etype)
4170
&& 0 != compare_tree_int (TYPE_RM_SIZE (etype),
4171
GET_MODE_BITSIZE (TYPE_MODE (etype))))
4172
@@ -3953,13 +4024,15 @@
4174
expr = maybe_unconstrained_array (expr);
4175
etype = TREE_TYPE (expr);
4176
- expr = fold_build1 (VIEW_CONVERT_EXPR, type, expr);
4177
+ if (can_fold_for_view_convert_p (expr))
4178
+ expr = fold_build1 (VIEW_CONVERT_EXPR, type, expr);
4180
+ expr = build1 (VIEW_CONVERT_EXPR, type, expr);
4183
- /* If the result is an integral type whose size is not equal to
4184
- the size of the underlying machine type, sign- or zero-extend
4185
- the result. We need not do this in the case where the input is
4186
- an integral type of the same precision and signedness or if the output
4187
+ /* If the result is an integral type whose precision is not equal to its
4188
+ size, sign- or zero-extend the result. We need not do this if the input
4189
+ is an integral type of the same precision and signedness or if the output
4190
is a biased type or if both the input and output are unsigned. */
4192
&& INTEGRAL_TYPE_P (type) && TYPE_RM_SIZE (type)
3690
4193
Index: gcc/fortran/trans-array.c
3691
4194
===================================================================
3692
--- gcc/fortran/trans-array.c (.../tags/gcc_4_3_2_release) (revision 140854)
3693
+++ gcc/fortran/trans-array.c (.../branches/gcc-4_3-branch) (revision 140854)
4195
--- gcc/fortran/trans-array.c (.../tags/gcc_4_3_2_release) (revision 141004)
4196
+++ gcc/fortran/trans-array.c (.../branches/gcc-4_3-branch) (revision 141004)
3694
4197
@@ -5621,7 +5621,7 @@
3695
4198
gfc_add_expr_to_block (&fnblock, tmp);