* [Ada] Wrong code with -gnatVa on lock-free protected objects
@ 2019-07-01 13:38 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-07-01 13:38 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 788 bytes --]
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.
Tested on x86_64-pc-linux-gnu, committed on trunk
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.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1909 bytes --]
--- gcc/ada/checks.adb
+++ 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.
--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/prot7.adb
@@ -0,0 +1,22 @@
+-- { dg-do compile }
+-- { dg-options "-gnatwa -gnatVa" }
+
+package body Prot7 is
+ protected body Default_Slice is
+ function Get return Instance_Pointer is
+ begin
+ return Default;
+ end Get;
+
+ procedure Set (
+ Discard : in out Boolean;
+ Slice : in Instance_Pointer
+ ) is
+ begin
+ Discard := Default /= null;
+ if not Discard then
+ Default := Slice;
+ end if;
+ end Set;
+ end Default_Slice;
+end Prot7;
--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/prot7.ads
@@ -0,0 +1,16 @@
+package Prot7 is
+ type Instance_Pointer is access Integer;
+
+ protected Default_Slice
+ with Lock_Free
+ is
+ function Get return Instance_Pointer;
+
+ procedure Set (
+ Discard : in out Boolean;
+ Slice : in Instance_Pointer
+ );
+ private
+ Default : Instance_Pointer;
+ end Default_Slice;
+end Prot7;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-07-01 13:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-01 13:38 [Ada] Wrong code with -gnatVa on lock-free protected objects Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).