[Ada] Missing predicate check on return value
commit41c47207de50552e1daba4425d5714bdb7c6772d
authorpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 26 Sep 2018 09:17:16 +0000 (26 09:17 +0000)
committerpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 26 Sep 2018 09:17:16 +0000 (26 09:17 +0000)
tree6f0259bd94fa7634186de098bbb969e0fec3564d
parenta30ea1d07d223e8851f394616f53e461a68cf133
[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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@264611 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ada/ChangeLog
gcc/ada/sem_ch6.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/predicate3.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/predicate3_pkg.ads [new file with mode: 0644]