From 2352eadb81e329fad9adbead81db9203610aa19a Mon Sep 17 00:00:00 2001 From: Arnaud Charlet Date: Wed, 3 Oct 2012 10:11:48 +0200 Subject: [PATCH] [multiple changes] 2012-10-03 Ed Schonberg * sem_ch6.adb (New_Overloaded_Entity): call Append_Inherited_Subprogram when appropriate. * sem_dim.adb (Analyze_Dimension_Call): Do not perform dimensional analysis if call has previous semantic error. * sem_util.ads, sem_util.adb (Append_Inherited_Subprogram): new subprogram to handle properly the visibility of inherited operations that are primitives of a type extension, when the parent type and operations are declared in the same visible part. 2012-10-03 Robert Dewar * checks.adb (Minimize_Eliminate_Overflow_Checks): Properly handle case of top level expression within type conversion * gnat1drv.adb (Adjust_Global_Switches): Set SUPPRESSED as default for overflow checking for -gnatg mode (includes run-time). * sem_res.adb (Resolve_Type_Conversion): Avoid bogus warnings about redundant conversions from MINIMIZED/EXTENDED mode checking From-SVN: r192029 --- gcc/ada/ChangeLog | 20 ++++++++++++++++ gcc/ada/checks.adb | 16 ++++++++----- gcc/ada/gnat1drv.adb | 6 +++++ gcc/ada/sem_ch6.adb | 7 +++++- gcc/ada/sem_dim.adb | 4 +++- gcc/ada/sem_res.adb | 7 ++++++ gcc/ada/sem_util.adb | 57 ++++++++++++++++++++++++++++++++++++++++++++ gcc/ada/sem_util.ads | 6 +++++ 8 files changed, 115 insertions(+), 8 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 7479da69997..d11055f81db 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,23 @@ +2012-10-03 Ed Schonberg + + * sem_ch6.adb (New_Overloaded_Entity): call + Append_Inherited_Subprogram when appropriate. + * sem_dim.adb (Analyze_Dimension_Call): Do not perform dimensional + analysis if call has previous semantic error. + * sem_util.ads, sem_util.adb (Append_Inherited_Subprogram): + new subprogram to handle properly the visibility of inherited + operations that are primitives of a type extension, when the + parent type and operations are declared in the same visible part. + +2012-10-03 Robert Dewar + + * checks.adb (Minimize_Eliminate_Overflow_Checks): Properly + handle case of top level expression within type conversion + * gnat1drv.adb (Adjust_Global_Switches): Set SUPPRESSED as + default for overflow checking for -gnatg mode (includes run-time). + * sem_res.adb (Resolve_Type_Conversion): Avoid bogus warnings + about redundant conversions from MINIMIZED/EXTENDED mode checking + 2012-10-03 Javier Miranda * exp_ch4.adb (Expand_N_Allocator_Expression): Minor code diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index 3e9ee563d21..d74a05c11fe 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -7404,6 +7404,16 @@ package body Checks is elsif Top_Level and then not (Bignum_Operands or Long_Long_Integer_Operands) + + -- One further refinement. If we are at the top level, but our parent + -- is a type conversion, then go into bignum or long long integer node + -- since the result will be converted to that type directly without + -- going through the result type, and we may avoid an overflow. This + -- is the case for example of Long_Long_Integer (A ** 4), where A is + -- of type Integer, and the result A ** 4 fits in Long_Long_Integer + -- but does not fit in Integer. + + and then Nkind (Parent (N)) /= N_Type_Conversion then -- Here we will keep the original types, but we do need an overflow -- check, so we will set Do_Overflow_Check to True (actually it is @@ -7561,12 +7571,6 @@ package body Checks is if Nkind (N) = N_Op_Expon and then Etype (Right_Opnd (N)) = LLIB then Convert_To_And_Rewrite (Standard_Natural, Right_Opnd (N)); - - -- Now Long_Long_Integer_Operands may have to be reset if that was - -- the only long long integer operand, i.e. we now have long long - -- integer operands only if the left operand is long long integer. - - Long_Long_Integer_Operands := Etype (Left_Opnd (N)) = LLIB; end if; -- Here we will do the operation in Long_Long_Integer. We do this even diff --git a/gcc/ada/gnat1drv.adb b/gcc/ada/gnat1drv.adb index d6b188337fd..2d79edfeca9 100644 --- a/gcc/ada/gnat1drv.adb +++ b/gcc/ada/gnat1drv.adb @@ -334,6 +334,12 @@ procedure Gnat1drv is if Opt.Suppress_Options.Overflow_Checks_General /= Not_Set then null; + -- By default suppress overflow checks in -gnatg mode + + elsif GNAT_Mode then + Suppress_Options.Overflow_Checks_General := Suppressed; + Suppress_Options.Overflow_Checks_Assertions := Suppressed; + -- If we have backend divide and overflow checks, then by default -- overflow checks are minimized, which is a reasonable setting. diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index 4988661a081..ea92eb93295 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -8063,7 +8063,12 @@ package body Sem_Ch6 is Set_Homonym (S, E); - Append_Entity (S, Current_Scope); + if Is_Inherited_Operation (S) then + Append_Inherited_Subprogram (S); + else + Append_Entity (S, Current_Scope); + end if; + Set_Public_Status (S); if Debug_Flag_E then diff --git a/gcc/ada/sem_dim.adb b/gcc/ada/sem_dim.adb index c350433e2bc..afe7d85ae6a 100644 --- a/gcc/ada/sem_dim.adb +++ b/gcc/ada/sem_dim.adb @@ -1508,10 +1508,12 @@ package body Sem_Dim is begin -- Aspect is an Ada 2012 feature. Note that there is no need to check - -- dimensions for calls that don't come from source. + -- dimensions for calls that don't come from source, or those that may + -- have semantic errors. if Ada_Version < Ada_2012 or else not Comes_From_Source (N) + or else Error_Posted (N) then return; end if; diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 5095088f0bc..81c4e142cab 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -9624,6 +9624,13 @@ package body Sem_Res is then null; + -- Never warn on conversion to Long_Long_Integer'Base since + -- that is most likely an artifact of the extended overflow + -- checking and comes from complex expanded code. + + elsif Orig_T = Base_Type (Standard_Long_Long_Integer) then + null; + -- Here we give the redundant conversion warning. If it is an -- entity, give the name of the entity in the message. If not, -- just mention the expression. diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index f557033d416..2e68039262f 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -279,6 +279,63 @@ package body Sem_Util is return Alignment (E) * System_Storage_Unit; end Alignment_In_Bits; + --------------------------------- + -- Append_Inherited_Subprogram -- + --------------------------------- + + procedure Append_Inherited_Subprogram (S : Entity_Id) is + Par : constant Entity_Id := Alias (S); + -- The parent subprogram + + Scop : constant Entity_Id := Scope (Par); + -- The scope of definition of the parent subprogram + + Typ : constant Entity_Id := Defining_Entity (Parent (S)); + -- The derived type of which S is a primitive operation + + Decl : Node_Id; + Next_E : Entity_Id; + + begin + if Ekind (Current_Scope) = E_Package + and then In_Private_Part (Current_Scope) + and then Has_Private_Declaration (Typ) + and then Is_Tagged_Type (Typ) + and then Scop = Current_Scope + then + -- The inherited operation is available at the earliest place after + -- the derived type declaration ( RM 7.3.1 (6/1)). This is only + -- relevant for type extensions. If the parent operation appears + -- after the type extension, the operation is not visible. + + Decl := First + (Visible_Declarations + (Specification (Unit_Declaration_Node (Current_Scope)))); + while Present (Decl) loop + if Nkind (Decl) = N_Private_Extension_Declaration + and then Defining_Entity (Decl) = Typ + then + if Sloc (Decl) > Sloc (Par) then + Next_E := Next_Entity (Par); + Set_Next_Entity (Par, S); + Set_Next_Entity (S, Next_E); + return; + + else + exit; + end if; + end if; + + Next (Decl); + end loop; + end if; + + -- If partial view is not a type extension, or it appears before the + -- subprogram declaration, insert normally at end of entity list. + + Append_Entity (S, Current_Scope); + end Append_Inherited_Subprogram; + ----------------------------------------- -- Apply_Compile_Time_Constraint_Error -- ----------------------------------------- diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index 31276c795dd..57c4880b425 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -63,6 +63,12 @@ package Sem_Util is -- Otherwise Uint_0 is returned, indicating that the alignment of the -- entity is not yet known to the compiler. + procedure Append_Inherited_Subprogram (S : Entity_Id); + -- If the parent of the operation is declared in the visible part of + -- the current scope, the inherited operation is visible even though the + -- derived type that inherits the operation may be completed in the private + -- part of the current package. + procedure Apply_Compile_Time_Constraint_Error (N : Node_Id; Msg : String; -- 2.30.2