diff options
author | Ed Schonberg <schonberg@adacore.com> | 2019-07-22 13:58:27 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2019-07-22 13:58:27 +0000 |
commit | ad277369b236a39fff13c87a51a8e67f7562a80a (patch) | |
tree | c1024ac2b531153bfb6a22989c8d9ff4e3dcfa63 | |
parent | a211917585ca978a84123c4c934f2f68bb545bcd (diff) | |
download | gcc-ad277369b236a39fff13c87a51a8e67f7562a80a.zip gcc-ad277369b236a39fff13c87a51a8e67f7562a80a.tar.gz gcc-ad277369b236a39fff13c87a51a8e67f7562a80a.tar.bz2 |
[Ada] Remove misleading warning/suggestion in membership test
This patch removes a warning on a membership test whose right operand is
given by a range. In many cases the check can be replaced by the use of
attribute 'Valid, but if the bounds of range are type conversion this
replacement would be invorrect and the warning and suggestion are
misleading.
2019-07-22 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* exp_ch4.adb (Expand_N_In): Do not suggest the use of attribute
'Valid as a replacement for a range check on a discrete type
when the bounds of the range are given by type conversions,
because in such a case there are distinct types involved and the
subbested attribute replacement would be misplaced.
gcc/testsuite/
* gnat.dg/warn26.adb: New testcase.
From-SVN: r273694
-rw-r--r-- | gcc/ada/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/ada/exp_ch4.adb | 9 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/warn26.adb | 20 |
4 files changed, 41 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 17d21f5..ef32945 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2019-07-22 Ed Schonberg <schonberg@adacore.com> + + * exp_ch4.adb (Expand_N_In): Do not suggest the use of attribute + 'Valid as a replacement for a range check on a discrete type + when the bounds of the range are given by type conversions, + because in such a case there are distinct types involved and the + subbested attribute replacement would be misplaced. + 2019-07-22 Yannick Moy <moy@adacore.com> * sem_spark.adb (Get_Root_Object, Is_Path_Expression, diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index a062434..7ef75f6 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -6272,6 +6272,10 @@ package body Exp_Ch4 is -- Similarly, do not rewrite membership as a validity check if -- within the predicate function for the type. + -- Finally, if the original bounds are type conversions, even + -- if they have been folded into constants, there are different + -- types involved and 'Valid is not appropriate. + then if In_Instance or else (Ekind (Current_Scope) = E_Function @@ -6279,6 +6283,11 @@ package body Exp_Ch4 is then null; + elsif Nkind (Lo_Orig) = N_Type_Conversion + or else Nkind (Hi_Orig) = N_Type_Conversion + then + null; + else Substitute_Valid_Check; goto Leave; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2ac298f..d8daa2d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-22 Ed Schonberg <schonberg@adacore.com> + + * gnat.dg/warn26.adb: New testcase. + 2019-07-22 Javier Miranda <miranda@adacore.com> * gnat.dg/class_wide5.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/warn26.adb b/gcc/testsuite/gnat.dg/warn26.adb new file mode 100644 index 0000000..08b681f --- /dev/null +++ b/gcc/testsuite/gnat.dg/warn26.adb @@ -0,0 +1,20 @@ +-- { dg-do compile } + +procedure Warn26 is + + Monitor_Period_Min : constant := 5; + Monitor_Period_Max : constant := 30; + + type Monitor_Period is range Monitor_Period_Min .. Monitor_Period_Max; + + subtype Period_T is Positive range 5 .. 30; + + function Id (X : Period_T) return Period_T is (X); + Input_Period : Period_T := Id (20); +begin + if Input_Period in + Integer (Monitor_Period'First) .. Integer ( Monitor_Period'Last) + then + null; + end if; +end Warn26; |