From ce3da0d0d54ce3e469828698ba1ac5f25146b6f9 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Wed, 28 Nov 2012 10:51:19 +0000 Subject: stor-layout.c (layout_type): Do not clear TREE_OVERFLOW on overflowed zeroes, except in one specific case. * stor-layout.c (layout_type) : Do not clear TREE_OVERFLOW on overflowed zeroes, except in one specific case. ada/ * gcc-interface/decl.c (gnat_to_gnu_entity) : Use valid_constant_size_p to detect too large objects. : Likewise for too large return types. (allocatable_size_p): Call valid_constant_size_p in the fixed case. (annotate_value) : Simplify. : Deal with negative values here. * gcc-interface/trans.c (gnat_to_gnu) : Use valid_constant_size_p to detect too large objects on the LHS. * gcc-interface/misc.c (default_pass_by_ref): Likewise for large types. And use TYPE_SIZE_UNIT throughout. (must_pass_by_ref): Likewise. * gcc-interface/utils.c (max_size) : Split from common case. : Likewise. Call size_binop instead of fold_build2. : Simplify. * gcc-interface/utils2.c (build_allocator): Use valid_constant_size_p to detect too large allocations. From-SVN: r193886 --- gcc/ada/gcc-interface/utils.c | 78 ++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 35 deletions(-) (limited to 'gcc/ada/gcc-interface/utils.c') diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 6aa465b..716ea9e 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -3024,59 +3024,67 @@ max_size (tree exp, bool max_p) return max_p ? size_one_node : size_zero_node; case tcc_unary: + if (code == NON_LVALUE_EXPR) + return max_size (TREE_OPERAND (exp, 0), max_p); + + return fold_build1 (code, type, + max_size (TREE_OPERAND (exp, 0), + code == NEGATE_EXPR ? !max_p : max_p)); + case tcc_binary: + { + tree lhs = max_size (TREE_OPERAND (exp, 0), max_p); + tree rhs = max_size (TREE_OPERAND (exp, 1), + code == MINUS_EXPR ? !max_p : max_p); + + /* Special-case wanting the maximum value of a MIN_EXPR. + In that case, if one side overflows, return the other. */ + if (max_p && code == MIN_EXPR) + { + if (TREE_CODE (rhs) == INTEGER_CST && TREE_OVERFLOW (rhs)) + return lhs; + + if (TREE_CODE (lhs) == INTEGER_CST && TREE_OVERFLOW (lhs)) + return rhs; + } + + /* Likewise, handle a MINUS_EXPR or PLUS_EXPR with the LHS + overflowing and the RHS a variable. */ + if ((code == MINUS_EXPR || code == PLUS_EXPR) + && TREE_CODE (lhs) == INTEGER_CST + && TREE_OVERFLOW (lhs) + && !TREE_CONSTANT (rhs)) + return lhs; + + return size_binop (code, lhs, rhs); + } + case tcc_expression: switch (TREE_CODE_LENGTH (code)) { case 1: if (code == SAVE_EXPR) return exp; - else if (code == NON_LVALUE_EXPR) - return max_size (TREE_OPERAND (exp, 0), max_p); - else - return - fold_build1 (code, type, - max_size (TREE_OPERAND (exp, 0), - code == NEGATE_EXPR ? !max_p : max_p)); + + return fold_build1 (code, type, + max_size (TREE_OPERAND (exp, 0), max_p)); case 2: if (code == COMPOUND_EXPR) return max_size (TREE_OPERAND (exp, 1), max_p); - { - tree lhs = max_size (TREE_OPERAND (exp, 0), max_p); - tree rhs = max_size (TREE_OPERAND (exp, 1), - code == MINUS_EXPR ? !max_p : max_p); - - /* Special-case wanting the maximum value of a MIN_EXPR. - In that case, if one side overflows, return the other. - sizetype is signed, but we know sizes are non-negative. - Likewise, handle a MINUS_EXPR or PLUS_EXPR with the LHS - overflowing and the RHS a variable. */ - if (max_p - && code == MIN_EXPR - && TREE_CODE (rhs) == INTEGER_CST - && TREE_OVERFLOW (rhs)) - return lhs; - else if (max_p - && code == MIN_EXPR - && TREE_CODE (lhs) == INTEGER_CST - && TREE_OVERFLOW (lhs)) - return rhs; - else if ((code == MINUS_EXPR || code == PLUS_EXPR) - && TREE_CODE (lhs) == INTEGER_CST - && TREE_OVERFLOW (lhs) - && !TREE_CONSTANT (rhs)) - return lhs; - else - return fold_build2 (code, type, lhs, rhs); - } + return fold_build2 (code, type, + max_size (TREE_OPERAND (exp, 0), max_p), + max_size (TREE_OPERAND (exp, 1), max_p)); case 3: if (code == COND_EXPR) return fold_build2 (max_p ? MAX_EXPR : MIN_EXPR, type, max_size (TREE_OPERAND (exp, 1), max_p), max_size (TREE_OPERAND (exp, 2), max_p)); + + default: + break; } /* Other tree classes cannot happen. */ -- cgit v1.1