trans.c (emit_range_check): Do not emit the check if the base type of the expression...
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 10 Mar 2008 19:26:35 +0000 (19:26 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 10 Mar 2008 19:26:35 +0000 (19:26 +0000)
* trans.c (emit_range_check): Do not emit the check if the base type
of the expression is the type against which its range must be checked.

From-SVN: r133083

gcc/ada/ChangeLog
gcc/ada/trans.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/range_check2.adb [new file with mode: 0644]

index c3c9cadc2b82a27e2d2f52d139365f1e30ae7703..814d51730f57d027f2edd316f0788b3f11d1c901 100644 (file)
@@ -1,3 +1,8 @@
+2008-03-10  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * trans.c (emit_range_check): Do not emit the check if the base type
+       of the expression is the type against which its range must be checked.
+
 2008-03-08  Eric Botcazou  <ebotcazou@adacore.com>
 
        * decl.c (maybe_pad_type): Use value_factor_p.
index acf4de3793d85d0b6eb94625f8d3bc98d746ea7b..4cfd2253987516e8fb9c052a094e7fc8045f1d54 100644 (file)
@@ -5757,6 +5757,11 @@ emit_range_check (tree gnu_expr, Entity_Id gnat_range_type)
   tree gnu_high = TYPE_MAX_VALUE (gnu_range_type);
   tree gnu_compare_type = get_base_type (TREE_TYPE (gnu_expr));
 
+  /* If GNU_EXPR has GNAT_RANGE_TYPE as its base type, no check is needed.
+     This can for example happen when translating 'Val or 'Value.  */
+  if (gnu_compare_type == gnu_range_type)
+    return gnu_expr;
+
   /* If GNU_EXPR has an integral type that is narrower than GNU_RANGE_TYPE,
      we can't do anything since we might be truncating the bounds.  No
      check is needed in this case.  */
index 693a2a1a7be22e7c9561987495eec234bbc56f78..d4cb32611cb3bbdf0e1942a17d842b2b7654c3ec 100644 (file)
@@ -1,3 +1,7 @@
+2008-03-10  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/range_check2.adb: New test.
+
 2008-03-10  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR tree-optimization/35494
diff --git a/gcc/testsuite/gnat.dg/range_check2.adb b/gcc/testsuite/gnat.dg/range_check2.adb
new file mode 100644 (file)
index 0000000..33172f1
--- /dev/null
@@ -0,0 +1,13 @@
+-- { dg-do compile }
+-- { dg-options "-O2" }
+
+procedure Range_Check2 is
+
+  subtype Block_Subtype is String(1 .. 6);
+  type Color is (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White);
+  Foregrnd_Color : Color := White;
+  Block : Block_Subtype := "123456";
+
+begin
+  Foregrnd_Color := Color'Val(Integer'Value(Block(5 .. 6)));
+end;