diff options
author | Ed Schonberg <schonberg@adacore.com> | 2018-09-26 09:17:16 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-09-26 09:17:16 +0000 |
commit | bcbe14db192f03018ea74cf6eb24c04a110ecac0 (patch) | |
tree | 6f0259bd94fa7634186de098bbb969e0fec3564d /gcc/ada | |
parent | 4453a8221c65f386ae361670fa932643521374d7 (diff) | |
download | gcc-bcbe14db192f03018ea74cf6eb24c04a110ecac0.zip gcc-bcbe14db192f03018ea74cf6eb24c04a110ecac0.tar.gz gcc-bcbe14db192f03018ea74cf6eb24c04a110ecac0.tar.bz2 |
[Ada] Missing predicate check on return value
The semantics of the return statement includes an implicit conversion of
the value to the return type of the funcction. This conversion, as
elsewhere, entails a predicate check if the return type has a predicate
aspect.
We do not apply the check to a case expression because in the context of
a return statement it will be expanded into a series of return
statements, each of which will receive a predicate check.
2018-09-26 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* sem_ch6.adb (Analyze_Function_Return): If the return type has
a dynamic_predicate, apply a Predicate_Check to the expression,
given that it is implicitly converted to the return type.
Exclude case expressions from the check, because in this context
the expression is expanded into individual return statements.
gcc/testsuite/
* gnat.dg/predicate3.adb, gnat.dg/predicate3_pkg.ads: New
testcase.
From-SVN: r264611
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/ada/sem_ch6.adb | 10 |
2 files changed, 18 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index a0252f8..9db2747 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2018-09-26 Ed Schonberg <schonberg@adacore.com> + + * sem_ch6.adb (Analyze_Function_Return): If the return type has + a dynamic_predicate, apply a Predicate_Check to the expression, + given that it is implicitly converted to the return type. + Exclude case expressions from the check, because in this context + the expression is expanded into individual return statements. + 2018-09-26 Eric Botcazou <ebotcazou@adacore.com> * gcc-interface/decl.c (gnat_to_gnu_entity) <E_Task_Type>: In diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index b330426..d0617fe 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -1060,6 +1060,16 @@ package body Sem_Ch6 is Apply_Constraint_Check (Expr, R_Type); + -- The return value is converted to the return type of the function, + -- which implies a predicate check if the return type is predicated. + -- We do not apply the check to a case expression because it will + -- be expanded into a series of return statements, each of which + -- will receive a predicate check. + + if Nkind (Expr) /= N_Case_Expression then + Apply_Predicate_Check (Expr, R_Type); + end if; + -- Ada 2005 (AI-318-02): When the result type is an anonymous access -- type, apply an implicit conversion of the expression to that type -- to force appropriate static and run-time accessibility checks. |