Patchwork [Ada] Ignore pragmas when looking for unreachable code

login
register
mail settings
Submitter Arnaud Charlet
Date April 26, 2012, 9:59 a.m.
Message ID <20120426095947.GA6734@adacore.com>
Download mbox | patch
Permalink /patch/155219/
State New
Headers show

Comments

Arnaud Charlet - April 26, 2012, 9:59 a.m.
This patch causes pragmas to be ignored when checking for unreachable
code, which catches additional cases not caught before, as shown by
the following example, compiled with -gnatwe.w -gnatld7

     1. with Ada.Text_IO; use Ada.Text_IO;
     2. procedure Main4 is
     3. begin
     4.    loop
     5.       Put_Line ("Main");
     6.    end loop;
     7.
     8.    pragma List (On);
     9.    Put_Line ("end");
           |
        >>> warning: unreachable code

    10. end Main4;

This also fixes an anomoly that trying to suppress the warning with
pragma Warnings (Off, text) did not work, since the pragma itself
killed the warning.

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

2012-04-26  Robert Dewar  <dewar@adacore.com>

	* sem_ch5.adb (Check_Unreachable_Code): Skip past pragmas.

Patch

Index: sem_ch5.adb
===================================================================
--- sem_ch5.adb	(revision 186860)
+++ sem_ch5.adb	(working copy)
@@ -2767,6 +2767,12 @@ 
          begin
             Nxt := Original_Node (Next (N));
 
+            --  Skip past pragmas
+
+            while Nkind (Nxt) = N_Pragma loop
+               Nxt := Original_Node (Next (Nxt));
+            end loop;
+
             --  If a label follows us, then we never have dead code, since
             --  someone could branch to the label, so we just ignore it, unless
             --  we are in formal mode where goto statements are not allowed.