* [COMMITTED] ada: Reject nonconfirming Size attribute value for aliased object
@ 2022-11-21 10:13 Marc Poulhiès
0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2022-11-21 10:13 UTC (permalink / raw)
To: gcc-patches; +Cc: Marc Poulhiès
Only confirming Size must be supported for aliased object of elementary
type (see RM 13.1 in the "Implementation Advice").
-- size is 1-byte
type Y is range 0 .. 20;
type Ay is access all Y;
-- Var size is 8-bytes
Var : aliased Y := 5 with Size => 64;
-- JP.all is a 1-byte reference to an 8-bytes objects.
JP : Ay := Var'Access;
The above JP.all references the first byte of the 8-byte Var object,
which is, for example, not correct on little-endian systems.
This change rejects nonconfirming Size attribute on such objects
instead of miscompiling it.
gcc/ada/
* sem_ch13.adb (Check_One_Attr): produce error when Size attribute
used on aliased object of elementary types with nonconfirming
value.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_ch13.adb | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 5507353136b..bf84a10ded6 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -7310,6 +7310,21 @@ package body Sem_Ch13 is
Set_Esize (U_Ent, Size);
end if;
+ -- As of RM 13.1, only confirming size
+ -- (i.e. (Size = Esize (Etyp))) for aliased object of
+ -- elementary type must be supported.
+ -- GNAT rejects nonconfirming size for such object.
+
+ if Is_Aliased (U_Ent)
+ and then Is_Elementary_Type (Etyp)
+ and then Known_Esize (U_Ent)
+ and then Size /= Esize (Etyp)
+ then
+ Error_Msg_N
+ ("nonconfirming Size for aliased object is not "
+ & "supported", N);
+ end if;
+
Set_Has_Size_Clause (U_Ent);
end;
end if;
--
2.34.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-21 10:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-21 10:13 [COMMITTED] ada: Reject nonconfirming Size attribute value for aliased object Marc Poulhiès
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).