[Ada] Assertion failure on Default_Initial_Condition
authorHristian Kirtchev <kirtchev@adacore.com>
Thu, 4 Jul 2019 08:06:19 +0000 (08:06 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Thu, 4 Jul 2019 08:06:19 +0000 (08:06 +0000)
This patch prevents the association of a Default_Initial_Condition with
an incomplete type whose full view is the private type or private
extension subject to the aspect/pragma.

2019-07-04  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

* sem_util.adb (Propagate_DIC_Attributes): Do not propagate the
Default_Initial_Condition attributes to an incomplete type.

gcc/testsuite/

* gnat.dg/default_initial_condition.adb,
gnat.dg/default_initial_condition_pack.adb,
gnat.dg/default_initial_condition_pack.ads: New testcase.

From-SVN: r273059

gcc/ada/ChangeLog
gcc/ada/sem_util.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/default_initial_condition.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/default_initial_condition_pack.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/default_initial_condition_pack.ads [new file with mode: 0644]

index be26421081dceb0064444b47d76301bf9a7437ec..2925c84508102e701f6a0a3ac16fa9f915dd5b69 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-04  Hristian Kirtchev  <kirtchev@adacore.com>
+
+       * sem_util.adb (Propagate_DIC_Attributes): Do not propagate the
+       Default_Initial_Condition attributes to an incomplete type.
+
 2019-07-04  Ed Schonberg  <schonberg@adacore.com>
 
        * sem_attr.adb (Check_Array_Type): An array type attribute such
index 4d19c6147143f25fc54df56f9bb86b569a1b7819..868e93ea9559184a660a48aee300c087892e226e 100644 (file)
@@ -23327,6 +23327,13 @@ package body Sem_Util is
 
          if From_Typ = Typ then
             return;
+
+         --  Nothing to do when the destination denotes an incomplete type
+         --  because the DIC is associated with the current instance of a
+         --  private type, thus it can never apply to an incomplete type.
+
+         elsif Is_Incomplete_Type (Typ) then
+            return;
          end if;
 
          DIC_Proc := DIC_Procedure (From_Typ);
index dd22271efe21e9f3aa20e626ec6f3aa282157037..2b1a479fda823c37968af9d5e6b7fb3eeaeaf52a 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-04  Hristian Kirtchev  <kirtchev@adacore.com>
+
+       * gnat.dg/default_initial_condition.adb,
+       gnat.dg/default_initial_condition_pack.adb,
+       gnat.dg/default_initial_condition_pack.ads: New testcase.
+
 2019-07-04  Ed Schonberg  <schonberg@adacore.com>
 
        * gnat.dg/aspect2.adb, gnat.dg/aspect2.ads: New testcase.
diff --git a/gcc/testsuite/gnat.dg/default_initial_condition.adb b/gcc/testsuite/gnat.dg/default_initial_condition.adb
new file mode 100644 (file)
index 0000000..5ba94a6
--- /dev/null
@@ -0,0 +1,12 @@
+--  { dg-do run }
+--  { dg-options "-gnata" }
+
+with Default_Initial_Condition_Pack; use Default_Initial_Condition_Pack;
+
+procedure Default_Initial_Condition is
+   Obj : T;
+begin
+   if not DIC_Called then
+      raise Program_Error;
+   end if;
+end Default_Initial_Condition;
diff --git a/gcc/testsuite/gnat.dg/default_initial_condition_pack.adb b/gcc/testsuite/gnat.dg/default_initial_condition_pack.adb
new file mode 100644 (file)
index 0000000..abcd491
--- /dev/null
@@ -0,0 +1,7 @@
+package body Default_Initial_Condition_Pack is
+   function Is_OK (Val : T) return Boolean is
+   begin
+      DIC_Called := True;
+      return True;
+   end Is_OK;
+end Default_Initial_Condition_Pack;
diff --git a/gcc/testsuite/gnat.dg/default_initial_condition_pack.ads b/gcc/testsuite/gnat.dg/default_initial_condition_pack.ads
new file mode 100644 (file)
index 0000000..c461bf2
--- /dev/null
@@ -0,0 +1,12 @@
+package Default_Initial_Condition_Pack is
+   type T;
+   type T is private
+     with Default_Initial_Condition => Is_OK (T);
+
+   function Is_OK (Val : T) return Boolean;
+
+   DIC_Called : Boolean := False;
+
+private
+   type T is null record;
+end Default_Initial_Condition_Pack;