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] |
Two pragmas exist - Unmodified and Unreferenced which issue warnings if the respective entities contained get written or read repectivly. Additionally, pragma Unreferenced will surpress compiler generated warnings for unread variables. However, this can lead to confusion about pragma Unreferenced whereby the assumed meaning would encompass writing as well as reading and to achive this effect both pragmas would have to be utilized which is inefficient. This patch adds a new pragma "Unused" to serve as a combination of Unmodified and Unreferenced. ------------ -- Source -- ------------ -- main.adb with Ada.Text_IO; -- Context clause pragma Unused (Ada.Text_IO); -- Warn Unused pragma Unmodified (Ada.Text_IO); -- Warn Unmodified pragma Unreferenced (Ada.Text_IO); -- Valid procedure Main is -- Improper use X, Y, Z : Boolean := False; -- Non-variable procedure Test is begin null; end; pragma Unmodified (Test); -- Warn Unmodified pragma Unused (Test); -- Warn Unused pragma Unreferenced (Test); -- Valid -- Equivalence of Unused to Unmodified + Unreferenced pragma Unmodified (X); -- Valid pragma Unmodified (X); -- Warn Unmodified pragma Unreferenced (X); -- Valid pragma Unused (Y); -- Valid -- Duplicate error messages pragma Unreferenced (X); -- Warn Unreferenced pragma Unused (X); -- Warn Unmodified and Unreferenced pragma Unused (Y); -- Warn Unused pragma Unmodified (Y); -- Warn Unused pragma Unreferenced (Y); -- Warn Unused -- Proper use A, B, C, D : Boolean := True; pragma Unmodified (A); -- Valid pragma Unreferenced (B); -- Valid pragma Unmodified (C); -- Valid pragma Unreferenced (C); -- Valid pragma Unused (D); -- Valid begin X := True; -- Warn Unmodified Z := X; -- Warn Unreferenced Y := True; -- Warn Unused Z := Y; -- Warn Unused Z := A; -- Valid B := False; -- Valid end Main; ---------------------------- -- Compilation and output -- ---------------------------- $ gcc -gnatl -c main.adb [...] 1. with Ada.Text_IO; 2. 3. -- Context clause 4. pragma Unused (Ada.Text_IO); -- Warn Unused | >>> pragma "Unused" argument must be in same declarative part 5. pragma Unmodified (Ada.Text_IO); -- Warn Unmodified | >>> pragma "Unmodified" argument must be in same declarative part 6. pragma Unreferenced (Ada.Text_IO); -- Valid 7. 8. procedure Main is 9. 10. -- Improper use 11. X, Y, Z : Boolean := False; 12. 13. -- Non-variable 14. procedure Test is begin null; end; 15. pragma Unmodified (Test); -- Warn Unmodified | >>> pragma "Unmodified" can only be applied to a variable 16. pragma Unused (Test); -- Warn Unused | >>> pragma "Unused" can only be applied to a variable 17. pragma Unreferenced (Test); -- Valid 18. 19. -- Equivalence of Unused to Unmodified + Unreferenced 20. pragma Unmodified (X); -- Valid 21. pragma Unmodified (X); -- Warn Unmodified | >>> warning: pragma Unmodified given for "X" 22. pragma Unreferenced (X); -- Valid 23. pragma Unused (Y); -- Valid 24. 25. -- Duplicate error messages 26. pragma Unreferenced (X); -- Warn Unreferenced | >>> warning: pragma Unreferenced given for "X" 27. pragma Unused (X); -- Warn Unmodified and Unreferenced | >>> warning: pragma Unmodified given for "X" >>> warning: pragma Unreferenced given for "X" 28. pragma Unused (Y); -- Warn Unused | >>> warning: pragma Unused given for "Y" 29. pragma Unmodified (Y); -- Warn Unused | >>> warning: pragma Unused given for "Y" 30. pragma Unreferenced (Y); -- Warn Unused | >>> warning: pragma Unused given for "Y" 31. 32. -- Proper use 33. A, B, C, D : Boolean := True; 34. pragma Unmodified (A); -- Valid 35. pragma Unreferenced (B); -- Valid 36. pragma Unmodified (C); -- Valid 37. pragma Unreferenced (C); -- Valid 38. pragma Unused (D); -- Valid 39. 40. begin 41. X := True; -- Warn Unmodified | >>> warning: pragma Unmodified given for "X" 42. Z := X; -- Warn Unreferenced | >>> warning: pragma Unreferenced given for "X" 43. Y := True; -- Warn Unused | >>> warning: pragma Unused given for "Y" 44. Z := Y; -- Warn Unused | >>> warning: pragma Unused given for "Y" 45. Z := A; -- Valid 46. B := False; -- Valid 47. end Main; 47 lines: 4 errors, 11 warnings Tested on x86_64-pc-linux-gnu, committed on trunk 2016-07-04 Justin Squirek <squirek@adacore.com> * einfo.adb (Has_Pragma_Unused): Create this function as a setter for a new flag294 (Set_Has_Pragma_Unused): Create this procedure as a getter for flag294 (Write_Entity_Flags): Register the new flag with an alias * einfo.ads Add comment documenting Has_Pragma_Unused (flag294) and subsequent getter and setter declarations. * lib-xref.adb (Generate_Reference): Recognize Has_Pragma_Unused flag to print appropriate warning messages. * par-prag.adb (Prag): Classify Pragma_Unused into "All Other Pragmas." * snames.ads-tmpl Add a new name to the name constants and a new pramga to Pragma_Id for pramga Unused. * sem_prag.adb (Analyze_Pragma): Create case for Pragma_Unused and move the block for Pragma_Unmodified and Pragma_Unreferenced out and into local subprograms. (Analyze_Unmodified, Analyze_Unreferenced): From the old pragma blocks that have been separated in to local subprograms add a parameter to indicate the if they are being called in the context of Pragma_Unused and handle it accordingly. (Is_Non_Significant_Pragma_Reference): Add an entry for Pragma_Unused and correct the position of Pragma_Unevaluated_Use_Of_Old. * sem_util.adb (Note_Possible_Modification): Recognize Has_Pragma_Unused flag to print appropriate warning messages.
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] |