From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Javier Miranda <miranda@adacore.com>
Subject: [Ada] Pragma Unchecked_Union on derived discriminated type
Date: Fri, 29 Sep 2017 13:24:00 -0000 [thread overview]
Message-ID: <20170929132431.GA145232@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1489 bytes --]
The compiler reports an spurious error processing a derived type
of a non-tagged record type that has discriminants, pragma
Unchecked_Union and pragma Convention C.
After this patch the following test compiles silently.
procedure Conversion is
type small_array is array (0 .. 2) of Integer;
type big_array is array (0 .. 3) of Integer;
type small_record is record
field1 : aliased Integer := 0;
field2 : aliased small_array := (0, 0, 0);
end record;
type big_record is record
field1 : aliased Integer := 0;
field2 : aliased big_array := (0, 0, 0, 0);
end record;
type myUnion (discr : Integer := 0) is record
case discr is
when 0 =>
record1 : aliased small_record;
when others =>
record2 : aliased big_record;
end case;
end record;
type UU_myUnion3 (discr : Integer := 0) is new myUnion (discr); -- Test
pragma Unchecked_Union (UU_myUnion3);
pragma Convention (C, UU_myUnion3);
procedure Convert (A : in UU_myUnion3; B : out UU_myUnion3);
pragma Import (C, Convert);
begin
null;
end Conversion;
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
2017-09-29 Javier Miranda <miranda@adacore.com>
* sem_ch3.adb (Replace_Components): Update references to discriminants
located in variant parts inherited from the parent type.
gcc/testsuite/
2017-09-29 Javier Miranda <miranda@adacore.com>
* gnat.dg/unchecked_union2.adb: New testcase.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1968 bytes --]
Index: sem_ch3.adb
===================================================================
--- sem_ch3.adb (revision 253283)
+++ sem_ch3.adb (working copy)
@@ -21932,6 +21932,17 @@
Next_Discriminant (Comp);
end loop;
+ elsif Nkind (N) = N_Variant_Part then
+ Comp := First_Discriminant (Typ);
+ while Present (Comp) loop
+ if Chars (Comp) = Chars (Name (N)) then
+ Set_Entity (Name (N), Comp);
+ exit;
+ end if;
+
+ Next_Component (Comp);
+ end loop;
+
elsif Nkind (N) = N_Component_Declaration then
Comp := First_Component (Typ);
while Present (Comp) loop
Index: ../testsuite/gnat.dg/unchecked_union2.adb
===================================================================
--- ../testsuite/gnat.dg/unchecked_union2.adb (revision 0)
+++ ../testsuite/gnat.dg/unchecked_union2.adb (revision 0)
@@ -0,0 +1,35 @@
+-- { dg-do compile }
+
+procedure Unchecked_Union2 is
+ type small_array is array (0 .. 2) of Integer;
+ type big_array is array (0 .. 3) of Integer;
+
+ type small_record is record
+ field1 : aliased Integer := 0;
+ field2 : aliased small_array := (0, 0, 0);
+ end record;
+
+ type big_record is record
+ field1 : aliased Integer := 0;
+ field2 : aliased big_array := (0, 0, 0, 0);
+ end record;
+
+ type myUnion (discr : Integer := 0) is record
+ case discr is
+ when 0 =>
+ record1 : aliased small_record;
+ when others =>
+ record2 : aliased big_record;
+ end case;
+ end record;
+
+ type UU_myUnion3 (discr : Integer := 0) is new myUnion (discr); -- Test
+ pragma Unchecked_Union (UU_myUnion3);
+ pragma Convention (C, UU_myUnion3);
+
+ procedure Convert (A : in UU_myUnion3; B : out UU_myUnion3);
+ pragma Import (C, Convert);
+
+begin
+ null;
+end Unchecked_Union2;
reply other threads:[~2017-09-29 13:24 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=20170929132431.GA145232@adacore.com \
--to=derodat@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=miranda@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).