This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Tested on i686-linux, committed on trunk. This patch implements a test to see whether a variable is referenced in an exception handler, and then the useless assignment warning is suppressed if so. Compile following with gcc -c h.adb -gnatld7 -gnatwa -gnatj60 Note the lack of warnings for Phase Compiling: h.adb 1. procedure H is 2. type Phase_T is (Phase_1, Phase_2, Phase_3); 3. Phase : Phase_T; 4. PhaseX : Phase_T; 5. begin 6. Phase := Phase_1; 7. PhaseX := Phase_2; 8. Phase := PhaseX; 9. PhaseX := Phase_3; | >>> warning: useless assignment to "PhaseX", value overwritten at line 11 10. Phase := Phase_3; 11. PhaseX := Phase_3; | >>> warning: useless assignment to "PhaseX", value never referenced 12. exception 13. when others => 14. if Phase = Phase_3 then 15. raise Program_Error; 16. end if; 17. end; This patch also implements three improvements to handling of pragma Obsolescent, as shown by these examples: procedure Gtk_New; pragma Obsolescent; package op is pragma Obsolescent; procedure ff; end op; with Initialize; with op; procedure Gtk_New is begin Initialize; op.ff; end Gtk_New; procedure Initialize; pragma Obsolescent; For the above program, compiling gtk_new.ads with -gnatwa used to give error messages, but no longer does so, since we decide that obsolescent units can now call other obsolescent stuff without any complaints. The second example shows that we no longer generate redundant messages when withing an obsolescent package, we now get one message on the with (we used to get two additional messages on the use and on the call). 1. with op; use op; | >>> warning: with of obsolescent package "op" declared at op.ads:1 2. procedure m is 3. begin 4. op.ff; 5. end; Finally, this patch adds some new warnings to code statements. In particular if Volatile is not specified then a warning is given if two or more code statements appear in sequence, or if either Input or Output operands are not present. Here are examples (these are x86 specific) (compiled with -gnatlj60) 1. with System.Machine_Code; use System.Machine_Code; 2. function Exp1 (X : Long_Long_Float) return Long_Long_Float is 3. Result : Long_Long_Float := 0.0; 4. NL : constant Character := ASCII.LF; 5. begin 6. Asm (Template => | >>> warning: code statement with no inputs should usually be Volatile 7. "fldl2e " & NL 8. & "fscale ", 9. Inputs => No_Input_Operands, 10. Outputs => No_Output_Operands); 11. return Result; 12. end; 1. with System.Machine_Code; use System.Machine_Code; 2. function Exp3 (X : Long_Long_Float) return Long_Long_Float is 3. Result : Long_Long_Float; 4. NL : constant Character := ASCII.LF; 5. begin 6. Asm (Template => 2006-10-31 Robert Dewar <dewar@adacore.com> Ed Schonberg <schonberg@adacore.com> * freeze.adb: Add handling of Last_Assignment field (Warn_Overlay): Supply missing continuation marks in error msgs (Freeze_Entity): Add check for Preelaborable_Initialization * g-comlin.adb: Add Warnings (Off) to prevent new warning * g-expect.adb: Add Warnings (Off) to prevent new warning * lib-xref.adb: Add handling of Last_Assignment field (Generate_Reference): Centralize handling of pragma Obsolescent here (Generate_Reference): Accept an implicit reference generated for a default in an instance. (Generate_Reference): Accept a reference for a node that is not in the main unit, if it is the generic body corresponding to an subprogram instantiation. * xref_lib.adb: Add pragma Warnings (Off) to avoid new warnings * sem_warn.ads, sem_warn.adb (Set_Warning_Switch): Add processing for -gnatwq/Q. (Warn_On_Useless_Assignment): Suppress warning if enclosing inner exception handler. (Output_Obsolescent_Entity_Warnings): Rewrite to avoid any messages on use clauses, to avoid messages on packages used to qualify, and also to avoid messages from obsolescent units. (Warn_On_Useless_Assignments): Don't generate messages for imported and exported variables. (Warn_On_Useless_Assignments): New procedure (Output_Obsolescent_Entity_Warnings): New procedure (Check_Code_Statement): New procedure * einfo.ads, einfo.adb (Has_Static_Discriminants): New flag Change name Is_Ada_2005 to Is_Ada_2005_Only (Last_Assignment): New field for useless assignment warning
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |