From ae59bda92bbab1a02562683dd54fb9c287307a9e Mon Sep 17 00:00:00 2001 From: Justin Squirek Date: Thu, 11 Jul 2019 08:02:21 +0000 Subject: [PATCH] [Ada] Pragma Unreferenced triggers undefined reference This patch corrects the generation of protected body declarations so that instances of pragma Unreferenced applied to formals don't falsly trigger undefined references. 2019-07-11 Justin Squirek gcc/ada/ * exp_ch9.adb (Build_Private_Protected_Declaration): Add exception for the moving of pragmas to internally generated specs for pragma Unreferenced. gcc/testsuite/ * gnat.dg/unreferenced2.adb: New testcase. From-SVN: r273392 --- gcc/ada/ChangeLog | 6 +++++ gcc/ada/exp_ch9.adb | 11 +++++++- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gnat.dg/unreferenced2.adb | 34 +++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gnat.dg/unreferenced2.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index a39069c6f64..b51a3ccba7a 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2019-07-11 Justin Squirek + + * exp_ch9.adb (Build_Private_Protected_Declaration): Add + exception for the moving of pragmas to internally generated + specs for pragma Unreferenced. + 2019-07-11 Bob Duff * doc/gnat_ugn/gnat_utility_programs.rst: Fix inconsistent diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb index 7eb6eb5ba81..077063f5939 100644 --- a/gcc/ada/exp_ch9.adb +++ b/gcc/ada/exp_ch9.adb @@ -3493,6 +3493,8 @@ package body Exp_Ch9 is procedure Move_Pragmas (From : Node_Id; To : Node_Id); -- Find all suitable source pragmas at the top of subprogram body From's -- declarations and insert them after arbitrary node To. + -- + -- Very similar to Move_Pragmas in sem_ch6 ??? --------------------- -- Analyze_Pragmas -- @@ -3544,7 +3546,14 @@ package body Exp_Ch9 is Next_Decl := Next (Decl); - if Nkind (Decl) = N_Pragma then + -- We add an exception here for Unreferenced pragmas since the + -- internally generated spec gets analyzed within + -- Build_Private_Protected_Declaration and will lead to spurious + -- warnings due to the way references are checked. + + if Nkind (Decl) = N_Pragma + and then Pragma_Name_Unmapped (Decl) /= Name_Unreferenced + then Remove (Decl); Insert_After (Insert_Nod, Decl); Insert_Nod := Decl; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f0d066db984..eefe9881548 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-11 Justin Squirek + + * gnat.dg/unreferenced2.adb: New testcase. + 2019-07-11 Hristian Kirtchev * gnat.dg/self_ref1.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/unreferenced2.adb b/gcc/testsuite/gnat.dg/unreferenced2.adb new file mode 100644 index 00000000000..9576ef822af --- /dev/null +++ b/gcc/testsuite/gnat.dg/unreferenced2.adb @@ -0,0 +1,34 @@ +-- { dg-do compile } +-- { dg-options "-gnatf" } + +procedure Unreferenced2 is + + protected Example is + procedure Callme; + end Example; + + procedure Other (X : Boolean) is + begin + null; + end; + + protected body Example is + + procedure Internal (X : Boolean) is + pragma Unreferenced (X); + Y : Integer; + begin + Y := 3; + end Internal; + + procedure Callme is + begin + Internal (X => True); + end Callme; + + end Example; + +begin + Example.Callme; + Other (True); +end Unreferenced2; -- 2.30.2