From: Ronan Desplanques <desplanq...@adacore.com> Before this patch, it was never allowed to use pragma Source_File_Name for the spec of System, allegedly because Targparm.Get_Target_Parameters is called before configuration pragmas are processed. Using a mapping file was allowed but did not work correctly.
This patch makes mapping files loading happen before the call to Get_Target_Parameters so mapping file can set the file name of System. Also, pragma Source_File_Name is allowed if it confirms a mapping that was previously given in a mapping file, to accommodate GPRbuild that uses both pragmas and mapping files. gcc/ada/ChangeLog: * frontend.adb (Frontend): Move call to Fmap.Initialize ... * gnat1drv.adb (Gnat1drv): ... here. Look up Fmap when loading System. * par-prag.adb (Prag): Allow pragma Source_File_Name for System when it confirms an existing mapping. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/frontend.adb | 7 ------- gcc/ada/gnat1drv.adb | 16 +++++++++++++--- gcc/ada/par-prag.adb | 30 +++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/gcc/ada/frontend.adb b/gcc/ada/frontend.adb index ece0e728e4a..ea0c7b12b4a 100644 --- a/gcc/ada/frontend.adb +++ b/gcc/ada/frontend.adb @@ -286,13 +286,6 @@ begin Save_Config_Cunit_Boolean_Restrictions; - -- If there was a -gnatem switch, initialize the mappings of unit names - -- to file names and of file names to path names from the mapping file. - - if Mapping_File_Name /= null then - Fmap.Initialize (Mapping_File_Name.all); - end if; - -- Adjust Optimize_Alignment mode from debug switches if necessary if Debug_Flag_Dot_SS then diff --git a/gcc/ada/gnat1drv.adb b/gcc/ada/gnat1drv.adb index b532aefcaaa..acc64912280 100644 --- a/gcc/ada/gnat1drv.adb +++ b/gcc/ada/gnat1drv.adb @@ -1034,6 +1034,13 @@ begin Sem_Eval.Initialize; Sem_Type.Init_Interp_Tables; + -- If there was a -gnatem switch, initialize the mappings of unit names + -- to file names and of file names to path names from the mapping file. + + if Mapping_File_Name /= null then + Fmap.Initialize (Mapping_File_Name.all); + end if; + -- Capture compilation date and time Opt.Compilation_Time := System.OS_Lib.Current_Time_String; @@ -1051,9 +1058,12 @@ begin N : File_Name_Type; begin - Name_Buffer (1 .. 10) := "system.ads"; - Name_Len := 10; - N := Name_Find; + N := Fmap.Mapped_File_Name (Name_To_Unit_Name (Name_System)); + + if N = No_File then + N := Name_Find ("system.ads"); + end if; + S := Load_Source_File (N); -- Failed to read system.ads, fatal error diff --git a/gcc/ada/par-prag.adb b/gcc/ada/par-prag.adb index 1a2a7b6b77b..8ea94a3f9bd 100644 --- a/gcc/ada/par-prag.adb +++ b/gcc/ada/par-prag.adb @@ -29,6 +29,7 @@ -- which require recognition and either partial or complete processing -- during parsing, and this unit performs this required processing. +with Fmap; with Fname.UF; use Fname.UF; with Osint; use Osint; with Rident; use Rident; @@ -754,15 +755,6 @@ begin and then Nkind (Selector_Name (Expr1)) = N_Identifier) then - if Nkind (Expr1) = N_Identifier - and then Chars (Expr1) = Name_System - then - Error_Msg_N - ("pragma Source_File_Name may not be used for System", - Arg1); - return Error; - end if; - -- Process index argument if present if Arg_Count = 3 then @@ -793,6 +785,26 @@ begin Check_Arg_Is_String_Literal (Arg2); + if Nkind (Expr1) = N_Identifier + and then Chars (Expr1) = Name_System + then + -- We allow pragma Source_File_Name on System if it confirms + -- a mapping that already exists in Fmap. The goal is to + -- accommodate GPRbuild, which uses both a map file and + -- a pragma, while at the same time preventing users from + -- using just a pragma. Using just a pragma is a problem + -- because those are not registered yet when + -- Get_Target_Parameters is called. + if Fmap.Mapped_File_Name (Name_To_Unit_Name (Name_System)) + /= Get_Fname (Arg2) + then + Error_Msg_N + ("pragma Source_File_Name may not be used for System", + Arg1); + return Error; + end if; + end if; + if Chars (Arg2) = Name_Spec_File_Name then Set_File_Name (Get_Spec_Name (Unam), Get_Fname (Arg2), Index); -- 2.43.0