From 2efdbf0f3c085ca257f06acf045a8d9e8586df04 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Tue, 13 Aug 2013 15:52:26 +0000 Subject: [PATCH] trans.c (can_equal_min_or_max_val_p): Be prepared for values outside of the range of the type. * gcc-interface/trans.c (can_equal_min_or_max_val_p): Be prepared for values outside of the range of the type. From-SVN: r201692 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/gcc-interface/trans.c | 5 ++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gnat.dg/loop_optimization16.adb | 24 +++++++++++++++++++++++ gcc/testsuite/gnat.dg/loop_optimization16_pkg.adb | 8 ++++++++ gcc/testsuite/gnat.dg/loop_optimization16_pkg.ads | 7 +++++++ 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gnat.dg/loop_optimization16.adb create mode 100644 gcc/testsuite/gnat.dg/loop_optimization16_pkg.adb create mode 100644 gcc/testsuite/gnat.dg/loop_optimization16_pkg.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index e8d5389..e1f7363 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,10 @@ 2013-08-13 Eric Botcazou + * gcc-interface/trans.c (can_equal_min_or_max_val_p): Be prepared for + values outside of the range of the type. + +2013-08-13 Eric Botcazou + * gcc-interface/utils2.c (build_atomic_load): Do a mere view-conversion to the original type before converting to the result type. (build_atomic_store): First do a conversion to the original type before diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index f91f4b8..fdd59a8 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -2391,7 +2391,10 @@ can_equal_min_or_max_val_p (tree val, tree type, bool max) if (TREE_CODE (val) != INTEGER_CST) return true; - return tree_int_cst_equal (val, min_or_max_val) == 1; + if (max) + return tree_int_cst_lt (val, min_or_max_val) == 0; + else + return tree_int_cst_lt (min_or_max_val, val) == 0; } /* Return true if VAL (of type TYPE) can equal the minimum value of TYPE. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ae7973d..c264264 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-08-13 Eric Botcazou + + * gnat.dg/loop_optimization16.adb: New test. + * gnat.dg/loop_optimization16_pkg.ad[sb]: New helper. + 2013-08-13 Marek Polacek * gcc.dg/pr57980.c: Use vector of two elements, not just one. diff --git a/gcc/testsuite/gnat.dg/loop_optimization16.adb b/gcc/testsuite/gnat.dg/loop_optimization16.adb new file mode 100644 index 0000000..b9f2b70 --- /dev/null +++ b/gcc/testsuite/gnat.dg/loop_optimization16.adb @@ -0,0 +1,24 @@ +-- { dg-do run } + +with Loop_Optimization16_Pkg; use Loop_Optimization16_Pkg; + +procedure Loop_Optimization16 is + + Counter : Natural := 0; + + C : constant Natural := F; + + subtype Index_T is Index_Base range 1 .. Index_Base (C); + +begin + + for I in Index_T'First .. Index_T'Last loop + Counter := Counter + 1; + exit when Counter > 200; + end loop; + + if Counter > 200 then + raise Program_Error; + end if; + +end Loop_Optimization16; diff --git a/gcc/testsuite/gnat.dg/loop_optimization16_pkg.adb b/gcc/testsuite/gnat.dg/loop_optimization16_pkg.adb new file mode 100644 index 0000000..e4142f6 --- /dev/null +++ b/gcc/testsuite/gnat.dg/loop_optimization16_pkg.adb @@ -0,0 +1,8 @@ +package body Loop_Optimization16_Pkg is + + function F return Natural is + begin + return Natural (Index_Base'Last); + end; + +end Loop_Optimization16_Pkg; diff --git a/gcc/testsuite/gnat.dg/loop_optimization16_pkg.ads b/gcc/testsuite/gnat.dg/loop_optimization16_pkg.ads new file mode 100644 index 0000000..abeecfb --- /dev/null +++ b/gcc/testsuite/gnat.dg/loop_optimization16_pkg.ads @@ -0,0 +1,7 @@ +package Loop_Optimization16_Pkg is + + type Index_Base is range 0 .. 127; + + function F return Natural; + +end Loop_Optimization16_Pkg; -- 2.7.4