diff options
author | Piotr Trojanek <trojanek@adacore.com> | 2021-02-17 23:55:59 +0100 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2021-10-11 13:38:11 +0000 |
commit | b89465c94165676ee278631b144781f1c739e680 (patch) | |
tree | abb736bdfe2d7ed29651e2da1b8111412bfd0ca1 | |
parent | 945ec76b8e110e2ef291777e123482389f6594e6 (diff) | |
download | gcc-b89465c94165676ee278631b144781f1c739e680.zip gcc-b89465c94165676ee278631b144781f1c739e680.tar.gz gcc-b89465c94165676ee278631b144781f1c739e680.tar.bz2 |
[Ada] Warn about conversion with any predefined time types
gcc/ada/
* sem_ch13.adb (Validate_Unchecked_Conversion): Simplify code
for detecting conversions with Ada.Calendar.Time type and extend
it to similar types in the Ada.Real_Time package.
-rw-r--r-- | gcc/ada/sem_ch13.adb | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index fb1be47..c60dd97 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -17335,8 +17335,32 @@ package body Sem_Ch13 is is Source : Entity_Id; Target : Entity_Id; + + procedure Warn_Nonportable (RE : RE_Id); + -- Warn if either source or target of the conversion is a predefined + -- private type, whose representation might differ between releases and + -- targets of the compiler. + + ---------------------- + -- Warn_Nonportable -- + ---------------------- + + procedure Warn_Nonportable (RE : RE_Id) is + begin + if Is_RTE (Source, RE) or else Is_RTE (Target, RE) then + pragma Assert (Is_Private_Type (RTE (RE))); + Error_Msg_NE + ("?z?representation of & values may change between " + & "'G'N'A'T versions", N, RTE (RE)); + end if; + end Warn_Nonportable; + + -- Local variables + Vnode : Node_Id; + -- Start of processing for Validate_Unchecked_Conversion + begin -- Obtain source and target types. Note that we call Ancestor_Subtype -- here because the processing for generic instantiation always makes @@ -17353,6 +17377,18 @@ package body Sem_Ch13 is return; end if; + -- Warn if one of the operands is a private type declared in + -- Ada.Calendar or Ada.Real_Time. Do not emit a warning when compiling + -- GNAT-related sources. + + if Warn_On_Unchecked_Conversion + and then not In_Predefined_Unit (N) + then + Warn_Nonportable (RO_CA_Time); + Warn_Nonportable (RO_RT_Time); + Warn_Nonportable (RE_Time_Span); + end if; + -- If we are dealing with private types, then do the check on their -- fully declared counterparts if the full declarations have been -- encountered (they don't have to be visible, but they must exist). @@ -17399,32 +17435,6 @@ package body Sem_Ch13 is end if; end if; - -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a - -- warning when compiling GNAT-related sources. - - if Warn_On_Unchecked_Conversion - and then not In_Predefined_Unit (N) - and then RTU_Loaded (Ada_Calendar) - and then (Chars (Source) = Name_Time - or else - Chars (Target) = Name_Time) - then - -- If Ada.Calendar is loaded and the name of one of the operands is - -- Time, there is a good chance that this is Ada.Calendar.Time. - - declare - Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time)); - begin - pragma Assert (Present (Calendar_Time)); - - if Source = Calendar_Time or else Target = Calendar_Time then - Error_Msg_N - ("?z?representation of 'Time values may change between " - & "'G'N'A'T versions", N); - end if; - end; - end if; - -- Make entry in unchecked conversion table for later processing by -- Validate_Unchecked_Conversions, which will check sizes and alignments -- (using values set by the back end where possible). This is only done |