This is the mail archive of the gcc-patches@gcc.gnu.org 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] Do not emit useless range checks


The recent warning added by Diego to VRP spotted useless range checks emitted 
by Gigi when translating 'Val or 'Value.

Regtested locally and ext-mailserved on x86.


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-10  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/range_check2.adb: New test.


-- 
Eric Botcazou
Index: trans.c
===================================================================
--- trans.c	(revision 133035)
+++ trans.c	(working copy)
@@ -5757,6 +5757,11 @@ emit_range_check (tree gnu_expr, Entity_
   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.  */
-- { 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;

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