From: Arnaud Charlet <charlet@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Vincent Pucci <pucci@adacore.com>
Subject: [Ada] New restriction for lock-free implementation
Date: Mon, 30 Jul 2012 15:14:00 -0000 [thread overview]
Message-ID: <20120730151227.GA14362@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]
This patch implements a new lock-free restriction. Thus, implicit dereferences
of access values prevent, as well as explicit dereference, the lock-free
implementation of protected objects.
The test below illustrates the new lock-free restriction:
------------
-- Source --
------------
generic
type Elmt_Type is private;
type Elmt_Access is access Elmt_Type;
package Test is
type Node_Type;
type Node_Access is access all Node_Type;
type Node_Type is limited record
Elmt : Elmt_Access;
Prev : Node_Access;
end record;
protected List with Lock_Free is
procedure Swap (L, R : Node_Access);
private
L : Node_Access := null;
end List;
end Test;
package body Test is
protected body List is
----------
-- Swap --
----------
procedure Swap (L, R : Node_Access) is
LP : constant Node_Access := L.Prev;
RP : constant Node_Access := R.Prev;
begin
L.Prev := RP;
R.Prev := LP;
end Swap;
end List;
end Test;
-----------------
-- Compilation --
-----------------
$ gnatmake -q -gnat12 test.adb
test.adb:7:07: illegal body when Lock_Free given
test.adb:8:40: dereference of access value not allowed
test.adb:9:40: dereference of access value not allowed
test.adb:12:11: dereference of access value not allowed
test.adb:13:11: dereference of access value not allowed
Tested on x86_64-pc-linux-gnu, committed on trunk
2012-07-30 Vincent Pucci <pucci@adacore.com>
* sem_ch9.adb (Allows_Lock_Free_Implementation): Restrict implicit
dereferences of access values.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1040 bytes --]
Index: sem_ch9.adb
===================================================================
--- sem_ch9.adb (revision 189974)
+++ sem_ch9.adb (working copy)
@@ -411,12 +411,15 @@
return Abandon;
- -- Explicit dereferences restricted (i.e. dereferences of
- -- access values).
+ -- Dereferences of access values restricted
- elsif Kind = N_Explicit_Dereference then
+ elsif Kind = N_Explicit_Dereference
+ or else (Kind = N_Selected_Component
+ and then Is_Access_Type (Etype (Prefix (N))))
+ then
if Lock_Free_Given then
- Error_Msg_N ("explicit dereference not allowed", N);
+ Error_Msg_N ("dereference of access value " &
+ "not allowed", N);
return Skip;
end if;
reply other threads:[~2012-07-30 15:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120730151227.GA14362@adacore.com \
--to=charlet@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=pucci@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).