OSDN Git Service

* gcc-interface/trans.c (can_equal_min_or_max_val_p): Be prepared for
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 13 Aug 2013 16:02:49 +0000 (16:02 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 13 Aug 2013 16:02:49 +0000 (16:02 +0000)
values outside of the range of the type.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@201694 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/gcc-interface/trans.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/loop_optimization16.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/loop_optimization16_pkg.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/loop_optimization16_pkg.ads [new file with mode: 0644]

index 3da582d..003eb66 100644 (file)
@@ -1,3 +1,8 @@
+2013-08-13  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/trans.c (can_equal_min_or_max_val_p): Be prepared for
+       values outside of the range of the type.
+
 2013-05-26  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/trans.c (Attribute_to_gnu) <Attr_Last_Bit>: Add kludge
index e5f8351..d63ffe8 100644 (file)
@@ -2232,7 +2232,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.
index 39178c0..26f4ce1 100644 (file)
@@ -1,3 +1,8 @@
+2013-08-13  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/loop_optimization16.adb: New test.
+       * gnat.dg/loop_optimization16_pkg.ad[sb]: New helper.
+
 2013-08-13  Marek Polacek  <polacek@redhat.com>
 
        Backport from 4.8:
diff --git a/gcc/testsuite/gnat.dg/loop_optimization16.adb b/gcc/testsuite/gnat.dg/loop_optimization16.adb
new file mode 100644 (file)
index 0000000..b9f2b70
--- /dev/null
@@ -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 (file)
index 0000000..e4142f6
--- /dev/null
@@ -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 (file)
index 0000000..abeecfb
--- /dev/null
@@ -0,0 +1,7 @@
+package Loop_Optimization16_Pkg is
+
+  type Index_Base is range 0 .. 127;
+
+  function F return Natural;
+
+end Loop_Optimization16_Pkg;