From: Hristian Kirtchev Date: Mon, 28 May 2018 08:53:54 +0000 (+0000) Subject: [Ada] Crash on aspect/pragma Linked_Section with -gnatR2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=24161618d265dbd7543e1286882ec517bed66f5b;p=gcc.git [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 gcc/ada/ * repinfo.adb (Expr_Value_S): New routine. (List_Linker_Section): Properly extract the value of the section argument. From-SVN: r260825 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 8e4982aa2ab..7a0a60dfb56 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2018-05-28 Hristian Kirtchev + + * repinfo.adb (Expr_Value_S): New routine. + (List_Linker_Section): Properly extract the value of the section + argument. + 2018-05-28 Patrick Bernardi * doc/gnat_ugn/building_executable_programs_with_gnat.rst: Update the diff --git a/gcc/ada/repinfo.adb b/gcc/ada/repinfo.adb index 38b2334b3de..1fa3f4eee8d 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;