[Ada] Fix spurious instantiation error on private record type

Programming / Compilers / GCC - pmderodat [138bc75d-0d04-0410-961f-82ee72b054a4] - 13 August 2019 08:08 EDT

This change was initially aimed at fixing a spurious instantiation error due to a disambiguation issue which happens when a generic unit with two formal type parameters is instantiated on a single actual type that is private.

The compiler internally sets the Is_Generic_Actual_Type flag on the actual subtypes built for the instantiation in order to ease the disambiguation, but it would fail to set it on the full view if the subtypes are private. The change makes it so that the flag is properly set and reset on the full view in this case.

But this uncovered an issue in Subtypes_Statically_Match, which was relying on a stalled Is_Generic_Actual_Type flag set on a full view outside of the instantiation to return a positive answer. This bypass was meant to solve an issue arising with a private discriminated record type whose completion is a discriminated record type itself derived from a private discriminated record type, which is used as actual type in an instantiation in another unit, and the instantiation is used in a child unit of the original unit. In this case, the private and full views of the generic actual type are swapped in the child unit, but there was a mismatch between the chain of full and underlying full views of the private discriminated record type and that of the generic actual type.

This secondary issue is solved by avoiding to skip the full view in the preparation of the completion of the private subtype and by directly constraining the underlying full view of the full view of the base type instead of building an underlying full view from scratch.

2019-08-13 Eric Botcazou

gcc/ada/

- sem_ch3.adb (Build_Underlying_Full_View): Delete. (Complete_Private_Subtype): Do not set the full view on the private subtype here. If the full base is itself derived from private, do not re-derive the parent type but instead constrain an existing underlying full view. (Prepare_Private_Subtype_Completion): Do not get to the underlying full view, if any. Set the full view on the private subtype here. (Process_Full_View): Likewise.
- sem_ch12.adb (Check_Generic_Actuals): Also set Is_Generic_Actual_Type on the full view if the type of the actual is private. (Restore_Private_Views): Also reset Is_Generic_Actual_Type on the full view if the type of the actual is private.
- sem_eval.adb (Subtypes_Statically_Match): Remove bypass for generic actual types.

gcc/testsuite/

- gnat.dg/generic_inst10.adb, gnat.dg/generic_inst10_pkg.ads: New testcase.

2fec02ad9b7 [Ada] Fix spurious instantiation error on private record type
gcc/ada/ChangeLog | 19 ++++
gcc/ada/sem_ch12.adb | 11 +-
gcc/ada/sem_ch3.adb | 162 +++------------------------
gcc/ada/sem_eval.adb | 12 +-
gcc/testsuite/ChangeLog | 5 +
gcc/testsuite/gnat.dg/generic_inst10.adb | 26 +++++
gcc/testsuite/gnat.dg/generic_inst10_pkg.ads | 11 ++
7 files changed, 90 insertions(+), 156 deletions(-)

Upstream: gcc.gnu.org


  • Share