diff options
author | Hristian Kirtchev <kirtchev@adacore.com> | 2018-05-28 08:53:54 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-05-28 08:53:54 +0000 |
commit | 24161618d265dbd7543e1286882ec517bed66f5b (patch) | |
tree | f4bc58c8dbcffbf24e8715e212c55aacfc97f84f /gcc | |
parent | f5a9ad2577ddea7a5646040b1d301515d834a8d1 (diff) | |
download | gcc-24161618d265dbd7543e1286882ec517bed66f5b.zip gcc-24161618d265dbd7543e1286882ec517bed66f5b.tar.gz gcc-24161618d265dbd7543e1286882ec517bed66f5b.tar.bz2 |
[Ada] Crash on aspect/pragma Linked_Section with -gnatR2
This patch modifies the output of the representation information related to
aspect or pragma Linker_Section, achieved with compiler switch -gnatR2. The
value of the section argument is now properly retrieved. Previously it was
assumed that the value is always a N_String_Literal, however the semantics
of the annotation allow for any static string expression, including a
reference to a static string.
------------
-- Source --
------------
-- linker_sections.ads
package Linker_Sections is
LS_1 : constant String := "1";
LS_2 : constant String := "2" & "2";
LS_3 : constant String := LS_1 & "3";
LS_4 : constant String := "4" & LS_2;
Val_1 : Integer with Linker_Section => LS_1;
Val_2 : Integer with Linker_Section => LS_2;
Val_3 : Integer with Linker_Section => LS_3;
Val_4 : Integer with Linker_Section => LS_4;
Val_5 : Integer with Linker_Section => LS_1 & "5";
Val_6 : Integer with Linker_Section => LS_2 & "6";
Val_7 : Integer with Linker_Section => LS_3 & "7";
Val_8 : Integer with Linker_Section => LS_4 & "8";
Val_9 : Integer with Linker_Section => "9" & LS_1;
Val_10 : Integer with Linker_Section => "10" & LS_2;
Val_11 : Integer with Linker_Section => "11" & LS_3;
Val_12 : Integer with Linker_Section => "12" & LS_4;
Val_13 : Integer; pragma Linker_Section (Val_13, LS_1);
Val_14 : Integer; pragma Linker_Section (Val_14, LS_2);
Val_15 : Integer; pragma Linker_Section (Val_15, LS_3);
Val_16 : Integer; pragma Linker_Section (Val_16, LS_4);
Val_17 : Integer; pragma Linker_Section (Val_17, LS_1 & "5");
Val_18 : Integer; pragma Linker_Section (Val_18, LS_2 & "6");
Val_19 : Integer; pragma Linker_Section (Val_19, LS_3 & "7");
Val_20 : Integer; pragma Linker_Section (Val_20, LS_4 & "8");
Val_21 : Integer; pragma Linker_Section (Val_21, "9" & LS_1);
Val_22 : Integer; pragma Linker_Section (Val_22, "10" & LS_2);
Val_23 : Integer; pragma Linker_Section (Val_23, "11" & LS_3);
Val_24 : Integer; pragma Linker_Section (Val_24, "12" & LS_4);
end Linker_Sections;
-----------------
-- Compilation --
-----------------
$ gcc -c -gnatR2s linker_sections.ads
2018-05-28 Hristian Kirtchev <kirtchev@adacore.com>
gcc/ada/
* repinfo.adb (Expr_Value_S): New routine.
(List_Linker_Section): Properly extract the value of the section
argument.
From-SVN: r260825
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/ada/repinfo.adb | 44 |
2 files changed, 40 insertions, 10 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 8e4982a..7a0a60d 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2018-05-28 Hristian Kirtchev <kirtchev@adacore.com> + + * repinfo.adb (Expr_Value_S): New routine. + (List_Linker_Section): Properly extract the value of the section + argument. + 2018-05-28 Patrick Bernardi <bernardi@adacore.com> * doc/gnat_ugn/building_executable_programs_with_gnat.rst: Update the diff --git a/gcc/ada/repinfo.adb b/gcc/ada/repinfo.adb index 38b2334..1fa3f4e 100644 --- a/gcc/ada/repinfo.adb +++ b/gcc/ada/repinfo.adb @@ -685,23 +685,47 @@ package body Repinfo is ------------------------- procedure List_Linker_Section (Ent : Entity_Id) is - Arg : Node_Id; + function Expr_Value_S (N : Node_Id) return Node_Id; + -- Returns the folded value of the expression. This function is called + -- in instances where it has already been determined that the expression + -- is static or its value is known at compile time. This version is used + -- for string types and returns the corresponding N_String_Literal node. + -- NOTE: This is an exact copy of Sem_Eval.Expr_Value_S. Licensing stops + -- Repinfo from within Sem_Eval. Once ASIS is removed, and the licenses + -- are modified, Repinfo should be able to rely on Sem_Eval. + + ------------------ + -- Expr_Value_S -- + ------------------ + + function Expr_Value_S (N : Node_Id) return Node_Id is + begin + if Nkind (N) = N_String_Literal then + return N; + else + pragma Assert (Ekind (Entity (N)) = E_Constant); + return Expr_Value_S (Constant_Value (Entity (N))); + end if; + end Expr_Value_S; + + -- Local variables + + Args : List_Id; + Sect : Node_Id; + + -- Start of processing for List_Linker_Section begin if Present (Linker_Section_Pragma (Ent)) then + Args := Pragma_Argument_Associations (Linker_Section_Pragma (Ent)); + Sect := Expr_Value_S (Get_Pragma_Arg (Last (Args))); + Write_Str ("pragma Linker_Section ("); List_Name (Ent); Write_Str (", """); - Arg := - Last (Pragma_Argument_Associations (Linker_Section_Pragma (Ent))); - - if Nkind (Arg) = N_Pragma_Argument_Association then - Arg := Expression (Arg); - end if; - - pragma Assert (Nkind (Arg) = N_String_Literal); - String_To_Name_Buffer (Strval (Arg)); + pragma Assert (Nkind (Sect) = N_String_Literal); + String_To_Name_Buffer (Strval (Sect)); Write_Str (Name_Buffer (1 .. Name_Len)); Write_Str (""");"); Write_Eol; |