utils.c (max_size): Add special code to deal with the subtraction of a "negative" value in an...
* gcc-interface/utils.c (max_size) <tcc_binary>: Add special code to deal with the subtraction of a "negative" value in an unsigned type. From-SVN: r223837
This commit is contained in:
parent
afd6f70235
commit
396e67d21a
@ -1,3 +1,8 @@
|
||||
2015-05-28 Eric Botcazou <ebotcazou@adacore.com>
|
||||
|
||||
* gcc-interface/utils.c (max_size) <tcc_binary>: Add special code to
|
||||
deal with the subtraction of a "negative" value in an unsigned type.
|
||||
|
||||
2015-05-28 Eric Botcazou <ebotcazou@adacore.com>
|
||||
|
||||
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Subprogram_Type>: Do
|
||||
|
@ -3443,9 +3443,23 @@ max_size (tree exp, bool max_p)
|
||||
if ((code == MINUS_EXPR || code == PLUS_EXPR)
|
||||
&& TREE_CODE (lhs) == INTEGER_CST
|
||||
&& TREE_OVERFLOW (lhs)
|
||||
&& !TREE_CONSTANT (rhs))
|
||||
&& TREE_CODE (rhs) != INTEGER_CST)
|
||||
return lhs;
|
||||
|
||||
/* If we are going to subtract a "negative" value in an unsigned type,
|
||||
do the operation as an addition of the negated value, in order to
|
||||
avoid creating a spurious overflow below. */
|
||||
if (code == MINUS_EXPR
|
||||
&& TYPE_UNSIGNED (type)
|
||||
&& TREE_CODE (rhs) == INTEGER_CST
|
||||
&& !TREE_OVERFLOW (rhs)
|
||||
&& tree_int_cst_sign_bit (rhs) != 0)
|
||||
{
|
||||
rhs = fold_build1 (NEGATE_EXPR, type, rhs);
|
||||
code = PLUS_EXPR;
|
||||
}
|
||||
|
||||
/* We need to detect overflows so we call size_binop here. */
|
||||
return size_binop (code, lhs, rhs);
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
2015-05-28 Eric Botcazou <ebotcazou@adacore.com>
|
||||
|
||||
* gnat.dg/discr43.adb: New test.
|
||||
|
||||
2015-05-28 Eric Botcazou <ebotcazou@adacore.com>
|
||||
|
||||
* gnat.dg/varsize_temp.adb: Rename into...
|
||||
|
16
gcc/testsuite/gnat.dg/discr43.adb
Normal file
16
gcc/testsuite/gnat.dg/discr43.adb
Normal file
@ -0,0 +1,16 @@
|
||||
-- { dg-do compile }
|
||||
|
||||
with Text_IO; use Text_IO;
|
||||
|
||||
procedure Discr43 is
|
||||
|
||||
type Arr is array (Short_Integer range <>) of Boolean;
|
||||
|
||||
type Rec (LB : Short_Integer; UB : Short_Integer) is record
|
||||
A : Arr (LB .. UB);
|
||||
end record;
|
||||
|
||||
begin
|
||||
Put_Line ("Arr'Max_Size =" & Arr'Max_Size_In_Storage_Elements'Img);
|
||||
Put_Line ("Rec'Max_Size =" & Rec'Max_Size_In_Storage_Elements'Img);
|
||||
end;
|
Loading…
Reference in New Issue
Block a user