diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-06-16 10:19:51 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-06-16 10:19:51 +0000 |
commit | c7a1569ab3456783fd91a40a894f72f147c2087b (patch) | |
tree | 6345a720226036cb41895309c44054bab3970883 /gcc/ada/sem_ch13.adb | |
parent | a5c78779c3391c1394c96cee6f6e9334a55ae6ec (diff) | |
download | gcc-c7a1569ab3456783fd91a40a894f72f147c2087b.tar.gz |
2016-06-16 Eric Botcazou <ebotcazou@adacore.com>
* sem_util.ads (Indexed_Component_Bit_Offset): Declare.
* sem_util.adb (Indexed_Component_Bit_Offset): New
function returning the offset of an indexed component.
(Has_Compatible_Alignment_Internal): Call it.
* sem_ch13.adb (Offset_Value): New function returning the offset of an
Address attribute reference from the underlying entity.
(Validate_Address_Clauses): Call it and take the offset into
account for the size warning.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@237511 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/sem_ch13.adb')
-rw-r--r-- | gcc/ada/sem_ch13.adb | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 06e5d1b66e5..1d732b9b590 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -13626,6 +13626,53 @@ package body Sem_Ch13 is ------------------------------ procedure Validate_Address_Clauses is + function Offset_Value (Expr : Node_Id) return Uint; + -- Given an Address attribute reference, return the value in bits of its + -- offset from the first bit of the underlying entity, or 0 if it is not + -- known at compile time. + + ------------------ + -- Offset_Value -- + ------------------ + + function Offset_Value (Expr : Node_Id) return Uint is + N : Node_Id := Prefix (Expr); + Off : Uint; + Val : Uint := Uint_0; + + begin + -- Climb the prefix chain and compute the cumulative offset + + loop + if Is_Entity_Name (N) then + return Val; + + elsif Nkind (N) = N_Selected_Component then + Off := Component_Bit_Offset (Entity (Selector_Name (N))); + if Off /= No_Uint and then Off >= Uint_0 then + Val := Val + Off; + N := Prefix (N); + else + return Uint_0; + end if; + + elsif Nkind (N) = N_Indexed_Component then + Off := Indexed_Component_Bit_Offset (N); + if Off /= No_Uint then + Val := Val + Off; + N := Prefix (N); + else + return Uint_0; + end if; + + else + return Uint_0; + end if; + end loop; + end Offset_Value; + + -- Start of processing for Validate_Address_Clauses + begin for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop declare @@ -13640,6 +13687,8 @@ package body Sem_Ch13 is X_Size : Uint; Y_Size : Uint; + X_Offs : Uint; + begin -- Skip processing of this entry if warning already posted @@ -13651,16 +13700,25 @@ package body Sem_Ch13 is X_Alignment := Alignment (ACCR.X); Y_Alignment := Alignment (ACCR.Y); - -- Similarly obtain sizes + -- Similarly obtain sizes and offset X_Size := Esize (ACCR.X); Y_Size := Esize (ACCR.Y); + if ACCR.Off + and then Nkind (Expr) = N_Attribute_Reference + and then Attribute_Name (Expr) = Name_Address + then + X_Offs := Offset_Value (Expr); + else + X_Offs := Uint_0; + end if; + -- Check for large object overlaying smaller one if Y_Size > Uint_0 and then X_Size > Uint_0 - and then X_Size > Y_Size + and then X_Offs + X_Size > Y_Size then Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X); Error_Msg_N @@ -13672,6 +13730,11 @@ package body Sem_Ch13 is Error_Msg_Uint_1 := Y_Size; Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y); + if X_Offs /= Uint_0 then + Error_Msg_Uint_1 := X_Offs; + Error_Msg_NE ("\??and offset of & is ^", ACCR.N, ACCR.X); + end if; + -- Check for inadequate alignment, both of the base object -- and of the offset, if any. We only do this check if the -- run-time Alignment_Check is active. No point in warning |