diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2008-03-10 19:26:35 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2008-03-10 19:26:35 +0000 |
commit | e1e7141cf3128d384dca902928d98a47cb57dddd (patch) | |
tree | dc98e5c42a55d7c4388ee9c0100c8cc34396efaa | |
parent | 725c2d321c429ef8f09b8474e0f3d693c6a5d1d8 (diff) | |
download | gcc-e1e7141cf3128d384dca902928d98a47cb57dddd.zip gcc-e1e7141cf3128d384dca902928d98a47cb57dddd.tar.gz gcc-e1e7141cf3128d384dca902928d98a47cb57dddd.tar.bz2 |
trans.c (emit_range_check): Do not emit the check if the base type of the expression is the type against...
* 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
-rw-r--r-- | gcc/ada/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/ada/trans.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/range_check2.adb | 13 |
4 files changed, 27 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index c3c9cad..814d517 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -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. diff --git a/gcc/ada/trans.c b/gcc/ada/trans.c index acf4de3..4cfd225 100644 --- a/gcc/ada/trans.c +++ b/gcc/ada/trans.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 693a2a1..d4cb326 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..33172f1 --- /dev/null +++ b/gcc/testsuite/gnat.dg/range_check2.adb @@ -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; |