[Ada] Fix crash on formal containers

Programming / Compilers / GCC - pmderodat [138bc75d-0d04-0410-961f-82ee72b054a4] - 24 May 2018 13:04 EDT

This patch modifies several mechanisms in the compiler:

1) The handling of Ghost regions now records the start of the outermost ignored Ghost region which is currently in effect.

2) Generation of freeze actions for an arbitrary entity now inserts the actions prior to the start of the outermost ignored Ghost region when the freezing takes effect within an ignored Ghost region, but the entity being frozen is "living". This ensures that any freeze actions associated with the living entity will not be eliminated from the tree once ignored Ghost code is stripped away.

3) The Default_Initial_Condition and Invariant procedures are not treated as primitives even when they apply to tagged types. These procedures already employ class-wide precondition-like semantics to handle inheritance and overriding. In addition, the procedures cannot be invoked from source and should not be targets of dispatching calls.

2018-05-24 Hristian Kirtchev

gcc/ada/

- expander.adb (Expand): Update the save and restore of the Ghost region.
- exp_ch3.adb (Freeze_Type): Likewise.
- exp_disp.adb (Make_DT): Likewise.
- exp_util.adb (Build_DIC_Procedure_Body): Likewise. (Build_DIC_Procedure_Declaration): Likewise. (Build_Invariant_Procedure_Body): Likewise. (Build_Invariant_Procedure_Declaration): Likewise. (Make_Predicate_Call): Likewise.
- freeze.adb (Add_To_Result): Insert the freeze action of a living entity prior to the start of the enclosing ignored Ghost region. (Freeze_Entity): Update the save and restore of the Ghost region.
- ghost.adb (Install_Ghost_Mode): Reimplemented. (Install_Ghost_Region): New routine. (Mark_And_Set_Ghost_Assignment): Install a region rather than a mode. (Mark_And_Set_Ghost_Body): Likewise. (Mark_And_Set_Ghost_Completion): Likewise. (Mark_And_Set_Ghost_Declaration): Likewise. (Mark_And_Set_Ghost_Instantiation): Likewise. (Mark_And_Set_Ghost_Procedure_Call): Likewise. (Name_To_Ghost_Mode): New routine. (Restore_Ghost_Region): New routine.
- ghost.ads (Install_Ghost_Region): New routine. (Restore_Ghost_Region): New routine.
- opt.ads: Add new global variable Ignored_Ghost_Region.
- rtsfind.adb (Load_RTU): Update the save and restore of the Ghost region. Install a clean region.
- sem.adb (Analyze): Likewise. (Do_Analyze): Likewise.
- sem_ch3.adb (Analyze_Object_Declaration): Likewise (Derive_Progenitor_Subprograms): Use local variable Iface_Alias to capture the ultimate alias of the current primitive. (Process_Full_View): Update the save and restore of the Ghost region. Do not inherit DIC and invariant procedures.
- sem_ch5.adb (Analyze_Assignment): Update the save and restore of the Ghost region.
- sem_ch6.adb (Analyze_Procedure_Call): Likewise. (Analyze_Subprogram_Body_Helper): Likewise.
- sem_ch7.adb (Analyze_Package_Body_Helper): Likewise.
- sem_ch12.adb (Analyze_Package_Instantiation): Likewise. (Analyze_Subprogram_Instantiation): Likewise. (Instantiate_Package_Body): Likewise. (Instantiate_Subprogram_Body): Likewise.
- sem_ch13.adb (Build_Predicate_Functions): Likewise. (Build_Predicate_Function_Declaration): Likewise.
- sem_disp.adb (Add_Dispatching_Operation): Do not consider DIC and invariant procedures. (Check_Dispatching_Operation): Use Add_Dispatching_Operation to collect a dispatching subprogram. (Check_Operation_From_Private_View): Likewise. (Override_Dispatching_Operation): Likewise.
- sem_prag.adb (Analyze_Contract_Cases_In_Decl_Part): Update the save and restore of the Ghost region. (Analyze_Initial_Condition_In_Decl_Part): Likewise. (Analyze_Pragma): Update the save and restore of the Ghost region. (Analyze_Pre_Post_Condition_In_Decl_Part): Likewise.
- sem_util.adb (Is_Suitable_Primitive): New routine.
- sem_util.ads (Is_Suitable_Primitive): New routine.
- sinfo.ads: Update the section of Ghost regions.

gcc/testsuite/

- gnat.dg/formal_containers.adb: New testcase.

150bddeba0a [Ada] Fix crash on formal containers
gcc/ada/ChangeLog | 63 ++++++++++++++
gcc/ada/exp_ch3.adb | 9 +-
gcc/ada/exp_disp.adb | 7 +-
gcc/ada/exp_util.adb | 35 ++++----
gcc/ada/expander.adb | 7 +-
gcc/ada/freeze.adb | 41 ++++++----
gcc/ada/ghost.adb | 123 ++++++++++++++++++++--------
gcc/ada/ghost.ads | 34 ++++----
gcc/ada/opt.ads | 8 +-
gcc/ada/rtsfind.adb | 15 ++--
gcc/ada/sem.adb | 22 +++--
gcc/ada/sem_ch12.adb | 28 ++++---
gcc/ada/sem_ch13.adb | 14 ++--
gcc/ada/sem_ch3.adb | 52 ++++++------
gcc/ada/sem_ch5.adb | 7 +-
gcc/ada/sem_ch6.adb | 10 ++-
gcc/ada/sem_ch7.adb | 3 +-
gcc/ada/sem_disp.adb | 17 +++-
gcc/ada/sem_prag.adb | 31 ++++---
gcc/ada/sem_util.adb | 23 ++++++
gcc/ada/sem_util.ads | 4 +
gcc/ada/sinfo.ads | 66 +++++++++------
gcc/testsuite/ChangeLog | 4 +
gcc/testsuite/gnat.dg/formal_containers.adb | 23 ++++++
24 files changed, 451 insertions(+), 195 deletions(-)

Upstream: gcc.gnu.org


  • Share