From d2bb0bbfc6766d392ab1069de05a9426c80d4efc Mon Sep 17 00:00:00 2001 From: Hristian Kirtchev Date: Thu, 24 May 2018 13:05:03 +0000 Subject: [PATCH] [Ada] Spurious error on pragma Independent_Components This patch modifies the analysis of pragma Independent_Components to account for a side effect from handling of self-referential records which render the pragma illegal. ------------ -- Source -- ------------ -- pack.ads package Pack is type OK is record Comp_1 : Integer; Comp_2 : access OK; end record; pragma Independent_Components (OK); type Error; pragma Independent_Components (Error); type Error is record Comp : Integer; end record; end Pack; ---------------------------- -- Compilation and output -- ---------------------------- $ gcc -c pack.ads pack.ads:9:04: representation item must be after full type declaration 2018-05-24 Hristian Kirtchev gcc/ada/ * sem_prag.adb (Analyze_Pragma): Use the full view of an internally generated incomplete type. From-SVN: r260649 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_prag.adb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index cad2b78..efe7559 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,10 @@ 2018-05-24 Hristian Kirtchev + * sem_prag.adb (Analyze_Pragma): Use the full view of an internally + generated incomplete type. + +2018-05-24 Hristian Kirtchev + * expander.adb (Expand): Update the save and restore of the Ghost region. * exp_ch3.adb (Freeze_Type): Likewise. diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index d75f20e..c85d26f 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -16999,6 +16999,38 @@ package body Sem_Prag is E := Entity (E_Id); + -- A record type with a self-referential component of anonymous + -- access type is given an incomplete view in order to handle the + -- self reference: + -- + -- type Rec is record + -- Self : access Rec; + -- end record; + -- + -- becomes + -- + -- type Rec; + -- type Ptr is access Rec; + -- type Rec is record + -- Self : Ptr; + -- end record; + -- + -- Since the incomplete view is now the initial view of the type, + -- the argument of the pragma will reference the incomplete view, + -- but this view is illegal according to the semantics of the + -- pragma. + -- + -- Obtain the full view of an internally-generated incomplete type + -- only. This way an attempt to associate the pragma with a source + -- incomplete type is still caught. + + if Ekind (E) = E_Incomplete_Type + and then not Comes_From_Source (E) + and then Present (Full_View (E)) + then + E := Full_View (E); + end if; + -- A pragma that applies to a Ghost entity becomes Ghost for the -- purposes of legality checks and removal of ignored Ghost code. -- 2.7.4