This is the mail archive of the 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]

[Ada] Avoid emitting overflow check for constant result

This is a follow-up to
so no code generation change for the time being.

While checks would be optimized away, if the constant overflows, there would 
be no way to warn the user.  Now the constant is returned and the caller has 
to check for TREE_OVERFLOW.  This matches the behavior of build_binary_op.

Tested on i586-suse-linux, applied on the mainline.

2008-11-07  Geert Bosch  <>

	* gcc-interface/trans.c (build_binary_op_trapv): Avoid emitting
	overflow check for constant result.

Eric Botcazou
Index: gcc-interface/trans.c
--- gcc-interface/trans.c	(revision 141665)
+++ gcc-interface/trans.c	(working copy)
@@ -6146,6 +6146,10 @@ build_binary_op_trapv (enum tree_code co
   gnu_expr = build_binary_op (code, gnu_type, lhs, rhs);
+  /* If we can fold the expression to a constant, just return it.
+     The caller will deal with overflow, no need to generate a check. */
+  if (TREE_CONSTANT (gnu_expr)) return gnu_expr;
   check = fold_build3 (COND_EXPR, integer_type_node,
 		       rhs_lt_zero,  check_neg, check_pos);

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