Fix g++.dg/torture/Wsizeof-pointer-memaccess2.C with -std=c++11
[official-gcc.git] / gcc / ada / frontend.adb
blobbab0b46abfa407e89db0310c0577f9e87c90b036
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- F R O N T E N D --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with System.Strings; use System.Strings;
28 with Atree; use Atree;
29 with Checks;
30 with CStand;
31 with Debug; use Debug;
32 with Elists;
33 with Exp_Dbug;
34 with Fmap;
35 with Fname.UF;
36 with Ghost; use Ghost;
37 with Inline; use Inline;
38 with Lib; use Lib;
39 with Lib.Load; use Lib.Load;
40 with Lib.Xref; use Lib.Xref;
41 with Live; use Live;
42 with Namet; use Namet;
43 with Nlists; use Nlists;
44 with Opt; use Opt;
45 with Osint;
46 with Par;
47 with Prep;
48 with Prepcomp;
49 with Restrict; use Restrict;
50 with Rident; use Rident;
51 with Rtsfind; use Rtsfind;
52 with Snames; use Snames;
53 with Sprint;
54 with Scn; use Scn;
55 with Sem; use Sem;
56 with Sem_Aux;
57 with Sem_Ch8; use Sem_Ch8;
58 with Sem_SCIL;
59 with Sem_Elab; use Sem_Elab;
60 with Sem_Prag; use Sem_Prag;
61 with Sem_Warn; use Sem_Warn;
62 with Sinfo; use Sinfo;
63 with Sinput; use Sinput;
64 with Sinput.L; use Sinput.L;
65 with SCIL_LL; use SCIL_LL;
66 with Targparm; use Targparm;
67 with Tbuild; use Tbuild;
68 with Types; use Types;
70 procedure Frontend is
71 Config_Pragmas : List_Id;
72 -- Gather configuration pragmas
74 begin
75 -- Carry out package initializations. These are initializations which might
76 -- logically be performed at elaboration time, were it not for the fact
77 -- that we may be doing things more than once in the big loop over files.
78 -- Like elaboration, the order in which these calls are made is in some
79 -- cases important. For example, Lib cannot be initialized before Namet,
80 -- since it uses names table entries.
82 Rtsfind.Initialize;
83 Nlists.Initialize;
84 Elists.Initialize;
85 Lib.Load.Initialize;
86 Sem_Aux.Initialize;
87 Sem_Ch8.Initialize;
88 Sem_Prag.Initialize;
89 Fname.UF.Initialize;
90 Checks.Initialize;
91 Sem_Warn.Initialize;
92 Prep.Initialize;
94 if Generate_SCIL then
95 SCIL_LL.Initialize;
96 end if;
98 -- Create package Standard
100 CStand.Create_Standard;
102 -- Check possible symbol definitions specified by -gnateD switches
104 Prepcomp.Process_Command_Line_Symbol_Definitions;
106 -- If -gnatep= was specified, parse the preprocessing data file
108 if Preprocessing_Data_File /= null then
109 Name_Len := Preprocessing_Data_File'Length;
110 Name_Buffer (1 .. Name_Len) := Preprocessing_Data_File.all;
111 Prepcomp.Parse_Preprocessing_Data_File (Name_Find);
113 -- Otherwise, check if there were preprocessing symbols on the command
114 -- line and set preprocessing if there are.
116 else
117 Prepcomp.Check_Symbols;
118 end if;
120 -- We set Parsing_Main_Extended_Source true here to cover processing of all
121 -- the configuration pragma files, as well as the main source unit itself.
123 Parsing_Main_Extended_Source := True;
125 -- Now that the preprocessing situation is established, we are able to
126 -- load the main source (this is no longer done by Lib.Load.Initialize).
128 Lib.Load.Load_Main_Source;
130 -- Return immediately if the main source could not be found
132 if Sinput.Main_Source_File = No_Source_File then
133 return;
134 end if;
136 -- Read and process configuration pragma files if present
138 declare
139 Save_Style_Check : constant Boolean := Opt.Style_Check;
140 -- Save style check mode so it can be restored later
142 Source_Config_File : Source_File_Index;
143 -- Source reference for -gnatec configuration file
145 Prag : Node_Id;
147 Temp_File : Boolean;
149 begin
150 -- We always analyze config files with style checks off, since we
151 -- don't want a miscellaneous gnat.adc that is around to discombobulate
152 -- intended -gnatg or -gnaty compilations. We also disconnect checking
153 -- for maximum line length.
155 Opt.Style_Check := False;
156 Style_Check := False;
158 -- Capture current suppress options, which may get modified
160 Scope_Suppress := Opt.Suppress_Options;
162 -- First deal with gnat.adc file
164 if Opt.Config_File then
165 Name_Buffer (1 .. 8) := "gnat.adc";
166 Name_Len := 8;
167 Source_gnat_adc := Load_Config_File (Name_Enter);
169 -- Case of gnat.adc file present
171 if Source_gnat_adc /= No_Source_File then
173 -- Parse the gnat.adc file for configuration pragmas
175 Initialize_Scanner (No_Unit, Source_gnat_adc);
176 Config_Pragmas := Par (Configuration_Pragmas => True);
178 -- We unconditionally add a compilation dependency for gnat.adc
179 -- so that if it changes, we force a recompilation. This is a
180 -- fairly recent (2014-03-28) change.
182 Prepcomp.Add_Dependency (Source_gnat_adc);
184 -- Case of no gnat.adc file present
186 else
187 Config_Pragmas := Empty_List;
188 end if;
190 else
191 Config_Pragmas := Empty_List;
192 end if;
194 -- Now deal with specified config pragmas files if there are any
196 if Opt.Config_File_Names /= null then
198 -- Loop through config pragmas files
200 for Index in Opt.Config_File_Names'Range loop
202 -- See if extension is .TMP/.tmp indicating a temporary config
203 -- file (which we ignore from the dependency point of view).
205 Name_Len := Config_File_Names (Index)'Length;
206 Name_Buffer (1 .. Name_Len) := Config_File_Names (Index).all;
207 Temp_File :=
208 Name_Len > 4
209 and then
210 (Name_Buffer (Name_Len - 3 .. Name_Len) = ".TMP"
211 or else
212 Name_Buffer (Name_Len - 3 .. Name_Len) = ".tmp");
214 -- Load the file, error if we did not find it
216 Source_Config_File := Load_Config_File (Name_Enter);
218 if Source_Config_File = No_Source_File then
219 Osint.Fail
220 ("cannot find configuration pragmas file "
221 & Config_File_Names (Index).all);
223 -- If we did find the file, and it is not a temporary file, then
224 -- we unconditionally add a compilation dependency for it so
225 -- that if it changes, we force a recompilation. This is a
226 -- fairly recent (2014-03-28) change.
228 elsif not Temp_File then
229 Prepcomp.Add_Dependency (Source_Config_File);
230 end if;
232 -- Parse the config pragmas file, and accumulate results
234 Initialize_Scanner (No_Unit, Source_Config_File);
235 Append_List_To
236 (Config_Pragmas, Par (Configuration_Pragmas => True));
237 end loop;
238 end if;
240 -- Now analyze all pragmas except those whose analysis must be
241 -- deferred till after the main unit is analyzed.
243 if Config_Pragmas /= Error_List
244 and then Operating_Mode /= Check_Syntax
245 then
246 Prag := First (Config_Pragmas);
247 while Present (Prag) loop
248 if not Delay_Config_Pragma_Analyze (Prag) then
249 Analyze_Pragma (Prag);
250 end if;
252 Next (Prag);
253 end loop;
254 end if;
256 -- Restore style check, but if config file turned on checks, leave on
258 Opt.Style_Check := Save_Style_Check or Style_Check;
260 -- Capture any modifications to suppress options from config pragmas
262 Opt.Suppress_Options := Scope_Suppress;
263 end;
265 -- If a target dependency info file has been read through switch -gnateT=,
266 -- add it to the dependencies.
268 if Target_Dependent_Info_Read_Name /= null then
269 declare
270 Index : Source_File_Index;
271 begin
272 Name_Len := 0;
273 Add_Str_To_Name_Buffer (Target_Dependent_Info_Read_Name.all);
274 Index := Load_Config_File (Name_Enter);
275 Prepcomp.Add_Dependency (Index);
276 end;
277 end if;
279 -- This is where we can capture the value of the compilation unit specific
280 -- restrictions that have been set by the config pragma files (or from
281 -- Targparm), for later restoration when processing e.g. subunits.
283 Save_Config_Cunit_Boolean_Restrictions;
285 -- If there was a -gnatem switch, initialize the mappings of unit names to
286 -- file names and of file names to path names from the mapping file.
288 if Mapping_File_Name /= null then
289 Fmap.Initialize (Mapping_File_Name.all);
290 end if;
292 -- Adjust Optimize_Alignment mode from debug switches if necessary
294 if Debug_Flag_Dot_SS then
295 Optimize_Alignment := 'S';
296 elsif Debug_Flag_Dot_TT then
297 Optimize_Alignment := 'T';
298 end if;
300 -- We have now processed the command line switches, and the configuration
301 -- pragma files, so this is the point at which we want to capture the
302 -- values of the configuration switches (see Opt for further details).
304 Opt.Register_Opt_Config_Switches;
306 -- Check for file which contains No_Body pragma
308 if Source_File_Is_No_Body (Source_Index (Main_Unit)) then
309 Change_Main_Unit_To_Spec;
310 end if;
312 -- Initialize the scanner. Note that we do this after the call to
313 -- Create_Standard, which uses the scanner in its processing of
314 -- floating-point bounds.
316 Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
318 -- Here we call the parser to parse the compilation unit (or units in
319 -- the check syntax mode, but in that case we won't go on to the
320 -- semantics in any case).
322 Discard_List (Par (Configuration_Pragmas => False));
323 Parsing_Main_Extended_Source := False;
325 -- The main unit is now loaded, and subunits of it can be loaded,
326 -- without reporting spurious loading circularities.
328 Set_Loading (Main_Unit, False);
330 -- Now that the main unit is installed, we can complete the analysis
331 -- of the pragmas in gnat.adc and the configuration file, that require
332 -- a context for their semantic processing.
334 if Config_Pragmas /= Error_List
335 and then Operating_Mode /= Check_Syntax
337 -- Do not attempt to process deferred configuration pragmas if the main
338 -- unit failed to load, to avoid cascaded inconsistencies that can lead
339 -- to a compiler crash.
341 and then Fatal_Error (Main_Unit) /= Error_Detected
342 then
343 -- Pragmas that require some semantic activity, such as Interrupt_State,
344 -- cannot be processed until the main unit is installed, because they
345 -- require a compilation unit on which to attach with_clauses, etc. So
346 -- analyze them now.
348 declare
349 Prag : Node_Id;
351 begin
352 Prag := First (Config_Pragmas);
353 while Present (Prag) loop
355 -- Guard against the case where a configuration pragma may be
356 -- split into multiple pragmas and the original rewritten as a
357 -- null statement.
359 if Nkind (Prag) = N_Pragma
360 and then Delay_Config_Pragma_Analyze (Prag)
361 then
362 Analyze_Pragma (Prag);
363 end if;
365 Next (Prag);
366 end loop;
367 end;
368 end if;
370 -- If we have restriction No_Exception_Propagation, and we did not have an
371 -- explicit switch turning off Warn_On_Non_Local_Exception, then turn on
372 -- this warning by default if we have encountered an exception handler.
374 if Restriction_Check_Required (No_Exception_Propagation)
375 and then not No_Warn_On_Non_Local_Exception
376 and then Exception_Handler_Encountered
377 then
378 Warn_On_Non_Local_Exception := True;
379 end if;
381 -- Now on to the semantics. Skip if in syntax only mode
383 if Operating_Mode /= Check_Syntax then
385 -- Install the configuration pragmas in the tree
387 Set_Config_Pragmas (Aux_Decls_Node (Cunit (Main_Unit)), Config_Pragmas);
389 -- Following steps are skipped if we had a fatal error during parsing
391 if Fatal_Error (Main_Unit) /= Error_Detected then
393 -- Reset Operating_Mode to Check_Semantics for subunits. We cannot
394 -- actually generate code for subunits, so we suppress expansion.
395 -- This also corrects certain problems that occur if we try to
396 -- incorporate subunits at a lower level.
398 if Operating_Mode = Generate_Code
399 and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
400 then
401 Operating_Mode := Check_Semantics;
402 end if;
404 -- Analyze (and possibly expand) main unit
406 Scope_Suppress := Suppress_Options;
407 Semantics (Cunit (Main_Unit));
409 -- Cleanup processing after completing main analysis
411 -- Turn off unnesting of subprograms mode. This is not right
412 -- with respect to instantiations. What needs to happen is that
413 -- we do the unnesting AFTER the call to Instantiate_Bodies. We
414 -- will take care of that later ???
416 Opt.Unnest_Subprogram_Mode := False;
418 -- Comment needed for ASIS mode test and GNATprove mode test???
420 if Operating_Mode = Generate_Code
421 or else (Operating_Mode = Check_Semantics
422 and then (ASIS_Mode or GNATprove_Mode))
423 then
424 Instantiate_Bodies;
425 end if;
427 if Operating_Mode = Generate_Code then
428 if Inline_Processing_Required then
429 Analyze_Inlined_Bodies;
430 end if;
432 -- Remove entities from program that do not have any execution
433 -- time references.
435 if Debug_Flag_UU then
436 Collect_Garbage_Entities;
437 end if;
439 Check_Elab_Calls;
441 -- Remove any ignored Ghost code as it must not appear in the
442 -- executable.
444 Remove_Ignored_Ghost_Code;
445 end if;
447 -- List library units if requested
449 if List_Units then
450 Lib.List;
451 end if;
453 -- Output waiting warning messages
455 Lib.Xref.Process_Deferred_References;
456 Sem_Warn.Output_Non_Modified_In_Out_Warnings;
457 Sem_Warn.Output_Unreferenced_Messages;
458 Sem_Warn.Check_Unused_Withs;
459 Sem_Warn.Output_Unused_Warnings_Off_Warnings;
460 end if;
461 end if;
463 -- Qualify all entity names in inner packages, package bodies, etc.,
464 -- except when compiling for the VM back-ends, which depend on having
465 -- unqualified names in certain cases and handles the generation of
466 -- qualified names when needed.
468 if VM_Target = No_VM then
469 Exp_Dbug.Qualify_All_Entity_Names;
470 end if;
472 -- SCIL backend requirement. Check that SCIL nodes associated with
473 -- dispatching calls reference subprogram calls.
475 if Generate_SCIL then
476 pragma Debug (Sem_SCIL.Check_SCIL_Nodes (Cunit (Main_Unit)));
477 null;
478 end if;
480 -- Dump the source now. Note that we do this as soon as the analysis
481 -- of the tree is complete, because it is not just a dump in the case
482 -- of -gnatD, where it rewrites all source locations in the tree.
484 Sprint.Source_Dump;
486 -- Check again for configuration pragmas that appear in the context of
487 -- the main unit. These pragmas only affect the main unit, and the
488 -- corresponding flag is reset after each call to Semantics, but they
489 -- may affect the generated ali for the unit, and therefore the flag
490 -- must be set properly after compilation. Currently we only check for
491 -- Initialize_Scalars, but others should be checked: as well???
493 declare
494 Item : Node_Id;
496 begin
497 Item := First (Context_Items (Cunit (Main_Unit)));
498 while Present (Item) loop
499 if Nkind (Item) = N_Pragma
500 and then Pragma_Name (Item) = Name_Initialize_Scalars
501 then
502 Initialize_Scalars := True;
503 end if;
505 Next (Item);
506 end loop;
507 end;
509 -- If a mapping file has been specified by a -gnatem switch, update
510 -- it if there has been some sources that were not in the mappings.
512 if Mapping_File_Name /= null then
513 Fmap.Update_Mapping_File (Mapping_File_Name.all);
514 end if;
516 return;
517 end Frontend;