diff options
author | Ed Schonberg <schonberg@adacore.com> | 2019-07-01 13:36:56 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2019-07-01 13:36:56 +0000 |
commit | 90fd73bbeaad8438a3251e061f8f6525691f3c30 (patch) | |
tree | 2f4f105ad34d7cfe70216ad8cd9cc29634a7dbef /gcc/ada | |
parent | 69b5279e977593d656906288316ee03a8bf79c6a (diff) | |
download | gcc-90fd73bbeaad8438a3251e061f8f6525691f3c30.zip gcc-90fd73bbeaad8438a3251e061f8f6525691f3c30.tar.gz gcc-90fd73bbeaad8438a3251e061f8f6525691f3c30.tar.bz2 |
[Ada] Wrong code with -gnatVa on lock-free protected objects
This patch fixes the handling of validity checks on protected objects
that use the Lock-Free implementation when validity checks are enabled,
previous to this patch the compiler would report improperly that a
condition in a protected operation was always True (when comoipled with
-gnatwa) and would generate incorrect code fhat operation.
2019-07-01 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* checks.adb (Insert_Valid_Check): Do not apply validity check
to variable declared within a protected object that uses the
Lock_Free implementation, to prevent unwarranted constant
folding, because entities within such an object msut be treated
as volatile.
gcc/testsuite/
* gnat.dg/prot7.adb, gnat.dg/prot7.ads: New testcase.
From-SVN: r272873
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/ada/checks.adb | 13 |
2 files changed, 21 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index c60b957..bf6e1c3 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2019-07-01 Ed Schonberg <schonberg@adacore.com> + + * checks.adb (Insert_Valid_Check): Do not apply validity check + to variable declared within a protected object that uses the + Lock_Free implementation, to prevent unwarranted constant + folding, because entities within such an object msut be treated + as volatile. + 2019-07-01 Eric Botcazou <ebotcazou@adacore.com> * exp_ch9.adb (Check_Inlining): Deal with Has_Pragma_No_Inline. diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index fcfaec7..e851c5f 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -7429,6 +7429,19 @@ package body Checks is return; end if; + -- Entities declared in Lock_free protected types must be treated + -- as volatile, and we must inhibit validity checks to prevent + -- improper constant folding. + + if Is_Entity_Name (Expr) + and then Is_Subprogram (Scope (Entity (Expr))) + and then Present (Protected_Subprogram (Scope (Entity (Expr)))) + and then Uses_Lock_Free + (Scope (Protected_Subprogram (Scope (Entity (Expr))))) + then + return; + end if; + -- If we have a checked conversion, then validity check applies to -- the expression inside the conversion, not the result, since if -- the expression inside is valid, then so is the conversion result. |