public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Pragma Unreferenced triggers undefined reference
@ 2019-07-11  8:03 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-07-11  8:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: Justin Squirek

[-- Attachment #1: Type: text/plain, Size: 493 bytes --]

This patch corrects the generation of protected body declarations so
that instances of pragma Unreferenced applied to formals don't falsly
trigger undefined references.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-07-11  Justin Squirek  <squirek@adacore.com>

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.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1781 bytes --]

--- gcc/ada/exp_ch9.adb
+++ 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;

--- /dev/null
new file mode 100644
+++ 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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-11  8:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-11  8:03 [Ada] Pragma Unreferenced triggers undefined reference Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).