From 0246fe44ac945c563cb57fdb625746293d8f8334 Mon Sep 17 00:00:00 2001 From: Bob Duff Date: Wed, 14 Aug 2019 09:52:34 +0000 Subject: [PATCH] [Ada] Warn about unknown condition in Compile_Time_Warning The compiler now warns if the condition in a pragma Compile_Time_Warning or Compile_Time_Error does not have a compile-time-known value. The warning is not given for pragmas in a generic template, but is given for pragmas in an instance. The -gnatw_c and -gnatw_C switches turn the warning on and off. The default is on. 2019-08-14 Bob Duff gcc/ada/ * sem_prag.ads, sem_prag.adb (Process_Compile_Time_Warning_Or_Error): In parameterless version, improve detection of whether we are in a generic unit to cover the case of an instance within a generic unit. (Process_Compile_Time_Warning_Or_Error): Rename the two-parameter version to be Validate_Compile_Time_Warning_Or_Error, and do not export it. Issue a warning if the condition is not known at compile time. The key point is that the warning must be given only for pragmas deferred to the back end, because the back end discovers additional values that are known at compile time. Previous changes in this ticket have enabled this by deferring to the back end without checking for special cases such as 'Size. (Validate_Compile_Time_Warning_Or_Error): Rename to be Defer_Compile_Time_Warning_Error_To_BE. * warnsw.ads, warnsw.adb (Warn_On_Unknown_Compile_Time_Warning): Add new switches -gnatw_c and -gnatw_C to control the above warning. * doc/gnat_ugn/building_executable_programs_with_gnat.rst: Document new switches. * gnat_ugn.texi: Regenerate. gcc/testsuite/ * gnat.dg/warn27.adb: New testcase. From-SVN: r274469 --- gcc/ada/ChangeLog | 24 ++ ...building_executable_programs_with_gnat.rst | 26 +- gcc/ada/gnat_ugn.texi | 67 ++-- gcc/ada/sem_prag.adb | 73 +++-- gcc/ada/sem_prag.ads | 8 - gcc/ada/warnsw.adb | 301 +++++++++--------- gcc/ada/warnsw.ads | 105 +++--- gcc/testsuite/ChangeLog | 4 + gcc/testsuite/gnat.dg/warn27.adb | 10 + 9 files changed, 374 insertions(+), 244 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/warn27.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index a507c894449..370d943a6df 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,27 @@ +2019-08-14 Bob Duff + + * sem_prag.ads, sem_prag.adb + (Process_Compile_Time_Warning_Or_Error): In parameterless + version, improve detection of whether we are in a generic unit + to cover the case of an instance within a generic unit. + (Process_Compile_Time_Warning_Or_Error): Rename the + two-parameter version to be + Validate_Compile_Time_Warning_Or_Error, and do not export it. + Issue a warning if the condition is not known at compile time. + The key point is that the warning must be given only for pragmas + deferred to the back end, because the back end discovers + additional values that are known at compile time. Previous + changes in this ticket have enabled this by deferring to the + back end without checking for special cases such as 'Size. + (Validate_Compile_Time_Warning_Or_Error): Rename to be + Defer_Compile_Time_Warning_Error_To_BE. + * warnsw.ads, warnsw.adb (Warn_On_Unknown_Compile_Time_Warning): + Add new switches -gnatw_c and -gnatw_C to control the above + warning. + * doc/gnat_ugn/building_executable_programs_with_gnat.rst: + Document new switches. + * gnat_ugn.texi: Regenerate. + 2019-08-14 Eric Botcazou * sem_ch12.adb (Might_Inline_Subp): Rework comment and restrict diff --git a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst index beceb5130ad..913d6b9f3dd 100644 --- a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst +++ b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst @@ -2972,7 +2972,7 @@ of the pragma in the :title:`GNAT_Reference_manual`). component for which no component clause is present. -.. index:: -gnatwC (gcc) +.. index:: -gnatw.C (gcc) :switch:`-gnatw.C` *Suppress warnings on missing component clauses.* @@ -2981,6 +2981,30 @@ of the pragma in the :title:`GNAT_Reference_manual`). missing a component clause in the situation described above. +.. index:: -gnatw_c (gcc) + +:switch:`-gnatw_c` + *Activate warnings on unknown condition in Compile_Time_Warning.* + + .. index:: Compile_Time_Warning + .. index:: Compile_Time_Error + + This switch activates warnings on a pragma Compile_Time_Warning + or Compile_Time_Error whose condition has a value that is not + known at compile time. + The default is that such warnings are generated. + + +.. index:: -gnatw_C (gcc) + +:switch:`-gnatw_C` + *Suppress warnings on missing component clauses.* + + This switch supresses warnings on a pragma Compile_Time_Warning + or Compile_Time_Error whose condition has a value that is not + known at compile time. + + .. index:: -gnatwd (gcc) :switch:`-gnatwd` diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi index 5f73ab7602e..3e0c857e432 100644 --- a/gcc/ada/gnat_ugn.texi +++ b/gcc/ada/gnat_ugn.texi @@ -21,7 +21,7 @@ @copying @quotation -GNAT User's Guide for Native Platforms , Jul 31, 2019 +GNAT User's Guide for Native Platforms , Aug 01, 2019 AdaCore @@ -11208,7 +11208,7 @@ majority, but not all, of the components. A warning is given for each component for which no component clause is present. @end table -@geindex -gnatwC (gcc) +@geindex -gnatw.C (gcc) @table @asis @@ -11221,6 +11221,39 @@ This switch suppresses warnings for record components that are missing a component clause in the situation described above. @end table +@geindex -gnatw_c (gcc) + + +@table @asis + +@item @code{-gnatw_c} + +@emph{Activate warnings on unknown condition in Compile_Time_Warning.} + +@geindex Compile_Time_Warning + +@geindex Compile_Time_Error + +This switch activates warnings on a pragma Compile_Time_Warning +or Compile_Time_Error whose condition has a value that is not +known at compile time. +The default is that such warnings are generated. +@end table + +@geindex -gnatw_C (gcc) + + +@table @asis + +@item @code{-gnatw_C} + +@emph{Suppress warnings on missing component clauses.} + +This switch supresses warnings on a pragma Compile_Time_Warning +or Compile_Time_Error whose condition has a value that is not +known at compile time. +@end table + @geindex -gnatwd (gcc) @@ -20919,7 +20952,6 @@ This section presents several topics related to program performance. It first describes some of the tradeoffs that need to be considered and some of the techniques for making your program run faster. - It then documents the unused subprogram/data elimination feature, which can reduce the size of program executables. @@ -22274,9 +22306,8 @@ appropriate options. @geindex Checks (overflow) - @node Overflow Check Handling in GNAT,Performing Dimensionality Analysis in GNAT,Improving Performance,GNAT and Program Execution -@anchor{gnat_ugn/gnat_and_program_execution id50}@anchor{169}@anchor{gnat_ugn/gnat_and_program_execution overflow-check-handling-in-gnat}@anchor{27} +@anchor{gnat_ugn/gnat_and_program_execution id45}@anchor{169}@anchor{gnat_ugn/gnat_and_program_execution overflow-check-handling-in-gnat}@anchor{27} @section Overflow Check Handling in GNAT @@ -22292,7 +22323,7 @@ This section explains how to control the handling of overflow checks. @end menu @node Background,Management of Overflows in GNAT,,Overflow Check Handling in GNAT -@anchor{gnat_ugn/gnat_and_program_execution id51}@anchor{1bb}@anchor{gnat_ugn/gnat_and_program_execution background}@anchor{1bc} +@anchor{gnat_ugn/gnat_and_program_execution id46}@anchor{1bb}@anchor{gnat_ugn/gnat_and_program_execution background}@anchor{1bc} @subsection Background @@ -22418,7 +22449,7 @@ exception raised because of the intermediate overflow (and we really would prefer this precondition to be considered True at run time). @node Management of Overflows in GNAT,Specifying the Desired Mode,Background,Overflow Check Handling in GNAT -@anchor{gnat_ugn/gnat_and_program_execution management-of-overflows-in-gnat}@anchor{1bd}@anchor{gnat_ugn/gnat_and_program_execution id52}@anchor{1be} +@anchor{gnat_ugn/gnat_and_program_execution id47}@anchor{1bd}@anchor{gnat_ugn/gnat_and_program_execution management-of-overflows-in-gnat}@anchor{1be} @subsection Management of Overflows in GNAT @@ -22532,7 +22563,7 @@ out in the normal manner (with infinite values always failing all range checks). @node Specifying the Desired Mode,Default Settings,Management of Overflows in GNAT,Overflow Check Handling in GNAT -@anchor{gnat_ugn/gnat_and_program_execution specifying-the-desired-mode}@anchor{f8}@anchor{gnat_ugn/gnat_and_program_execution id53}@anchor{1bf} +@anchor{gnat_ugn/gnat_and_program_execution specifying-the-desired-mode}@anchor{f8}@anchor{gnat_ugn/gnat_and_program_execution id48}@anchor{1bf} @subsection Specifying the Desired Mode @@ -22656,7 +22687,7 @@ causing all intermediate operations to be computed using the base type (@code{STRICT} mode). @node Default Settings,Implementation Notes,Specifying the Desired Mode,Overflow Check Handling in GNAT -@anchor{gnat_ugn/gnat_and_program_execution id54}@anchor{1c0}@anchor{gnat_ugn/gnat_and_program_execution default-settings}@anchor{1c1} +@anchor{gnat_ugn/gnat_and_program_execution id49}@anchor{1c0}@anchor{gnat_ugn/gnat_and_program_execution default-settings}@anchor{1c1} @subsection Default Settings @@ -22703,7 +22734,7 @@ checking, but it has no effect on the method used for computing intermediate results. @node Implementation Notes,,Default Settings,Overflow Check Handling in GNAT -@anchor{gnat_ugn/gnat_and_program_execution id55}@anchor{1c2}@anchor{gnat_ugn/gnat_and_program_execution implementation-notes}@anchor{1c3} +@anchor{gnat_ugn/gnat_and_program_execution implementation-notes}@anchor{1c2}@anchor{gnat_ugn/gnat_and_program_execution id50}@anchor{1c3} @subsection Implementation Notes @@ -22751,7 +22782,7 @@ platforms for which @code{Long_Long_Integer} is 64-bits (nearly all GNAT platforms). @node Performing Dimensionality Analysis in GNAT,Stack Related Facilities,Overflow Check Handling in GNAT,GNAT and Program Execution -@anchor{gnat_ugn/gnat_and_program_execution id56}@anchor{16a}@anchor{gnat_ugn/gnat_and_program_execution performing-dimensionality-analysis-in-gnat}@anchor{28} +@anchor{gnat_ugn/gnat_and_program_execution performing-dimensionality-analysis-in-gnat}@anchor{28}@anchor{gnat_ugn/gnat_and_program_execution id51}@anchor{16a} @section Performing Dimensionality Analysis in GNAT @@ -23138,7 +23169,7 @@ passing (the dimension vector for the actual parameter must be equal to the dimension vector for the formal parameter). @node Stack Related Facilities,Memory Management Issues,Performing Dimensionality Analysis in GNAT,GNAT and Program Execution -@anchor{gnat_ugn/gnat_and_program_execution id57}@anchor{16b}@anchor{gnat_ugn/gnat_and_program_execution stack-related-facilities}@anchor{29} +@anchor{gnat_ugn/gnat_and_program_execution stack-related-facilities}@anchor{29}@anchor{gnat_ugn/gnat_and_program_execution id52}@anchor{16b} @section Stack Related Facilities @@ -23154,7 +23185,7 @@ particular, it deals with dynamic and static stack usage measurements. @end menu @node Stack Overflow Checking,Static Stack Usage Analysis,,Stack Related Facilities -@anchor{gnat_ugn/gnat_and_program_execution id58}@anchor{1c4}@anchor{gnat_ugn/gnat_and_program_execution stack-overflow-checking}@anchor{f4} +@anchor{gnat_ugn/gnat_and_program_execution id53}@anchor{1c4}@anchor{gnat_ugn/gnat_and_program_execution stack-overflow-checking}@anchor{f4} @subsection Stack Overflow Checking @@ -23199,7 +23230,7 @@ Consequently, to modify the size of the environment task please refer to your operating system documentation. @node Static Stack Usage Analysis,Dynamic Stack Usage Analysis,Stack Overflow Checking,Stack Related Facilities -@anchor{gnat_ugn/gnat_and_program_execution static-stack-usage-analysis}@anchor{f5}@anchor{gnat_ugn/gnat_and_program_execution id59}@anchor{1c5} +@anchor{gnat_ugn/gnat_and_program_execution id54}@anchor{1c5}@anchor{gnat_ugn/gnat_and_program_execution static-stack-usage-analysis}@anchor{f5} @subsection Static Stack Usage Analysis @@ -23248,7 +23279,7 @@ subprogram whose stack usage might be larger than the specified amount of bytes. The wording is in keeping with the qualifier documented above. @node Dynamic Stack Usage Analysis,,Static Stack Usage Analysis,Stack Related Facilities -@anchor{gnat_ugn/gnat_and_program_execution dynamic-stack-usage-analysis}@anchor{122}@anchor{gnat_ugn/gnat_and_program_execution id60}@anchor{1c6} +@anchor{gnat_ugn/gnat_and_program_execution id55}@anchor{1c6}@anchor{gnat_ugn/gnat_and_program_execution dynamic-stack-usage-analysis}@anchor{122} @subsection Dynamic Stack Usage Analysis @@ -23327,7 +23358,7 @@ The package @code{GNAT.Task_Stack_Usage} provides facilities to get stack-usage reports at run time. See its body for the details. @node Memory Management Issues,,Stack Related Facilities,GNAT and Program Execution -@anchor{gnat_ugn/gnat_and_program_execution id61}@anchor{16c}@anchor{gnat_ugn/gnat_and_program_execution memory-management-issues}@anchor{2a} +@anchor{gnat_ugn/gnat_and_program_execution id56}@anchor{16c}@anchor{gnat_ugn/gnat_and_program_execution memory-management-issues}@anchor{2a} @section Memory Management Issues @@ -23343,7 +23374,7 @@ incorrect uses of access values (including 'dangling references'). @end menu @node Some Useful Memory Pools,The GNAT Debug Pool Facility,,Memory Management Issues -@anchor{gnat_ugn/gnat_and_program_execution id62}@anchor{1c7}@anchor{gnat_ugn/gnat_and_program_execution some-useful-memory-pools}@anchor{1c8} +@anchor{gnat_ugn/gnat_and_program_execution id57}@anchor{1c7}@anchor{gnat_ugn/gnat_and_program_execution some-useful-memory-pools}@anchor{1c8} @subsection Some Useful Memory Pools @@ -23424,7 +23455,7 @@ for T1'Storage_Size use 10_000; @end quotation @node The GNAT Debug Pool Facility,,Some Useful Memory Pools,Memory Management Issues -@anchor{gnat_ugn/gnat_and_program_execution id63}@anchor{1c9}@anchor{gnat_ugn/gnat_and_program_execution the-gnat-debug-pool-facility}@anchor{1ca} +@anchor{gnat_ugn/gnat_and_program_execution id58}@anchor{1c9}@anchor{gnat_ugn/gnat_and_program_execution the-gnat-debug-pool-facility}@anchor{1ca} @subsection The GNAT Debug Pool Facility diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index f4c07a35106..035b0eee1f4 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -299,11 +299,20 @@ package body Sem_Prag is -- pragma. Entity name for unit and its parents is taken from item in -- previous with_clause that mentions the unit. - procedure Validate_Compile_Time_Warning_Error (N : Node_Id); + procedure Validate_Compile_Time_Warning_Or_Error + (N : Node_Id; + Eloc : Source_Ptr); + -- Common processing for Compile_Time_Error and Compile_Time_Warning of + -- pragma N. Called when the pragma is processed as part of its regular + -- analysis but also called after calling the back end to validate these + -- pragmas for size and alignment appropriateness. + + procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id); -- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean - -- expression is not known at compile time. This procedure makes an entry - -- in a table. The actual checking is performed by Validate_Compile_Time_ - -- Warning_Errors, which is invoked after calling the back end. + -- expression is not known at compile time during the front end. This + -- procedure makes an entry in a table. The actual checking is performed by + -- Validate_Compile_Time_Warning_Errors, which is invoked after calling the + -- back end. Dummy : Integer := 0; pragma Volatile (Dummy); @@ -323,13 +332,13 @@ package body Sem_Prag is -- pragma in the source program, a breakpoint on rv catches this place in -- the source, allowing convenient stepping to the point of interest. - --------------------------------------------------- - -- Table for Validate_Compile_Time_Warning_Error -- - --------------------------------------------------- + ------------------------------------------------------ + -- Table for Defer_Compile_Time_Warning_Error_To_BE -- + ------------------------------------------------------ -- The following table collects pragmas Compile_Time_Error and Compile_ -- Time_Warning for validation. Entries are made by calls to subprogram - -- Validate_Compile_Time_Warning_Error, and the call to the procedure + -- Defer_Compile_Time_Warning_Error_To_BE, and the call to the procedure -- Validate_Compile_Time_Warning_Errors does the actual error checking -- and posting of warning and error messages. The reason for this delayed -- processing is to take advantage of back-annotations of attributes size @@ -7598,6 +7607,7 @@ package body Sem_Prag is ------------------------------------------- procedure Process_Compile_Time_Warning_Or_Error is + P : Node_Id := Parent (N); Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1); begin -- In GNATprove mode, pragmas Compile_Time_Error and @@ -7616,18 +7626,29 @@ package body Sem_Prag is Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String); Analyze_And_Resolve (Arg1x, Standard_Boolean); - -- If the condition is known at compile time (now), process it now. + -- If the condition is known at compile time (now), validate it now. -- Otherwise, register the expression for validation after the back -- end has been called, because it might be known at compile time -- then. For example, if the expression is "Record_Type'Size /= 32" -- it might be known after the back end has determined the size of - -- Record_Type. We do not defer processing if we're inside a generic + -- Record_Type. We do not defer validation if we're inside a generic -- unit, because we will have more information in the instances. if Compile_Time_Known_Value (Arg1x) then - Process_Compile_Time_Warning_Or_Error (N, Sloc (Arg1)); - elsif not Inside_A_Generic then - Validate_Compile_Time_Warning_Error (N); + Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1)); + else + while Present (P) and then Nkind (P) not in N_Generic_Declaration + loop + if Nkind_In (P, N_Package_Body, N_Subprogram_Body) then + P := Corresponding_Spec (P); + else + P := Parent (P); + end if; + end loop; + + if No (P) then + Defer_Compile_Time_Warning_Error_To_BE (N); + end if; end if; end Process_Compile_Time_Warning_Or_Error; @@ -31419,11 +31440,11 @@ package body Sem_Prag is end Process_Compilation_Unit_Pragmas; - ------------------------------------------- - -- Process_Compile_Time_Warning_Or_Error -- - ------------------------------------------- + -------------------------------------------- + -- Validate_Compile_Time_Warning_Or_Error -- + -------------------------------------------- - procedure Process_Compile_Time_Warning_Or_Error + procedure Validate_Compile_Time_Warning_Or_Error (N : Node_Id; Eloc : Source_Ptr) is @@ -31530,8 +31551,16 @@ package body Sem_Prag is end loop; end; end if; + + -- Arg1x is not known at compile time, so issue a warning. This can + -- happen only if the pragma's processing was deferred until after the + -- back end is run (see Process_Compile_Time_Warning_Or_Error). + -- Note that the warning control switch applies to both pragmas. + + elsif Warn_On_Unknown_Compile_Time_Warning then + Error_Msg_N ("?condition is not known at compile time", Arg1x); end if; - end Process_Compile_Time_Warning_Or_Error; + end Validate_Compile_Time_Warning_Or_Error; ------------------------------------ -- Record_Possible_Body_Reference -- @@ -32094,17 +32123,17 @@ package body Sem_Prag is end Test_Case_Arg; ----------------------------------------- - -- Validate_Compile_Time_Warning_Error -- + -- Defer_Compile_Time_Warning_Error_To_BE -- ----------------------------------------- - procedure Validate_Compile_Time_Warning_Error (N : Node_Id) is + procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id) is Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N)); begin Compile_Time_Warnings_Errors.Append (New_Val => CTWE_Entry'(Eloc => Sloc (Arg1), Scope => Current_Scope, Prag => N)); - end Validate_Compile_Time_Warning_Error; + end Defer_Compile_Time_Warning_Error_To_BE; ------------------------------------------ -- Validate_Compile_Time_Warning_Errors -- @@ -32158,7 +32187,7 @@ package body Sem_Prag is begin Set_Scope (T.Scope); Reset_Analyzed_Flags (T.Prag); - Process_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc); + Validate_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc); Unset_Scope (T.Scope); end; end loop; diff --git a/gcc/ada/sem_prag.ads b/gcc/ada/sem_prag.ads index 4978299c4f0..88c103aa9d4 100644 --- a/gcc/ada/sem_prag.ads +++ b/gcc/ada/sem_prag.ads @@ -499,14 +499,6 @@ package Sem_Prag is -- Name_uInvariant, and Name_uType_Invariant (_Pre, _Post, _Invariant, -- and _Type_Invariant). - procedure Process_Compile_Time_Warning_Or_Error - (N : Node_Id; - Eloc : Source_Ptr); - -- Common processing for Compile_Time_Error and Compile_Time_Warning of - -- pragma N. Called when the pragma is processed as part of its regular - -- analysis but also called after calling the back end to validate these - -- pragmas for size and alignment appropriateness. - procedure Process_Compilation_Unit_Pragmas (N : Node_Id); -- Called at the start of processing compilation unit N to deal with any -- special issues regarding pragmas. In particular, we have to deal with diff --git a/gcc/ada/warnsw.adb b/gcc/ada/warnsw.adb index 219d440bc87..a7319073c15 100644 --- a/gcc/ada/warnsw.adb +++ b/gcc/ada/warnsw.adb @@ -43,53 +43,54 @@ package body Warnsw is procedure All_Warnings (Setting : Boolean) is begin - Address_Clause_Overlay_Warnings := Setting; - Check_Unreferenced := Setting; - Check_Unreferenced_Formals := Setting; - Check_Withs := Setting; - Constant_Condition_Warnings := Setting; - Elab_Warnings := Setting; - Implementation_Unit_Warnings := Setting; - Ineffective_Inline_Warnings := Setting; - List_Body_Required_Info := Setting; - List_Inherited_Aspects := Setting; - Warn_On_Ada_2005_Compatibility := Setting; - Warn_On_Ada_2012_Compatibility := Setting; - Warn_On_All_Unread_Out_Parameters := Setting; - Warn_On_Anonymous_Allocators := Setting; - Warn_On_Assertion_Failure := Setting; - Warn_On_Assumed_Low_Bound := Setting; - Warn_On_Atomic_Synchronization := Setting; - Warn_On_Bad_Fixed_Value := Setting; - Warn_On_Biased_Representation := Setting; - Warn_On_Constant := Setting; - Warn_On_Deleted_Code := Setting; - Warn_On_Dereference := Setting; - Warn_On_Export_Import := Setting; - Warn_On_Hiding := Setting; - Warn_On_Late_Primitives := Setting; - Warn_On_Modified_Unread := Setting; - Warn_On_No_Value_Assigned := Setting; - Warn_On_Non_Local_Exception := Setting; - Warn_On_Object_Renames_Function := Setting; - Warn_On_Obsolescent_Feature := Setting; - Warn_On_Overlap := Setting; - Warn_On_Overridden_Size := Setting; - Warn_On_Parameter_Order := Setting; - Warn_On_Questionable_Layout := Setting; - Warn_On_Questionable_Missing_Parens := Setting; - Warn_On_Record_Holes := Setting; - Warn_On_Redundant_Constructs := Setting; - Warn_On_Reverse_Bit_Order := Setting; - Warn_On_Size_Alignment := Setting; - Warn_On_Standard_Redefinition := Setting; - Warn_On_Suspicious_Contract := Setting; - Warn_On_Suspicious_Modulus_Value := Setting; - Warn_On_Unchecked_Conversion := Setting; - Warn_On_Unordered_Enumeration_Type := Setting; - Warn_On_Unrecognized_Pragma := Setting; - Warn_On_Unrepped_Components := Setting; - Warn_On_Warnings_Off := Setting; + Address_Clause_Overlay_Warnings := Setting; + Check_Unreferenced := Setting; + Check_Unreferenced_Formals := Setting; + Check_Withs := Setting; + Constant_Condition_Warnings := Setting; + Elab_Warnings := Setting; + Implementation_Unit_Warnings := Setting; + Ineffective_Inline_Warnings := Setting; + List_Body_Required_Info := Setting; + List_Inherited_Aspects := Setting; + Warn_On_Ada_2005_Compatibility := Setting; + Warn_On_Ada_2012_Compatibility := Setting; + Warn_On_All_Unread_Out_Parameters := Setting; + Warn_On_Anonymous_Allocators := Setting; + Warn_On_Assertion_Failure := Setting; + Warn_On_Assumed_Low_Bound := Setting; + Warn_On_Atomic_Synchronization := Setting; + Warn_On_Bad_Fixed_Value := Setting; + Warn_On_Biased_Representation := Setting; + Warn_On_Constant := Setting; + Warn_On_Deleted_Code := Setting; + Warn_On_Dereference := Setting; + Warn_On_Export_Import := Setting; + Warn_On_Hiding := Setting; + Warn_On_Late_Primitives := Setting; + Warn_On_Modified_Unread := Setting; + Warn_On_No_Value_Assigned := Setting; + Warn_On_Non_Local_Exception := Setting; + Warn_On_Object_Renames_Function := Setting; + Warn_On_Obsolescent_Feature := Setting; + Warn_On_Overlap := Setting; + Warn_On_Overridden_Size := Setting; + Warn_On_Parameter_Order := Setting; + Warn_On_Questionable_Layout := Setting; + Warn_On_Questionable_Missing_Parens := Setting; + Warn_On_Record_Holes := Setting; + Warn_On_Redundant_Constructs := Setting; + Warn_On_Reverse_Bit_Order := Setting; + Warn_On_Size_Alignment := Setting; + Warn_On_Standard_Redefinition := Setting; + Warn_On_Suspicious_Contract := Setting; + Warn_On_Suspicious_Modulus_Value := Setting; + Warn_On_Unchecked_Conversion := Setting; + Warn_On_Unknown_Compile_Time_Warning := Setting; + Warn_On_Unordered_Enumeration_Type := Setting; + Warn_On_Unrecognized_Pragma := Setting; + Warn_On_Unrepped_Components := Setting; + Warn_On_Warnings_Off := Setting; end All_Warnings; ---------------------- @@ -98,103 +99,105 @@ package body Warnsw is procedure Restore_Warnings (W : Warning_Record) is begin - Address_Clause_Overlay_Warnings := + Address_Clause_Overlay_Warnings := W.Address_Clause_Overlay_Warnings; - Check_Unreferenced := + Check_Unreferenced := W.Check_Unreferenced; - Check_Unreferenced_Formals := + Check_Unreferenced_Formals := W.Check_Unreferenced_Formals; - Check_Withs := + Check_Withs := W.Check_Withs; - Constant_Condition_Warnings := + Constant_Condition_Warnings := W.Constant_Condition_Warnings; - Elab_Warnings := + Elab_Warnings := W.Elab_Warnings; - Elab_Info_Messages := + Elab_Info_Messages := W.Elab_Info_Messages; - Implementation_Unit_Warnings := + Implementation_Unit_Warnings := W.Implementation_Unit_Warnings; - Ineffective_Inline_Warnings := + Ineffective_Inline_Warnings := W.Ineffective_Inline_Warnings; - List_Body_Required_Info := + List_Body_Required_Info := W.List_Body_Required_Info; - List_Inherited_Aspects := + List_Inherited_Aspects := W.List_Inherited_Aspects; - No_Warn_On_Non_Local_Exception := + No_Warn_On_Non_Local_Exception := W.No_Warn_On_Non_Local_Exception; - Warning_Doc_Switch := + Warning_Doc_Switch := W.Warning_Doc_Switch; - Warn_On_Ada_2005_Compatibility := + Warn_On_Ada_2005_Compatibility := W.Warn_On_Ada_2005_Compatibility; - Warn_On_Ada_2012_Compatibility := + Warn_On_Ada_2012_Compatibility := W.Warn_On_Ada_2012_Compatibility; - Warn_On_All_Unread_Out_Parameters := + Warn_On_All_Unread_Out_Parameters := W.Warn_On_All_Unread_Out_Parameters; - Warn_On_Anonymous_Allocators := + Warn_On_Anonymous_Allocators := W.Warn_On_Anonymous_Allocators; - Warn_On_Assertion_Failure := + Warn_On_Assertion_Failure := W.Warn_On_Assertion_Failure; - Warn_On_Assumed_Low_Bound := + Warn_On_Assumed_Low_Bound := W.Warn_On_Assumed_Low_Bound; - Warn_On_Atomic_Synchronization := + Warn_On_Atomic_Synchronization := W.Warn_On_Atomic_Synchronization; - Warn_On_Bad_Fixed_Value := + Warn_On_Bad_Fixed_Value := W.Warn_On_Bad_Fixed_Value; - Warn_On_Biased_Representation := + Warn_On_Biased_Representation := W.Warn_On_Biased_Representation; - Warn_On_Constant := + Warn_On_Constant := W.Warn_On_Constant; - Warn_On_Deleted_Code := + Warn_On_Deleted_Code := W.Warn_On_Deleted_Code; - Warn_On_Dereference := + Warn_On_Dereference := W.Warn_On_Dereference; - Warn_On_Export_Import := + Warn_On_Export_Import := W.Warn_On_Export_Import; - Warn_On_Hiding := + Warn_On_Hiding := W.Warn_On_Hiding; - Warn_On_Late_Primitives := + Warn_On_Late_Primitives := W.Warn_On_Late_Primitives; - Warn_On_Modified_Unread := + Warn_On_Modified_Unread := W.Warn_On_Modified_Unread; - Warn_On_No_Value_Assigned := + Warn_On_No_Value_Assigned := W.Warn_On_No_Value_Assigned; - Warn_On_Non_Local_Exception := + Warn_On_Non_Local_Exception := W.Warn_On_Non_Local_Exception; - Warn_On_Object_Renames_Function := + Warn_On_Object_Renames_Function := W.Warn_On_Object_Renames_Function; - Warn_On_Obsolescent_Feature := + Warn_On_Obsolescent_Feature := W.Warn_On_Obsolescent_Feature; - Warn_On_Overlap := + Warn_On_Overlap := W.Warn_On_Overlap; - Warn_On_Overridden_Size := + Warn_On_Overridden_Size := W.Warn_On_Overridden_Size; - Warn_On_Parameter_Order := + Warn_On_Parameter_Order := W.Warn_On_Parameter_Order; - Warn_On_Questionable_Layout := + Warn_On_Questionable_Layout := W.Warn_On_Questionable_Layout; - Warn_On_Questionable_Missing_Parens := + Warn_On_Questionable_Missing_Parens := W.Warn_On_Questionable_Missing_Parens; - Warn_On_Record_Holes := + Warn_On_Record_Holes := W.Warn_On_Record_Holes; - Warn_On_Redundant_Constructs := + Warn_On_Redundant_Constructs := W.Warn_On_Redundant_Constructs; - Warn_On_Reverse_Bit_Order := + Warn_On_Reverse_Bit_Order := W.Warn_On_Reverse_Bit_Order; - Warn_On_Size_Alignment := + Warn_On_Size_Alignment := W.Warn_On_Size_Alignment; - Warn_On_Standard_Redefinition := + Warn_On_Standard_Redefinition := W.Warn_On_Standard_Redefinition; - Warn_On_Suspicious_Contract := + Warn_On_Suspicious_Contract := W.Warn_On_Suspicious_Contract; - Warn_On_Unchecked_Conversion := + Warn_On_Unchecked_Conversion := W.Warn_On_Unchecked_Conversion; - Warn_On_Unordered_Enumeration_Type := + Warn_On_Unknown_Compile_Time_Warning := + W.Warn_On_Unknown_Compile_Time_Warning; + Warn_On_Unordered_Enumeration_Type := W.Warn_On_Unordered_Enumeration_Type; - Warn_On_Unrecognized_Pragma := + Warn_On_Unrecognized_Pragma := W.Warn_On_Unrecognized_Pragma; - Warn_On_Unrepped_Components := + Warn_On_Unrepped_Components := W.Warn_On_Unrepped_Components; - Warn_On_Warnings_Off := + Warn_On_Warnings_Off := W.Warn_On_Warnings_Off; end Restore_Warnings; @@ -206,103 +209,105 @@ package body Warnsw is W : Warning_Record; begin - W.Address_Clause_Overlay_Warnings := + W.Address_Clause_Overlay_Warnings := Address_Clause_Overlay_Warnings; - W.Check_Unreferenced := + W.Check_Unreferenced := Check_Unreferenced; - W.Check_Unreferenced_Formals := + W.Check_Unreferenced_Formals := Check_Unreferenced_Formals; - W.Check_Withs := + W.Check_Withs := Check_Withs; - W.Constant_Condition_Warnings := + W.Constant_Condition_Warnings := Constant_Condition_Warnings; - W.Elab_Info_Messages := + W.Elab_Info_Messages := Elab_Info_Messages; - W.Elab_Warnings := + W.Elab_Warnings := Elab_Warnings; - W.Implementation_Unit_Warnings := + W.Implementation_Unit_Warnings := Implementation_Unit_Warnings; - W.Ineffective_Inline_Warnings := + W.Ineffective_Inline_Warnings := Ineffective_Inline_Warnings; - W.List_Body_Required_Info := + W.List_Body_Required_Info := List_Body_Required_Info; - W.List_Inherited_Aspects := + W.List_Inherited_Aspects := List_Inherited_Aspects; - W.No_Warn_On_Non_Local_Exception := + W.No_Warn_On_Non_Local_Exception := No_Warn_On_Non_Local_Exception; - W.Warning_Doc_Switch := + W.Warning_Doc_Switch := Warning_Doc_Switch; - W.Warn_On_Ada_2005_Compatibility := + W.Warn_On_Ada_2005_Compatibility := Warn_On_Ada_2005_Compatibility; - W.Warn_On_Ada_2012_Compatibility := + W.Warn_On_Ada_2012_Compatibility := Warn_On_Ada_2012_Compatibility; - W.Warn_On_All_Unread_Out_Parameters := + W.Warn_On_All_Unread_Out_Parameters := Warn_On_All_Unread_Out_Parameters; - W.Warn_On_Anonymous_Allocators := + W.Warn_On_Anonymous_Allocators := Warn_On_Anonymous_Allocators; - W.Warn_On_Assertion_Failure := + W.Warn_On_Assertion_Failure := Warn_On_Assertion_Failure; - W.Warn_On_Assumed_Low_Bound := + W.Warn_On_Assumed_Low_Bound := Warn_On_Assumed_Low_Bound; - W.Warn_On_Atomic_Synchronization := + W.Warn_On_Atomic_Synchronization := Warn_On_Atomic_Synchronization; - W.Warn_On_Bad_Fixed_Value := + W.Warn_On_Bad_Fixed_Value := Warn_On_Bad_Fixed_Value; - W.Warn_On_Biased_Representation := + W.Warn_On_Biased_Representation := Warn_On_Biased_Representation; - W.Warn_On_Constant := + W.Warn_On_Constant := Warn_On_Constant; - W.Warn_On_Deleted_Code := + W.Warn_On_Deleted_Code := Warn_On_Deleted_Code; - W.Warn_On_Dereference := + W.Warn_On_Dereference := Warn_On_Dereference; - W.Warn_On_Export_Import := + W.Warn_On_Export_Import := Warn_On_Export_Import; - W.Warn_On_Hiding := + W.Warn_On_Hiding := Warn_On_Hiding; - W.Warn_On_Late_Primitives := + W.Warn_On_Late_Primitives := Warn_On_Late_Primitives; - W.Warn_On_Modified_Unread := + W.Warn_On_Modified_Unread := Warn_On_Modified_Unread; - W.Warn_On_No_Value_Assigned := + W.Warn_On_No_Value_Assigned := Warn_On_No_Value_Assigned; - W.Warn_On_Non_Local_Exception := + W.Warn_On_Non_Local_Exception := Warn_On_Non_Local_Exception; - W.Warn_On_Object_Renames_Function := + W.Warn_On_Object_Renames_Function := Warn_On_Object_Renames_Function; - W.Warn_On_Obsolescent_Feature := + W.Warn_On_Obsolescent_Feature := Warn_On_Obsolescent_Feature; - W.Warn_On_Overlap := + W.Warn_On_Overlap := Warn_On_Overlap; - W.Warn_On_Overridden_Size := + W.Warn_On_Overridden_Size := Warn_On_Overridden_Size; - W.Warn_On_Parameter_Order := + W.Warn_On_Parameter_Order := Warn_On_Parameter_Order; - W.Warn_On_Questionable_Layout := + W.Warn_On_Questionable_Layout := Warn_On_Questionable_Layout; - W.Warn_On_Questionable_Missing_Parens := + W.Warn_On_Questionable_Missing_Parens := Warn_On_Questionable_Missing_Parens; - W.Warn_On_Record_Holes := + W.Warn_On_Record_Holes := Warn_On_Record_Holes; - W.Warn_On_Redundant_Constructs := + W.Warn_On_Redundant_Constructs := Warn_On_Redundant_Constructs; - W.Warn_On_Reverse_Bit_Order := + W.Warn_On_Reverse_Bit_Order := Warn_On_Reverse_Bit_Order; - W.Warn_On_Size_Alignment := + W.Warn_On_Size_Alignment := Warn_On_Size_Alignment; - W.Warn_On_Standard_Redefinition := + W.Warn_On_Standard_Redefinition := Warn_On_Standard_Redefinition; - W.Warn_On_Suspicious_Contract := + W.Warn_On_Suspicious_Contract := Warn_On_Suspicious_Contract; - W.Warn_On_Unchecked_Conversion := + W.Warn_On_Unchecked_Conversion := Warn_On_Unchecked_Conversion; - W.Warn_On_Unordered_Enumeration_Type := + W.Warn_On_Unknown_Compile_Time_Warning := + Warn_On_Unknown_Compile_Time_Warning; + W.Warn_On_Unordered_Enumeration_Type := Warn_On_Unordered_Enumeration_Type; - W.Warn_On_Unrecognized_Pragma := + W.Warn_On_Unrecognized_Pragma := Warn_On_Unrecognized_Pragma; - W.Warn_On_Unrepped_Components := + W.Warn_On_Unrepped_Components := Warn_On_Unrepped_Components; - W.Warn_On_Warnings_Off := + W.Warn_On_Warnings_Off := Warn_On_Warnings_Off; return W; end Save_Warnings; @@ -489,6 +494,12 @@ package body Warnsw is when 'A' => Warn_On_Anonymous_Allocators := False; + when 'c' => + Warn_On_Unknown_Compile_Time_Warning := True; + + when 'C' => + Warn_On_Unknown_Compile_Time_Warning := False; + when others => if Ignore_Unrecognized_VWY_Switches then Write_Line ("unrecognized switch -gnatw_" & C & " ignored"); diff --git a/gcc/ada/warnsw.ads b/gcc/ada/warnsw.ads index 422f8df66da..f96c11c3b80 100644 --- a/gcc/ada/warnsw.ads +++ b/gcc/ada/warnsw.ads @@ -48,6 +48,10 @@ package Warnsw is -- Warn when tagged type public primitives are defined after its private -- extensions. + Warn_On_Unknown_Compile_Time_Warning : Boolean := True; + -- Warn on a pragma Compile_Time_Warning or Compile_Time_Error whose + -- condition has a value that is not known at compile time. + Warn_On_Overridden_Size : Boolean := False; -- Warn when explicit record component clause or array component_size -- clause specifies a size that overrides a size for the type which was @@ -80,56 +84,57 @@ package Warnsw is -- Type used to save and restore warnings type Warning_Record is record - Address_Clause_Overlay_Warnings : Boolean; - Check_Unreferenced : Boolean; - Check_Unreferenced_Formals : Boolean; - Check_Withs : Boolean; - Constant_Condition_Warnings : Boolean; - Elab_Info_Messages : Boolean; - Elab_Warnings : Boolean; - Implementation_Unit_Warnings : Boolean; - Ineffective_Inline_Warnings : Boolean; - List_Body_Required_Info : Boolean; - List_Inherited_Aspects : Boolean; - No_Warn_On_Non_Local_Exception : Boolean; - Warning_Doc_Switch : Boolean; - Warn_On_Ada_2005_Compatibility : Boolean; - Warn_On_Ada_2012_Compatibility : Boolean; - Warn_On_All_Unread_Out_Parameters : Boolean; - Warn_On_Anonymous_Allocators : Boolean; - Warn_On_Assertion_Failure : Boolean; - Warn_On_Assumed_Low_Bound : Boolean; - Warn_On_Atomic_Synchronization : Boolean; - Warn_On_Bad_Fixed_Value : Boolean; - Warn_On_Biased_Representation : Boolean; - Warn_On_Constant : Boolean; - Warn_On_Deleted_Code : Boolean; - Warn_On_Dereference : Boolean; - Warn_On_Export_Import : Boolean; - Warn_On_Hiding : Boolean; - Warn_On_Late_Primitives : Boolean; - Warn_On_Modified_Unread : Boolean; - Warn_On_No_Value_Assigned : Boolean; - Warn_On_Non_Local_Exception : Boolean; - Warn_On_Object_Renames_Function : Boolean; - Warn_On_Obsolescent_Feature : Boolean; - Warn_On_Overlap : Boolean; - Warn_On_Overridden_Size : Boolean; - Warn_On_Parameter_Order : Boolean; - Warn_On_Questionable_Layout : Boolean; - Warn_On_Questionable_Missing_Parens : Boolean; - Warn_On_Record_Holes : Boolean; - Warn_On_Redundant_Constructs : Boolean; - Warn_On_Reverse_Bit_Order : Boolean; - Warn_On_Size_Alignment : Boolean; - Warn_On_Standard_Redefinition : Boolean; - Warn_On_Suspicious_Contract : Boolean; - Warn_On_Suspicious_Modulus_Value : Boolean; - Warn_On_Unchecked_Conversion : Boolean; - Warn_On_Unordered_Enumeration_Type : Boolean; - Warn_On_Unrecognized_Pragma : Boolean; - Warn_On_Unrepped_Components : Boolean; - Warn_On_Warnings_Off : Boolean; + Address_Clause_Overlay_Warnings : Boolean; + Check_Unreferenced : Boolean; + Check_Unreferenced_Formals : Boolean; + Check_Withs : Boolean; + Constant_Condition_Warnings : Boolean; + Elab_Info_Messages : Boolean; + Elab_Warnings : Boolean; + Implementation_Unit_Warnings : Boolean; + Ineffective_Inline_Warnings : Boolean; + List_Body_Required_Info : Boolean; + List_Inherited_Aspects : Boolean; + No_Warn_On_Non_Local_Exception : Boolean; + Warning_Doc_Switch : Boolean; + Warn_On_Ada_2005_Compatibility : Boolean; + Warn_On_Ada_2012_Compatibility : Boolean; + Warn_On_All_Unread_Out_Parameters : Boolean; + Warn_On_Anonymous_Allocators : Boolean; + Warn_On_Assertion_Failure : Boolean; + Warn_On_Assumed_Low_Bound : Boolean; + Warn_On_Atomic_Synchronization : Boolean; + Warn_On_Bad_Fixed_Value : Boolean; + Warn_On_Biased_Representation : Boolean; + Warn_On_Constant : Boolean; + Warn_On_Deleted_Code : Boolean; + Warn_On_Dereference : Boolean; + Warn_On_Export_Import : Boolean; + Warn_On_Hiding : Boolean; + Warn_On_Late_Primitives : Boolean; + Warn_On_Modified_Unread : Boolean; + Warn_On_No_Value_Assigned : Boolean; + Warn_On_Non_Local_Exception : Boolean; + Warn_On_Object_Renames_Function : Boolean; + Warn_On_Obsolescent_Feature : Boolean; + Warn_On_Overlap : Boolean; + Warn_On_Overridden_Size : Boolean; + Warn_On_Parameter_Order : Boolean; + Warn_On_Questionable_Layout : Boolean; + Warn_On_Questionable_Missing_Parens : Boolean; + Warn_On_Record_Holes : Boolean; + Warn_On_Redundant_Constructs : Boolean; + Warn_On_Reverse_Bit_Order : Boolean; + Warn_On_Size_Alignment : Boolean; + Warn_On_Standard_Redefinition : Boolean; + Warn_On_Suspicious_Contract : Boolean; + Warn_On_Suspicious_Modulus_Value : Boolean; + Warn_On_Unchecked_Conversion : Boolean; + Warn_On_Unknown_Compile_Time_Warning : Boolean; + Warn_On_Unordered_Enumeration_Type : Boolean; + Warn_On_Unrecognized_Pragma : Boolean; + Warn_On_Unrepped_Components : Boolean; + Warn_On_Warnings_Off : Boolean; end record; function Save_Warnings return Warning_Record; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 857505281f9..1b0c4a5d2b0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-08-14 Bob Duff + + * gnat.dg/warn27.adb: New testcase. + 2019-08-14 Bob Duff * gnat.dg/inline19.adb, gnat.dg/inline19.ads: New testcase. diff --git a/gcc/testsuite/gnat.dg/warn27.adb b/gcc/testsuite/gnat.dg/warn27.adb new file mode 100644 index 00000000000..d4b905917ec --- /dev/null +++ b/gcc/testsuite/gnat.dg/warn27.adb @@ -0,0 +1,10 @@ +-- { dg-do compile } + +procedure Warn27 is + Dummy : Boolean; + + pragma Compile_Time_Warning (Dummy, "warning"); -- { dg-warning "condition is not known at compile time" } + pragma Compile_Time_Error (Dummy, "error"); -- { dg-warning "condition is not known at compile time" } +begin + pragma Unreferenced (Dummy); +end Warn27; -- 2.30.2