]> git.ipfire.org Git - thirdparty/gcc.git/commit
[Ada] Different runtime behavior of Predicate_Failure
authorHristian Kirtchev <kirtchev@adacore.com>
Thu, 11 Jan 2018 08:51:39 +0000 (08:51 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Thu, 11 Jan 2018 08:51:39 +0000 (08:51 +0000)
commit806312986f95213e4321f4a282ff1738fe72c1ea
tree1d6b19fff5051188563921dccc1eb44ac05b1754
parent6a5e79b44f0d0d06c793ec200ef3b597b07ebc1a
[Ada] Different runtime behavior of Predicate_Failure

This patch corrects the generation of predicate checks to handle the case where
Predicate_Failure appears as a pragma.

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

--  main.adb

with Ada.Assertions; use Ada.Assertions;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO;    use Ada.Text_IO;

procedure Main is
   subtype Even_Asp is Integer
     with Predicate => Even_Asp mod 2 = 0,
          Predicate_Failure => "Even_Asp failed";

   subtype Even_Prag is Integer
     with Predicate => Even_Prag mod 2 = 0;
   pragma Predicate_Failure (Even_Prag, "Even_Prag failed");

begin
   begin
      declare
         Val : constant Even_Asp := 1;
      begin
         Put_Line ("ERROR: Even_Asp: did not fail");
      end;
   exception
      when AE : Assertion_Error => Put_Line (Exception_Message (AE));
      when others => Put_Line ("ERROR: Even_Asp: raised unexpected error");
   end;

   begin
      declare
         Val : constant Even_Prag := 3;
      begin
         Put_Line ("ERROR: Even_Prag: did not fail");
      end;
   exception
      when AE : Assertion_Error => Put_Line (Exception_Message (AE));
      when others => Put_Line ("ERROR: Even_Prag: raised unexpected error");
   end;
end Main;

----------------------------
-- Compilation and output --
----------------------------

$ gnatmake -q main.adb
$ ./main
Even_Asp failed
Even_Prag failed

2018-01-11  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

* exp_util.adb (Add_Failure_Expression): New routine.
(Make_Predicate_Check): Reimplement the handling of Predicate_Failure.
* sem_util.adb (Is_Current_Instance): Code cleanup.

From-SVN: r256493
gcc/ada/ChangeLog
gcc/ada/exp_util.adb
gcc/ada/sem_util.adb