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]

[Ada] Crash on potential access-before-elaboration in ZFP


This patch update the mechanism which retrieves the enclosing scope of a node
to account for blocks produces by exception handler expansion. These blocks are
not scoping constructs and should not be considered. As a result, an access-
before-elaboration check will no longer cause a crash on ZFP.

------------
-- Source --
------------

--  pack.ads

package Pack is
   procedure Force_Body;
end Pack;

--  pack.adb

with Ada.Text_IO; use Ada.Text_IO;

package body Pack is
   procedure Force_Body is begin null; end Force_Body;

   package Nested is
      function Func (Val : Integer) return Integer;
   end Nested;

   package body Nested is
      procedure Proc is
         Val : Integer;

      begin
         Val := Func (1);
         Put_Line ("ERROR: Program_Error not raised");
      exception
         when Program_Error =>
            Put_Line ("OK");
         when others =>
            Put_Line ("ERROR: unexpected exception");
      end Proc;

      package Elaborator is
      end Elaborator;

      package body Elaborator is
      begin
         Proc;
      end Elaborator;

      function Func (Val : Integer) return Integer is
      begin
         return Val + 1;
      end Func;
   end Nested;
end Pack;

-----------------
-- Compilation --
-----------------

$ gcc -c -gnatws --RTS=zfp pack.adb

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

2017-10-09  Hristian Kirtchev  <kirtchev@adacore.com>

	* sem_unit.adb (Find_Enclosing_Scope): Do not treat a block statement
	as a scoping construct when it is byproduct of exception handling.

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]