Debian Codegraph @

gcc/ada/exp_ch11.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ C H 1 1 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, 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 ------------------------------------------------------------------------------
25
26 with Atree; use Atree;
27 with Debug; use Debug;
28 with Einfo; use Einfo;
29 with Einfo.Entities; use Einfo.Entities;
30 with Einfo.Utils; use Einfo.Utils;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Ch7; use Exp_Ch7;
34 with Exp_Intr; use Exp_Intr;
35 with Exp_Util; use Exp_Util;
36 with Namet; use Namet;
37 with Nlists; use Nlists;
38 with Nmake; use Nmake;
39 with Opt; use Opt;
40 with Restrict; use Restrict;
41 with Rident; use Rident;
42 with Rtsfind; use Rtsfind;
43 with Sem; use Sem;
44 with Sem_Res; use Sem_Res;
45 with Sem_Util; use Sem_Util;
46 with Sinfo; use Sinfo;
47 with Sinfo.Nodes; use Sinfo.Nodes;
48 with Sinfo.Utils; use Sinfo.Utils;
49 with Sinput; use Sinput;
50 with Snames; use Snames;
51 with Stand; use Stand;
52 with Stringt; use Stringt;
53 with Targparm; use Targparm;
54 with Tbuild; use Tbuild;
55 with Uintp; use Uintp;
56 with Warnsw; use Warnsw;
57
58 package body Exp_Ch11 is
59
60 -----------------------
61 -- Local Subprograms --
62 -----------------------
63
64 procedure Warn_No_Exception_Propagation_Active (N : Node_Id);
65 -- Generates warning that pragma Restrictions (No_Exception_Propagation)
66 -- is in effect. Caller then generates appropriate continuation message.
67 -- N is the node on which the warning is placed.
68
69 procedure Warn_If_No_Propagation (N : Node_Id);
70 -- Called for an exception raise that is not a local raise (and thus cannot
71 -- be optimized to a goto). Issues warning if No_Exception_Propagation
72 -- restriction is set. N is the node for the raise or equivalent call.
73
74 ---------------------------
75 -- Expand_At_End_Handler --
76 ---------------------------
77
78 -- For a handled statement sequence that has a cleanup (At_End_Proc
79 -- field set), perform any needed expansion.
80
81 -- Do nothing by default. We used to perform a special expansion for
82 -- front-end SJLJ, and we may want to customize this processing in
83 -- the future for new back-ends.
84
85 procedure Expand_At_End_Handler (HSS : Node_Id; Blk_Id : Entity_Id) is
86 pragma Unreferenced (Blk_Id);
87 begin
88 pragma Assert (Present (Entity (At_End_Proc (HSS))));
89 end Expand_At_End_Handler;
90
91 -------------------------------
92 -- Expand_Exception_Handlers --
93 -------------------------------
94
95 procedure Expand_Exception_Handlers (HSS : Node_Id) is
96 Handlrs : constant List_Id := Exception_Handlers (HSS);
97 Loc : constant Source_Ptr := Sloc (HSS);
98 Handler : Node_Id;
99 Obj_Decl : Node_Id;
100 Next_Handler : Node_Id;
101
102 procedure Expand_Local_Exception_Handlers;
103 -- This procedure handles the expansion of exception handlers for the
104 -- optimization of local raise statements into goto statements.
105
106 procedure Replace_Raise_By_Goto (Raise_S : Node_Id; Goto_L1 : Node_Id);
107 -- Raise_S is a raise statement (possibly expanded, and possibly of the
108 -- form of a Raise_xxx_Error node with a condition. This procedure is
109 -- called to replace the raise action with the (already analyzed) goto
110 -- statement passed as Goto_L1. This procedure also takes care of the
111 -- requirement of inserting a Local_Raise call where possible.
112
113 -------------------------------------
114 -- Expand_Local_Exception_Handlers --
115 -------------------------------------
116
117 -- There are two cases for this transformation. First the case of
118 -- explicit raise statements. For this case, the transformation we do
119 -- looks like this. Right now we have for example (where L1, L2 are
120 -- exception labels)
121
122 -- begin
123 -- ...
124 -- raise_exception (excep1'identity); -- was raise excep1
125 -- ...
126 -- raise_exception (excep2'identity); -- was raise excep2
127 -- ...
128 -- exception
129 -- when excep1 =>
130 -- estmts1
131 -- when excep2 =>
132 -- estmts2
133 -- end;
134
135 -- This gets transformed into:
136
137 -- begin
138 -- L1 : label; -- marked Exception_Junk
139 -- L2 : label; -- marked Exception_Junk
140 -- L3 : label; -- marked Exception_Junk
141
142 -- begin -- marked Exception_Junk
143 -- ...
144 -- local_raise (excep1'address); -- was raise excep1
145 -- goto L1;
146 -- ...
147 -- local_raise (excep2'address); -- was raise excep2
148 -- goto L2;
149 -- ...
150 -- exception
151 -- when excep1 =>
152 -- goto L1;
153 -- when excep2 =>
154 -- goto L2;
155 -- end;
156
157 -- goto L3; -- skip handler if no raise, marked Exception_Junk
158
159 -- <<L1>> -- local excep target label, marked Exception_Junk
160 -- begin -- marked Exception_Junk
161 -- estmts1
162 -- end;
163 -- goto L3; -- marked Exception_Junk
164
165 -- <<L2>> -- marked Exception_Junk
166 -- begin -- marked Exception_Junk
167 -- estmts2
168 -- end;
169 -- goto L3; -- marked Exception_Junk
170 -- <<L3>> -- marked Exception_Junk
171 -- end;
172
173 -- Note: the reason we wrap the original statement sequence in an
174 -- inner block is that there may be raise statements within the
175 -- sequence of statements in the handlers, and we must ensure that
176 -- these are properly handled, and in particular, such raise statements
177 -- must not reenter the same exception handlers.
178
179 -- If the restriction No_Exception_Propagation is in effect, then we
180 -- can omit the exception handlers.
181
182 -- begin
183 -- L1 : label; -- marked Exception_Junk
184 -- L2 : label; -- marked Exception_Junk
185 -- L3 : label; -- marked Exception_Junk
186
187 -- begin -- marked Exception_Junk
188 -- ...
189 -- local_raise (excep1'address); -- was raise excep1
190 -- goto L1;
191 -- ...
192 -- local_raise (excep2'address); -- was raise excep2
193 -- goto L2;
194 -- ...
195 -- end;
196
197 -- goto L3; -- skip handler if no raise, marked Exception_Junk
198
199 -- <<L1>> -- local excep target label, marked Exception_Junk
200 -- begin -- marked Exception_Junk
201 -- estmts1
202 -- end;
203 -- goto L3; -- marked Exception_Junk
204
205 -- <<L2>> -- marked Exception_Junk
206 -- begin -- marked Exception_Junk
207 -- estmts2
208 -- end;
209
210 -- <<L3>> -- marked Exception_Junk
211 -- end;
212
213 -- The second case is for exceptions generated by the back end in one
214 -- of three situations:
215
216 -- 1. Front end generates N_Raise_xxx_Error node
217 -- 2. Front end sets Do_xxx_Check flag in subexpression node
218 -- 3. Back end detects a situation where an exception is appropriate
219
220 -- In all these cases, the current processing in gigi is to generate a
221 -- call to the appropriate Rcheck_xx routine (where xx encodes both the
222 -- exception message and the exception to be raised, Constraint_Error,
223 -- Program_Error, or Storage_Error.
224
225 -- We could handle some subcases of 1 using the same front end expansion
226 -- into gotos, but even for case 1, we can't handle all cases, since
227 -- generating gotos in the middle of expressions is not possible (it's
228 -- possible at the gigi/gcc level, but not at the level of the GNAT
229 -- tree).
230
231 -- In any case, it seems easier to have a scheme which handles all three
232 -- cases in a uniform manner. So here is how we proceed in this case.
233
234 -- This procedure detects all handlers for these three exceptions,
235 -- Constraint_Error, Program_Error and Storage_Error (including WHEN
236 -- OTHERS handlers that cover one or more of these cases).
237
238 -- If the handler meets the requirements for being the target of a local
239 -- raise, then the front end does the expansion described previously,
240 -- creating a label to be used as a goto target to raise the exception.
241 -- However, no attempt is made in the front end to convert any related
242 -- raise statements into gotos, e.g. all N_Raise_xxx_Error nodes are
243 -- left unchanged and passed to the back end.
244
245 -- Instead, the front end generates three nodes
246
247 -- N_Push_Constraint_Error_Label
248 -- N_Push_Program_Error_Label
249 -- N_Push_Storage_Error_Label
250
251 -- The Push node is generated at the start of the statements
252 -- covered by the handler, and has as a parameter the label to be
253 -- used as the raise target.
254
255 -- N_Pop_Constraint_Error_Label
256 -- N_Pop_Program_Error_Label
257 -- N_Pop_Storage_Error_Label
258
259 -- The Pop node is generated at the end of the covered statements
260 -- and undoes the effect of the preceding corresponding Push node.
261
262 -- In the case where the handler does NOT meet the requirements, the
263 -- front end will still generate the Push and Pop nodes, but the label
264 -- field in the Push node will be empty signifying that for this region
265 -- of code, no optimization is possible.
266
267 -- These Push/Pop nodes are inhibited if No_Exception_Handlers is set
268 -- since they are useless in this case, and in CodePeer mode, where
269 -- they serve no purpose and can intefere with the analysis.
270
271 -- The back end must maintain three stacks, one for each exception case,
272 -- the Push node pushes an entry onto the corresponding stack, and Pop
273 -- node pops off the entry. Then instead of calling Rcheck_nn, if the
274 -- corresponding top stack entry has an non-empty label, a goto is
275 -- generated. This goto should be preceded by a call to Local_Raise as
276 -- described above.
277
278 -- An example of this transformation is as follows, given:
279
280 -- declare
281 -- A : Integer range 1 .. 10;
282 -- begin
283 -- A := B + C;
284 -- exception
285 -- when Constraint_Error =>
286 -- estmts
287 -- end;
288
289 -- gets transformed to:
290
291 -- declare
292 -- A : Integer range 1 .. 10;
293
294 -- begin
295 -- L1 : label;
296 -- L2 : label;
297
298 -- begin
299 -- %push_constraint_error_label (L1)
300 -- R1b : constant long_long_integer := long_long_integer?(b) +
301 -- long_long_integer?(c);
302 -- [constraint_error when
303 -- not (R1b in -16#8000_0000# .. 16#7FFF_FFFF#)
304 -- "overflow check failed"]
305 -- a := integer?(R1b);
306 -- %pop_constraint_error_Label
307
308 -- exception
309 -- ...
310 -- when constraint_error =>
311 -- goto L1;
312 -- end;
313
314 -- goto L2; -- skip handler when exception not raised
315 -- <<L1>> -- target label for local exception
316 -- estmts
317 -- <<L2>>
318 -- end;
319
320 -- Note: the generated labels and goto statements all have the flag
321 -- Exception_Junk set True, so that Sem_Ch6.Check_Returns will ignore
322 -- this generated exception stuff when checking for missing return
323 -- statements (see circuitry in Check_Statement_Sequence).
324
325 -- Note: All of the processing described above occurs only if
326 -- restriction No_Exception_Propagation applies or debug flag .g is
327 -- enabled.
328
329 CE_Locally_Handled : Boolean := False;
330 SE_Locally_Handled : Boolean := False;
331 PE_Locally_Handled : Boolean := False;
332 -- These three flags indicate whether a handler for the corresponding
333 -- exception (CE=Constraint_Error, SE=Storage_Error, PE=Program_Error)
334 -- is present. If so the switch is set to True, the Exception_Label
335 -- field of the corresponding handler is set, and appropriate Push
336 -- and Pop nodes are inserted into the code.
337
338 Local_Expansion_Required : Boolean := False;
339 -- Set True if we have at least one handler requiring local raise
340 -- expansion as described above.
341
342 procedure Expand_Local_Exception_Handlers is
343 procedure Add_Exception_Label (H : Node_Id);
344 -- H is an exception handler. First check for an Exception_Label
345 -- already allocated for H. If none, allocate one, set the field in
346 -- the handler node, add the label declaration, and set the flag
347 -- Local_Expansion_Required. Note: if Local_Raise_Not_OK is set
348 -- the call has no effect and Exception_Label is left empty.
349
350 procedure Add_Label_Declaration (L : Entity_Id);
351 -- Add an implicit declaration of the given label to the declaration
352 -- list in the parent of the current sequence of handled statements.
353
354 generic
355 Exc_Locally_Handled : in out Boolean;
356 -- Flag indicating whether a local handler for this exception
357 -- has already been generated.
358
359 with function Make_Push_Label (Loc : Source_Ptr) return Node_Id;
360 -- Function to create a Push_xxx_Label node
361
362 with function Make_Pop_Label (Loc : Source_Ptr) return Node_Id;
363 -- Function to create a Pop_xxx_Label node
364
365 procedure Generate_Push_Pop (H : Node_Id);
366 -- Common code for Generate_Push_Pop_xxx below, used to generate an
367 -- exception label and Push/Pop nodes for Constraint_Error,
368 -- Program_Error, or Storage_Error.
369
370 -------------------------
371 -- Add_Exception_Label --
372 -------------------------
373
374 procedure Add_Exception_Label (H : Node_Id) is
375 begin
376 if No (Exception_Label (H))
377 and then not Local_Raise_Not_OK (H)
378 and then not Special_Exception_Package_Used
379 then
380 Local_Expansion_Required := True;
381
382 declare
383 L : constant Entity_Id := Make_Temporary (Sloc (H), 'L');
384 begin
385 Set_Exception_Label (H, L);
386 Add_Label_Declaration (L);
387 end;
388 end if;
389 end Add_Exception_Label;
390
391 ---------------------------
392 -- Add_Label_Declaration --
393 ---------------------------
394
395 procedure Add_Label_Declaration (L : Entity_Id) is
396 P : constant Node_Id := Parent (HSS);
397
398 Decl_L : constant Node_Id :=
399 Make_Implicit_Label_Declaration (Loc,
400 Defining_Identifier => L);
401
402 begin
403 if Declarations (P) = No_List then
404 Set_Declarations (P, Empty_List);
405 end if;
406
407 Append (Decl_L, Declarations (P));
408 Analyze (Decl_L);
409 end Add_Label_Declaration;
410
411 -----------------------
412 -- Generate_Push_Pop --
413 -----------------------
414
415 procedure Generate_Push_Pop (H : Node_Id) is
416 begin
417 if Restriction_Active (No_Exception_Handlers)
418 or else CodePeer_Mode
419 then
420 return;
421 end if;
422
423 if Exc_Locally_Handled then
424 return;
425 else
426 Exc_Locally_Handled := True;
427 end if;
428
429 Add_Exception_Label (H);
430
431 declare
432 F : constant Node_Id := First (Statements (HSS));
433 L : constant Node_Id := Last (Statements (HSS));
434
435 Push : constant Node_Id := Make_Push_Label (Sloc (F));
436 Pop : constant Node_Id := Make_Pop_Label (Sloc (L));
437
438 begin
439 -- We make sure that a call to Get_Local_Raise_Call_Entity is
440 -- made during front end processing, so that when we need it
441 -- in the back end, it will already be available and loaded.
442
443 Discard_Node (Get_Local_Raise_Call_Entity);
444
445 -- Prepare and insert Push and Pop nodes
446
447 Set_Exception_Label (Push, Exception_Label (H));
448 Insert_Before (F, Push);
449 Set_Analyzed (Push);
450
451 Insert_After (L, Pop);
452 Set_Analyzed (Pop);
453 end;
454 end Generate_Push_Pop;
455
456 -- Local declarations
457
458 Loc : constant Source_Ptr := Sloc (HSS);
459 Stmts : List_Id := No_List;
460 Choice : Node_Id;
461 Excep : Entity_Id;
462
463 procedure Generate_Push_Pop_For_Constraint_Error is
464 new Generate_Push_Pop
465 (Exc_Locally_Handled => CE_Locally_Handled,
466 Make_Push_Label => Make_Push_Constraint_Error_Label,
467 Make_Pop_Label => Make_Pop_Constraint_Error_Label);
468 -- If no Push/Pop has been generated for CE yet, then set the flag
469 -- CE_Locally_Handled, allocate an Exception_Label for handler H (if
470 -- not already done), and generate Push/Pop nodes for the exception
471 -- label at the start and end of the statements of HSS.
472
473 procedure Generate_Push_Pop_For_Program_Error is
474 new Generate_Push_Pop
475 (Exc_Locally_Handled => PE_Locally_Handled,
476 Make_Push_Label => Make_Push_Program_Error_Label,
477 Make_Pop_Label => Make_Pop_Program_Error_Label);
478 -- If no Push/Pop has been generated for PE yet, then set the flag
479 -- PE_Locally_Handled, allocate an Exception_Label for handler H (if
480 -- not already done), and generate Push/Pop nodes for the exception
481 -- label at the start and end of the statements of HSS.
482
483 procedure Generate_Push_Pop_For_Storage_Error is
484 new Generate_Push_Pop
485 (Exc_Locally_Handled => SE_Locally_Handled,
486 Make_Push_Label => Make_Push_Storage_Error_Label,
487 Make_Pop_Label => Make_Pop_Storage_Error_Label);
488 -- If no Push/Pop has been generated for SE yet, then set the flag
489 -- SE_Locally_Handled, allocate an Exception_Label for handler H (if
490 -- not already done), and generate Push/Pop nodes for the exception
491 -- label at the start and end of the statements of HSS.
492
493 -- Start of processing for Expand_Local_Exception_Handlers
494
495 begin
496 -- No processing if all exception handlers will get removed
497
498 if Debug_Flag_Dot_X then
499 return;
500 end if;
501
502 -- See for each handler if we have any local raises to expand
503
504 Handler := First_Non_Pragma (Handlrs);
505 while Present (Handler) loop
506
507 -- Note, we do not test Local_Raise_Not_OK here, because in the
508 -- case of Push/Pop generation we want to generate push with a
509 -- null label. The Add_Exception_Label routine has no effect if
510 -- Local_Raise_Not_OK is set, so this works as required.
511
512 if Present (Local_Raise_Statements (Handler)) then
513 Add_Exception_Label (Handler);
514 end if;
515
516 -- If we are doing local raise to goto optimization (restriction
517 -- No_Exception_Propagation set or debug flag .g set), then check
518 -- to see if handler handles CE, PE, SE and if so generate the
519 -- appropriate push/pop sequence for the back end.
520
521 if (Debug_Flag_Dot_G
522 or else Restriction_Active (No_Exception_Propagation))
523 and then Has_Local_Raise (Handler)
524 then
525 Choice := First (Exception_Choices (Handler));
526 while Present (Choice) loop
527 if Nkind (Choice) = N_Others_Choice
528 and then not All_Others (Choice)
529 then
530 Generate_Push_Pop_For_Constraint_Error (Handler);
531 Generate_Push_Pop_For_Program_Error (Handler);
532 Generate_Push_Pop_For_Storage_Error (Handler);
533
534 elsif Is_Entity_Name (Choice) then
535 Excep := Get_Renamed_Entity (Entity (Choice));
536
537 if Excep = Standard_Constraint_Error then
538 Generate_Push_Pop_For_Constraint_Error (Handler);
539 elsif Excep = Standard_Program_Error then
540 Generate_Push_Pop_For_Program_Error (Handler);
541 elsif Excep = Standard_Storage_Error then
542 Generate_Push_Pop_For_Storage_Error (Handler);
543 end if;
544 end if;
545
546 Next (Choice);
547 end loop;
548 end if;
549
550 Next_Non_Pragma (Handler);
551 end loop;
552
553 -- Nothing to do if no handlers requiring the goto transformation
554
555 if not Local_Expansion_Required then
556 return;
557 end if;
558
559 -- Prepare to do the transformation
560
561 declare
562 -- L3 is the label to exit the HSS
563
564 L3_Dent : constant Entity_Id := Make_Temporary (Loc, 'L');
565
566 Labl_L3 : constant Node_Id :=
567 Make_Label (Loc,
568 Identifier => New_Occurrence_Of (L3_Dent, Loc));
569
570 Blk_Stm : Node_Id;
571 Relmt : Elmt_Id;
572
573 begin
574 Set_Exception_Junk (Labl_L3);
575 Add_Label_Declaration (L3_Dent);
576
577 -- Wrap existing statements and handlers in an inner block
578
579 Blk_Stm :=
580 Make_Block_Statement (Loc,
581 Handled_Statement_Sequence => Relocate_Node (HSS));
582 Set_Exception_Junk (Blk_Stm);
583
584 Rewrite (HSS,
585 Make_Handled_Sequence_Of_Statements (Loc,
586 Statements => New_List (Blk_Stm),
587 End_Label => Relocate_Node (End_Label (HSS))));
588
589 -- Set block statement as analyzed, we don't want to actually call
590 -- Analyze on this block, it would cause a recursion in exception
591 -- handler processing which would mess things up.
592
593 Set_Analyzed (Blk_Stm);
594
595 -- Now loop through the exception handlers to deal with those that
596 -- are targets of local raise statements.
597
598 Handler := First_Non_Pragma (Handlrs);
599 while Present (Handler) loop
600 if Present (Exception_Label (Handler)) then
601
602 -- This handler needs the goto expansion
603
604 declare
605 Loc : constant Source_Ptr := Sloc (Handler);
606
607 -- L1 is the start label for this handler
608
609 L1_Dent : constant Entity_Id := Exception_Label (Handler);
610
611 Labl_L1 : constant Node_Id :=
612 Make_Label (Loc,
613 Identifier =>
614 New_Occurrence_Of (L1_Dent, Loc));
615
616 -- Jump to L1 to be used as replacement for the original
617 -- handler (used in the case where exception propagation
618 -- may still occur).
619
620 Name_L1 : constant Node_Id :=
621 New_Occurrence_Of (L1_Dent, Loc);
622
623 Goto_L1 : constant Node_Id :=
624 Make_Goto_Statement (Loc,
625 Name => Name_L1);
626
627 -- Jump to L3 to be used at the end of handler
628
629 Name_L3 : constant Node_Id :=
630 New_Occurrence_Of (L3_Dent, Loc);
631
632 Goto_L3 : constant Node_Id :=
633 Make_Goto_Statement (Loc,
634 Name => Name_L3);
635
636 H_Stmts : constant List_Id := Statements (Handler);
637
638 begin
639 Set_Exception_Junk (Labl_L1);
640 Set_Exception_Junk (Goto_L3);
641
642 -- Note: we do NOT set Exception_Junk in Goto_L1, since
643 -- this is a real transfer of control that we want the
644 -- Sem_Ch6.Check_Returns procedure to recognize properly.
645
646 -- Replace handler by a goto L1. We can mark this as
647 -- analyzed since it is fully formed, and we don't
648 -- want it going through any further checks. We save
649 -- the last statement location in the goto L1 node for
650 -- the benefit of Sem_Ch6.Check_Returns.
651
652 Set_Statements (Handler, New_List (Goto_L1));
653 Set_Analyzed (Goto_L1);
654 Set_Etype (Name_L1, Standard_Void_Type);
655
656 -- Now replace all the raise statements by goto L1
657
658 if Present (Local_Raise_Statements (Handler)) then
659 Relmt := First_Elmt (Local_Raise_Statements (Handler));
660 while Present (Relmt) loop
661 declare
662 Raise_S : constant Node_Id := Node (Relmt);
663 RLoc : constant Source_Ptr := Sloc (Raise_S);
664 Name_L1 : constant Node_Id :=
665 New_Occurrence_Of (L1_Dent, Loc);
666 Goto_L1 : constant Node_Id :=
667 Make_Goto_Statement (RLoc,
668 Name => Name_L1);
669
670 begin
671 -- Replace raise by goto L1
672
673 Set_Analyzed (Goto_L1);
674 Set_Etype (Name_L1, Standard_Void_Type);
675 Replace_Raise_By_Goto (Raise_S, Goto_L1);
676 end;
677
678 Next_Elmt (Relmt);
679 end loop;
680 end if;
681
682 -- Add a goto L3 at end of statement list in block. The
683 -- first time, this is what skips over the exception
684 -- handlers in the normal case. Subsequent times, it
685 -- terminates the execution of the previous handler code,
686 -- and skips subsequent handlers.
687
688 Stmts := Statements (HSS);
689
690 Insert_After (Last (Stmts), Goto_L3);
691 Set_Analyzed (Goto_L3);
692 Set_Etype (Name_L3, Standard_Void_Type);
693
694 -- Now we drop the label that marks the handler start,
695 -- followed by the statements of the handler.
696
697 Set_Etype (Identifier (Labl_L1), Standard_Void_Type);
698
699 Insert_After_And_Analyze (Last (Stmts), Labl_L1);
700
701 declare
702 Loc : constant Source_Ptr := Sloc (First (H_Stmts));
703 Blk : constant Node_Id :=
704 Make_Block_Statement (Loc,
705 Handled_Statement_Sequence =>
706 Make_Handled_Sequence_Of_Statements (Loc,
707 Statements => H_Stmts));
708 begin
709 Set_Exception_Junk (Blk);
710 Insert_After_And_Analyze (Last (Stmts), Blk);
711 end;
712 end;
713
714 -- Here if we have local raise statements but the handler is
715 -- not suitable for processing with a local raise. In this
716 -- case we have to generate possible diagnostics.
717
718 elsif Has_Local_Raise (Handler)
719 and then Present (Local_Raise_Statements (Handler))
720 then
721 Relmt := First_Elmt (Local_Raise_Statements (Handler));
722 while Present (Relmt) loop
723 Warn_If_No_Propagation (Node (Relmt));
724 Next_Elmt (Relmt);
725 end loop;
726 end if;
727
728 Next (Handler);
729 end loop;
730
731 -- Only remaining step is to drop the L3 label and we are done
732
733 Set_Etype (Identifier (Labl_L3), Standard_Void_Type);
734
735 -- If we had at least one handler, then we drop the label after
736 -- the last statement of that handler.
737
738 if Stmts /= No_List then
739 Insert_After_And_Analyze (Last (Stmts), Labl_L3);
740
741 -- Otherwise we have removed all the handlers (this results from
742 -- use of pragma Restrictions (No_Exception_Propagation), and we
743 -- drop the label at the end of the statements of the HSS.
744
745 else
746 Insert_After_And_Analyze (Last (Statements (HSS)), Labl_L3);
747 end if;
748
749 return;
750 end;
751 end Expand_Local_Exception_Handlers;
752
753 ---------------------------
754 -- Replace_Raise_By_Goto --
755 ---------------------------
756
757 procedure Replace_Raise_By_Goto (Raise_S : Node_Id; Goto_L1 : Node_Id) is
758 Loc : constant Source_Ptr := Sloc (Raise_S);
759 Excep : Entity_Id;
760 LR : Node_Id;
761 Cond : Node_Id;
762 Orig : Node_Id;
763
764 begin
765 -- If we have a null statement, it means that there is no replacement
766 -- needed (typically this results from a suppressed check).
767
768 if Nkind (Raise_S) = N_Null_Statement then
769 return;
770
771 -- Test for Raise_xxx_Error
772
773 elsif Nkind (Raise_S) = N_Raise_Constraint_Error then
774 Excep := Standard_Constraint_Error;
775 Cond := Condition (Raise_S);
776
777 elsif Nkind (Raise_S) = N_Raise_Storage_Error then
778 Excep := Standard_Storage_Error;
779 Cond := Condition (Raise_S);
780
781 elsif Nkind (Raise_S) = N_Raise_Program_Error then
782 Excep := Standard_Program_Error;
783 Cond := Condition (Raise_S);
784
785 -- The only other possibility is a node that is or used to be a
786 -- simple raise statement. Note that the string expression in the
787 -- original Raise statement is ignored.
788
789 else
790 Orig := Original_Node (Raise_S);
791 pragma Assert (Nkind (Orig) = N_Raise_Statement
792 and then Present (Name (Orig)));
793 Excep := Entity (Name (Orig));
794 Cond := Empty;
795 end if;
796
797 -- Here Excep is the exception to raise, and Cond is the condition
798 -- First prepare the call to Local_Raise (excep'address).
799
800 if RTE_Available (RE_Local_Raise) then
801 LR :=
802 Make_Procedure_Call_Statement (Loc,
803 Name => New_Occurrence_Of (RTE (RE_Local_Raise), Loc),
804 Parameter_Associations => New_List (
805 Unchecked_Convert_To (RTE (RE_Address),
806 Make_Attribute_Reference (Loc,
807 Prefix => New_Occurrence_Of (Excep, Loc),
808 Attribute_Name => Name_Identity))));
809
810 -- Use null statement if Local_Raise not available
811
812 else
813 LR :=
814 Make_Null_Statement (Loc);
815 end if;
816
817 -- If there is no condition, we rewrite as
818
819 -- begin
820 -- Local_Raise (excep'Identity);
821 -- goto L1;
822 -- end;
823
824 if No (Cond) then
825 Rewrite (Raise_S,
826 Make_Block_Statement (Loc,
827 Handled_Statement_Sequence =>
828 Make_Handled_Sequence_Of_Statements (Loc,
829 Statements => New_List (LR, Goto_L1))));
830 Set_Exception_Junk (Raise_S);
831
832 -- If there is a condition, we rewrite as
833
834 -- if condition then
835 -- Local_Raise (excep'Identity);
836 -- goto L1;
837 -- end if;
838
839 else
840 Rewrite (Raise_S,
841 Make_If_Statement (Loc,
842 Condition => Cond,
843 Then_Statements => New_List (LR, Goto_L1)));
844 end if;
845
846 Analyze (Raise_S);
847 end Replace_Raise_By_Goto;
848
849 -- Start of processing for Expand_Exception_Handlers
850
851 begin
852 Expand_Local_Exception_Handlers;
853
854 -- Loop through handlers
855
856 Handler := First_Non_Pragma (Handlrs);
857 Handler_Loop : while Present (Handler) loop
858 Process_Statements_For_Controlled_Objects (Handler);
859
860 Next_Handler := Next_Non_Pragma (Handler);
861
862 -- Remove source handler if gnat debug flag .x is set
863
864 if Debug_Flag_Dot_X and then Comes_From_Source (Handler) then
865 Remove (Handler);
866
867 -- Remove handler if no exception propagation, generating a warning
868 -- if a source generated handler was not the target of a local raise.
869
870 else
871 if not Has_Local_Raise (Handler)
872 and then Comes_From_Source (Handler)
873 then
874 Warn_If_No_Local_Raise (Handler);
875 end if;
876
877 if No_Exception_Propagation_Active then
878 Remove (Handler);
879
880 -- Exception handler is active and retained and must be processed
881
882 else
883 -- If an exception occurrence is present, then we must declare
884 -- it and initialize it from the value stored in the TSD
885
886 -- declare
887 -- name : Exception_Occurrence;
888 -- begin
889 -- Save_Occurrence (name, Get_Current_Excep.all)
890 -- ...
891 -- end;
892
893 -- This expansion is only performed when using CodePeer.
894 -- Gigi will insert a call to initialize the choice parameter.
895
896 if Present (Choice_Parameter (Handler))
897 and then CodePeer_Mode
898 then
899 declare
900 Cparm : constant Entity_Id := Choice_Parameter (Handler);
901 Cloc : constant Source_Ptr := Sloc (Cparm);
902 Hloc : constant Source_Ptr := Sloc (Handler);
903 Save : Node_Id;
904
905 begin
906 -- Note: No_Location used to hide code from the debugger,
907 -- so single stepping doesn't jump back and forth.
908
909 Save :=
910 Make_Procedure_Call_Statement (No_Location,
911 Name =>
912 New_Occurrence_Of
913 (RTE (RE_Save_Occurrence), No_Location),
914 Parameter_Associations => New_List (
915 New_Occurrence_Of (Cparm, No_Location),
916 Make_Explicit_Dereference (No_Location,
917 Prefix =>
918 Make_Function_Call (No_Location,
919 Name =>
920 Make_Explicit_Dereference (No_Location,
921 Prefix =>
922 New_Occurrence_Of
923 (RTE (RE_Get_Current_Excep),
924 No_Location))))));
925
926 Mark_Rewrite_Insertion (Save);
927 Prepend (Save, Statements (Handler));
928
929 Obj_Decl :=
930 Make_Object_Declaration (Cloc,
931 Defining_Identifier => Cparm,
932 Object_Definition =>
933 New_Occurrence_Of
934 (RTE (RE_Exception_Occurrence), Cloc));
935 Set_No_Initialization (Obj_Decl, True);
936
937 Rewrite (Handler,
938 Make_Exception_Handler (Hloc,
939 Choice_Parameter => Empty,
940 Exception_Choices => Exception_Choices (Handler),
941 Statements => New_List (
942 Make_Block_Statement (Hloc,
943 Declarations => New_List (Obj_Decl),
944 Handled_Statement_Sequence =>
945 Make_Handled_Sequence_Of_Statements (Hloc,
946 Statements => Statements (Handler))))));
947
948 -- Local raise statements can't occur, since exception
949 -- handlers with choice parameters are not allowed when
950 -- No_Exception_Propagation applies, so set attributes
951 -- accordingly.
952
953 Set_Local_Raise_Statements (Handler, No_Elist);
954 Set_Local_Raise_Not_OK (Handler);
955
956 Analyze_List
957 (Statements (Handler), Suppress => All_Checks);
958 end;
959 end if;
960 end if;
961 end if;
962
963 Handler := Next_Handler;
964 end loop Handler_Loop;
965
966 -- If all handlers got removed, then remove the list. Note we cannot
967 -- reference HSS here, since expanding local handlers may have buried
968 -- the handlers in an inner block.
969
970 if Is_Empty_List (Handlrs) then
971 Set_Exception_Handlers (Parent (Handlrs), No_List);
972 end if;
973 end Expand_Exception_Handlers;
974
975 ------------------------------------
976 -- Expand_N_Exception_Declaration --
977 ------------------------------------
978
979 -- Generates:
980 -- exceptE : constant String := "A.B.EXCEP"; -- static data
981 -- except : exception_data :=
982 -- (Handled_By_Other => False,
983 -- Lang => 'A',
984 -- Name_Length => exceptE'Length,
985 -- Full_Name => exceptE'Address,
986 -- HTable_Ptr => null,
987 -- Foreign_Data => null,
988 -- Raise_Hook => null);
989
990 -- (protecting test only needed if not at library level)
991
992 -- exceptF : aliased System.Atomic_Operations.Test_And_Set.
993 -- .Test_And_Set_Flag; -- static data
994 -- if not Atomic_Test_And_Set (exceptF) then
995 -- Register_Exception (except'Unrestricted_Access);
996 -- end if;
997
998 -- If a No_Tasking restriction is in effect, or if Test_And_Set_Flag
999 -- is unavailable, then use Boolean instead. In that case, we generate:
1000 --
1001 -- exceptF : Boolean := True; -- static data
1002 -- if exceptF then
1003 -- ExceptF := False;
1004 -- Register_Exception (except'Unrestricted_Access);
1005 -- end if;
1006
1007 procedure Expand_N_Exception_Declaration (N : Node_Id) is
1008 Id : constant Entity_Id := Defining_Identifier (N);
1009 Loc : constant Source_Ptr := Sloc (N);
1010
1011 procedure Force_Static_Allocation_Of_Referenced_Objects
1012 (Aggregate : Node_Id);
1013 -- A specialized solution to one particular case of an ugly problem
1014 --
1015 -- The given aggregate includes an Unchecked_Conversion as one of the
1016 -- component values. The call to Analyze_And_Resolve below ends up
1017 -- calling Exp_Ch4.Expand_N_Unchecked_Type_Conversion, which may decide
1018 -- to introduce a (constant) temporary and then obtain the component
1019 -- value by evaluating the temporary.
1020 --
1021 -- In the case of an exception declared within a subprogram (or any
1022 -- other dynamic scope), this is a bad transformation. The exception
1023 -- object is marked as being Statically_Allocated but the temporary is
1024 -- not. If the initial value of a Statically_Allocated declaration
1025 -- references a dynamically allocated object, this prevents static
1026 -- initialization of the object.
1027 --
1028 -- We cope with this here by marking the temporary Statically_Allocated.
1029 -- It might seem cleaner to generalize this utility and then use it to
1030 -- enforce a rule that the entities referenced in the declaration of any
1031 -- "hoisted" (i.e., Is_Statically_Allocated and not Is_Library_Level)
1032 -- entity must also be either Library_Level or hoisted. It turns out
1033 -- that this would be incompatible with the current treatment of an
1034 -- object which is local to a subprogram, subject to an Export pragma,
1035 -- not subject to an address clause, and whose declaration contains
1036 -- references to other local (non-hoisted) objects (e.g., in the initial
1037 -- value expression).
1038
1039 function Null_String return String_Id;
1040 -- Build a null-terminated empty string
1041
1042 ---------------------------------------------------
1043 -- Force_Static_Allocation_Of_Referenced_Objects --
1044 ---------------------------------------------------
1045
1046 procedure Force_Static_Allocation_Of_Referenced_Objects
1047 (Aggregate : Node_Id)
1048 is
1049 function Fixup_Node (N : Node_Id) return Traverse_Result;
1050 -- If the given node references a dynamically allocated object, then
1051 -- correct the declaration of the object.
1052
1053 ----------------
1054 -- Fixup_Node --
1055 ----------------
1056
1057 function Fixup_Node (N : Node_Id) return Traverse_Result is
1058 begin
1059 if Nkind (N) in N_Has_Entity
1060 and then Present (Entity (N))
1061 and then not Is_Library_Level_Entity (Entity (N))
1062
1063 -- Note: the following test is not needed but it seems cleaner
1064 -- to do this test (this would be more important if procedure
1065 -- Force_Static_Allocation_Of_Referenced_Objects recursively
1066 -- traversed the declaration of an entity after marking it as
1067 -- statically allocated).
1068
1069 and then not Is_Statically_Allocated (Entity (N))
1070 then
1071 Set_Is_Statically_Allocated (Entity (N));
1072 end if;
1073
1074 return OK;
1075 end Fixup_Node;
1076
1077 procedure Fixup_Tree is new Traverse_Proc (Fixup_Node);
1078
1079 -- Start of processing for Force_Static_Allocation_Of_Referenced_Objects
1080
1081 begin
1082 Fixup_Tree (Aggregate);
1083 end Force_Static_Allocation_Of_Referenced_Objects;
1084
1085 -----------------
1086 -- Null_String --
1087 -----------------
1088
1089 function Null_String return String_Id is
1090 begin
1091 Start_String;
1092 Store_String_Char (Get_Char_Code (ASCII.NUL));
1093 return End_String;
1094 end Null_String;
1095
1096 -- Local variables
1097
1098 Ex_Id : Entity_Id;
1099 Ex_Val : String_Id;
1100 Flag_Id : Entity_Id;
1101 L : List_Id;
1102
1103 -- Start of processing for Expand_N_Exception_Declaration
1104
1105 begin
1106 -- Definition of the external name: nam : constant String := "A.B.NAME";
1107
1108 Ex_Id :=
1109 Make_Defining_Identifier (Loc, New_External_Name (Chars (Id), 'E'));
1110
1111 -- Do not generate an external name if the exception declaration is
1112 -- subject to pragma Discard_Names. Use a null-terminated empty name
1113 -- to ensure that Ada.Exceptions.Exception_Name functions properly.
1114
1115 if Global_Discard_Names or else Discard_Names (Ex_Id) then
1116 Ex_Val := Null_String;
1117
1118 -- Otherwise generate the fully qualified name of the exception
1119
1120 else
1121 Ex_Val := Fully_Qualified_Name_String (Id);
1122 end if;
1123
1124 Insert_Action (N,
1125 Make_Object_Declaration (Loc,
1126 Defining_Identifier => Ex_Id,
1127 Constant_Present => True,
1128 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
1129 Expression => Make_String_Literal (Loc, Ex_Val)));
1130
1131 Set_Is_Statically_Allocated (Ex_Id);
1132
1133 -- Create the aggregate list for type Standard.Exception_Type:
1134 -- Not_Handled_By_Others component: False
1135
1136 L := Empty_List;
1137 Append_To (L, New_Occurrence_Of (Standard_False, Loc));
1138
1139 -- Lang component: 'A'
1140
1141 Append_To (L,
1142 Make_Character_Literal (Loc,
1143 Chars => Name_uA,
1144 Char_Literal_Value => UI_From_CC (Get_Char_Code ('A'))));
1145
1146 -- Name_Length component: Nam'Length
1147
1148 Append_To (L,
1149 Make_Attribute_Reference (Loc,
1150 Prefix => New_Occurrence_Of (Ex_Id, Loc),
1151 Attribute_Name => Name_Length));
1152
1153 -- Full_Name component: Standard_Address?(Nam'Address)
1154 -- or 0 if CodePeer_Mode
1155
1156 if CodePeer_Mode then
1157 Append_To (L, Make_Integer_Literal (Loc, Uint_0));
1158 else
1159 Append_To (L, OK_Convert_To (Standard_Address,
1160 Make_Attribute_Reference (Loc,
1161 Prefix => New_Occurrence_Of (Ex_Id, Loc),
1162 Attribute_Name => Name_Address)));
1163 end if;
1164
1165 -- HTable_Ptr component: null
1166
1167 Append_To (L, Make_Null (Loc));
1168
1169 -- Foreign_Data component: null address
1170
1171 Append_To (L, Make_Integer_Literal (Loc, Uint_0));
1172
1173 -- Raise_Hook component: null
1174
1175 Append_To (L, Make_Null (Loc));
1176
1177 Set_Expression (N, Make_Aggregate (Loc, Expressions => L));
1178 Analyze_And_Resolve (Expression (N), Etype (Id));
1179
1180 Force_Static_Allocation_Of_Referenced_Objects (Expression (N));
1181
1182 -- Register_Exception (except'Unrestricted_Access);
1183
1184 if not No_Exception_Handlers_Set
1185 and then not Restriction_Active (No_Exception_Registration)
1186 then
1187 L := New_List (
1188 Make_Procedure_Call_Statement (Loc,
1189 Name =>
1190 New_Occurrence_Of (RTE (RE_Register_Exception), Loc),
1191 Parameter_Associations => New_List (
1192 Unchecked_Convert_To (RTE (RE_Exception_Data_Ptr),
1193 Make_Attribute_Reference (Loc,
1194 Prefix => New_Occurrence_Of (Id, Loc),
1195 Attribute_Name => Name_Unrestricted_Access)))));
1196
1197 Set_Register_Exception_Call (Id, First (L));
1198
1199 if not Is_Library_Level_Entity (Id) then
1200 Flag_Id :=
1201 Make_Defining_Identifier (Loc,
1202 Chars => New_External_Name (Chars (Id), 'F'));
1203 Set_Is_Statically_Allocated (Flag_Id);
1204
1205 declare
1206 Use_Test_And_Set_Flag : constant Boolean :=
1207 not Global_No_Tasking
1208 and then RTE_Available (RE_Test_And_Set_Flag);
1209
1210 Flag_Decl : Node_Id;
1211 Condition : Node_Id;
1212 begin
1213 if Use_Test_And_Set_Flag then
1214 Flag_Decl :=
1215 Make_Object_Declaration (Loc,
1216 Defining_Identifier => Flag_Id,
1217 Aliased_Present => True,
1218 Object_Definition =>
1219 New_Occurrence_Of (RTE (RE_Test_And_Set_Flag), Loc));
1220 else
1221 Flag_Decl :=
1222 Make_Object_Declaration (Loc,
1223 Defining_Identifier => Flag_Id,
1224 Object_Definition =>
1225 New_Occurrence_Of (Standard_Boolean, Loc),
1226 Expression =>
1227 New_Occurrence_Of (Standard_True, Loc));
1228 end if;
1229
1230 Insert_Action (N, Flag_Decl);
1231
1232 if Use_Test_And_Set_Flag then
1233 Condition :=
1234 Make_Op_Not (Loc,
1235 Make_Function_Call (Loc,
1236 Name => New_Occurrence_Of
1237 (RTE (RE_Atomic_Test_And_Set), Loc),
1238 Parameter_Associations =>
1239 New_List (New_Occurrence_Of (Flag_Id, Loc))));
1240 else
1241 Condition := New_Occurrence_Of (Flag_Id, Loc);
1242
1243 Append_To (L,
1244 Make_Assignment_Statement (Loc,
1245 Name => New_Occurrence_Of (Flag_Id, Loc),
1246 Expression => New_Occurrence_Of (Standard_False, Loc)));
1247 end if;
1248
1249 Insert_After_And_Analyze (N,
1250 Make_Implicit_If_Statement (N,
1251 Condition => Condition,
1252 Then_Statements => L));
1253 end;
1254 else
1255 Insert_List_After_And_Analyze (N, L);
1256 end if;
1257 end if;
1258 end Expand_N_Exception_Declaration;
1259
1260 ---------------------------------------------
1261 -- Expand_N_Handled_Sequence_Of_Statements --
1262 ---------------------------------------------
1263
1264 procedure Expand_N_Handled_Sequence_Of_Statements (N : Node_Id) is
1265 begin
1266 -- Expand exception handlers
1267
1268 if Present (Exception_Handlers (N))
1269 and then not Restriction_Active (No_Exception_Handlers)
1270 then
1271 Expand_Exception_Handlers (N);
1272 end if;
1273
1274 -- If local exceptions are being expanded, the previous call will
1275 -- have rewritten the construct as a block and reanalyzed it. No
1276 -- further expansion is needed.
1277
1278 if Analyzed (N) then
1279 return;
1280 end if;
1281
1282 -- Add cleanup actions if required. No cleanup actions are needed in
1283 -- thunks associated with interfaces, because they only displace the
1284 -- pointer to the object. For extended return statements, we need
1285 -- cleanup actions if the Handled_Statement_Sequence contains generated
1286 -- objects of controlled types, for example. We do not want to clean up
1287 -- the return object.
1288
1289 if Nkind (Parent (N)) not in N_Accept_Statement
1290 | N_Extended_Return_Statement
1291 | N_Package_Body
1292 and then not Delay_Cleanups (Current_Scope)
1293 and then not Is_Thunk (Current_Scope)
1294 then
1295 Expand_Cleanup_Actions (Parent (N));
1296
1297 elsif Nkind (Parent (N)) = N_Extended_Return_Statement
1298 and then Handled_Statement_Sequence (Parent (N)) = N
1299 and then not Delay_Cleanups (Current_Scope)
1300 then
1301 pragma Assert (not Is_Thunk (Current_Scope));
1302 Expand_Cleanup_Actions (Parent (N));
1303 end if;
1304
1305 if Present (Finally_Statements (N)) and then Abort_Allowed then
1306 if Exceptions_OK then
1307 Set_Finally_Statements
1308 (N,
1309 New_List
1310 (Build_Runtime_Call (Sloc (N), RE_Abort_Defer),
1311 Build_Abort_Undefer_Block
1312 (Sloc (N),
1313 Stmts => Finally_Statements (N),
1314 Context => N)));
1315 else
1316 Prepend_To
1317 (Finally_Statements (N),
1318 Build_Runtime_Call (Sloc (N), RE_Abort_Defer));
1319
1320 Append_To
1321 (Finally_Statements (N),
1322 Build_Runtime_Call (Sloc (N), RE_Abort_Undefer));
1323 end if;
1324
1325 Analyze_List (Finally_Statements (N));
1326 end if;
1327 end Expand_N_Handled_Sequence_Of_Statements;
1328
1329 -------------------------------------
1330 -- Expand_N_Raise_Constraint_Error --
1331 -------------------------------------
1332
1333 procedure Expand_N_Raise_Constraint_Error (N : Node_Id) is
1334 begin
1335 -- We adjust the condition to deal with the C/Fortran boolean case. This
1336 -- may well not be necessary, as all such conditions are generated by
1337 -- the expander and probably are all standard boolean, but who knows
1338 -- what strange optimization in future may require this adjustment.
1339
1340 Adjust_Condition (Condition (N));
1341
1342 -- Now deal with possible local raise handling
1343
1344 Possible_Local_Raise (N, Standard_Constraint_Error);
1345 end Expand_N_Raise_Constraint_Error;
1346
1347 -------------------------------
1348 -- Expand_N_Raise_Expression --
1349 -------------------------------
1350
1351 procedure Expand_N_Raise_Expression (N : Node_Id) is
1352 Loc : constant Source_Ptr := Sloc (N);
1353 Typ : constant Entity_Id := Etype (N);
1354 RCE : Node_Id;
1355
1356 begin
1357 Possible_Local_Raise (N, Entity (Name (N)));
1358
1359 -- Later we must teach the back end/gigi how to deal with this, but
1360 -- for now we will assume the type is Standard_Boolean and transform
1361 -- the node to:
1362
1363 -- do
1364 -- raise X [with string]
1365 -- in
1366 -- raise Constraint_Error;
1367
1368 -- The raise constraint error can never be executed. It is just a dummy
1369 -- node that can be labeled with an arbitrary type.
1370
1371 RCE := Make_Raise_Constraint_Error (Loc, Reason => CE_Explicit_Raise);
1372 Set_Etype (RCE, Typ);
1373
1374 Rewrite (N,
1375 Make_Expression_With_Actions (Loc,
1376 Actions => New_List (
1377 Make_Raise_Statement (Loc,
1378 Name => Name (N),
1379 Expression => Expression (N))),
1380 Expression => RCE));
1381
1382 Analyze_And_Resolve (N, Typ);
1383 end Expand_N_Raise_Expression;
1384
1385 ----------------------------------
1386 -- Expand_N_Raise_Program_Error --
1387 ----------------------------------
1388
1389 procedure Expand_N_Raise_Program_Error (N : Node_Id) is
1390 begin
1391 -- We adjust the condition to deal with the C/Fortran boolean case. This
1392 -- may well not be necessary, as all such conditions are generated by
1393 -- the expander and probably are all standard boolean, but who knows
1394 -- what strange optimization in future may require this adjustment.
1395
1396 Adjust_Condition (Condition (N));
1397
1398 -- Now deal with possible local raise handling
1399
1400 Possible_Local_Raise (N, Standard_Program_Error);
1401 end Expand_N_Raise_Program_Error;
1402
1403 ------------------------------
1404 -- Expand_N_Raise_Statement --
1405 ------------------------------
1406
1407 procedure Expand_N_Raise_Statement (N : Node_Id) is
1408 Loc : constant Source_Ptr := Sloc (N);
1409 Ehand : Node_Id;
1410 E : Entity_Id;
1411 Str : String_Id;
1412 H : Node_Id;
1413 Src : Boolean;
1414
1415 begin
1416 -- Processing for locally handled exception (exclude reraise case)
1417
1418 if Present (Name (N)) and then Is_Entity_Name (Name (N)) then
1419 if Debug_Flag_Dot_G
1420 or else Restriction_Active (No_Exception_Propagation)
1421 then
1422 -- If we have a local handler, then note that this is potentially
1423 -- able to be transformed into a goto statement.
1424
1425 H := Find_Local_Handler (Entity (Name (N)), N);
1426
1427 if Present (H) then
1428 if No (Local_Raise_Statements (H)) then
1429 Set_Local_Raise_Statements (H, New_Elmt_List);
1430 end if;
1431
1432 -- Append the new entry if it is not there already. Sometimes
1433 -- we have situations where due to reexpansion, the same node
1434 -- is analyzed twice and would otherwise be added twice.
1435
1436 Append_Unique_Elmt (N, Local_Raise_Statements (H));
1437 Set_Has_Local_Raise (H);
1438
1439 -- If no local handler, then generate no propagation warning
1440
1441 else
1442 Warn_If_No_Propagation (N);
1443 end if;
1444
1445 end if;
1446 end if;
1447
1448 -- If a string expression is present, then the raise statement is
1449 -- converted to a call:
1450 -- Raise_Exception (exception-name'Identity, string);
1451 -- and there is nothing else to do.
1452
1453 if Present (Expression (N)) then
1454
1455 -- Adjust message to deal with Prefix_Exception_Messages. We only
1456 -- add the prefix to string literals, if the message is being
1457 -- constructed, we assume it already deals with uniqueness.
1458
1459 if Prefix_Exception_Messages
1460 and then Nkind (Expression (N)) = N_String_Literal
1461 then
1462 declare
1463 Buf : Bounded_String;
1464 begin
1465 Add_Source_Info (Buf, Loc, Name_Enclosing_Entity);
1466 Append (Buf, ": ");
1467 Append (Buf, Strval (Expression (N)));
1468 Rewrite (Expression (N), Make_String_Literal (Loc, +Buf));
1469 Analyze_And_Resolve (Expression (N), Standard_String);
1470 end;
1471 end if;
1472
1473 -- Avoid passing exception-name'identity in runtimes in which this
1474 -- argument is not used. This avoids generating undefined references
1475 -- to these exceptions when compiling with no optimization
1476
1477 if Configurable_Run_Time_On_Target
1478 and then (Restriction_Active (No_Exception_Handlers)
1479 or else
1480 Restriction_Active (No_Exception_Propagation))
1481 then
1482 Rewrite (N,
1483 Make_Procedure_Call_Statement (Loc,
1484 Name => New_Occurrence_Of (RTE (RE_Raise_Exception), Loc),
1485 Parameter_Associations => New_List (
1486 New_Occurrence_Of (RTE (RE_Null_Id), Loc),
1487 Expression (N))));
1488 else
1489 Rewrite (N,
1490 Make_Procedure_Call_Statement (Loc,
1491 Name => New_Occurrence_Of (RTE (RE_Raise_Exception), Loc),
1492 Parameter_Associations => New_List (
1493 Make_Attribute_Reference (Loc,
1494 Prefix => Name (N),
1495 Attribute_Name => Name_Identity),
1496 Expression (N))));
1497 end if;
1498
1499 Analyze (N);
1500 return;
1501 end if;
1502
1503 -- Remaining processing is for the case where no string expression is
1504 -- present.
1505
1506 -- Don't expand a raise statement that does not come from source if we
1507 -- have already had configurable run-time violations, since most likely
1508 -- it will be junk cascaded nonsense.
1509
1510 if Configurable_Run_Time_Violations > 0
1511 and then not Comes_From_Source (N)
1512 then
1513 return;
1514 end if;
1515
1516 -- Convert explicit raise of Program_Error, Constraint_Error, and
1517 -- Storage_Error into the corresponding raise (in High_Integrity_Mode
1518 -- all other raises will get normal expansion and be disallowed,
1519 -- but this is also faster in all modes). Propagate Comes_From_Source
1520 -- flag to the new node.
1521
1522 if Present (Name (N)) and then Is_Entity_Name (Name (N)) then
1523 Src := Comes_From_Source (N);
1524
1525 if Entity (Name (N)) = Standard_Constraint_Error then
1526 Rewrite (N,
1527 Make_Raise_Constraint_Error (Loc, Reason => CE_Explicit_Raise));
1528 Set_Comes_From_Source (N, Src);
1529 Analyze (N);
1530 return;
1531
1532 elsif Entity (Name (N)) = Standard_Program_Error then
1533 Rewrite (N,
1534 Make_Raise_Program_Error (Loc, Reason => PE_Explicit_Raise));
1535 Set_Comes_From_Source (N, Src);
1536 Analyze (N);
1537 return;
1538
1539 elsif Entity (Name (N)) = Standard_Storage_Error then
1540 Rewrite (N,
1541 Make_Raise_Storage_Error (Loc, Reason => SE_Explicit_Raise));
1542 Set_Comes_From_Source (N, Src);
1543 Analyze (N);
1544 return;
1545 end if;
1546 end if;
1547
1548 -- Case of name present, in this case we expand raise name to
1549
1550 -- Raise_Exception (name'Identity, location_string);
1551
1552 -- where location_string identifies the file/line of the raise
1553
1554 if Present (Name (N)) and then Is_Entity_Name (Name (N)) then
1555 declare
1556 Id : Entity_Id := Entity (Name (N));
1557 Buf : Bounded_String;
1558
1559 begin
1560 Build_Location_String (Buf, Loc);
1561
1562 -- If the exception is a renaming, use the exception that it
1563 -- renames (which might be a predefined exception, e.g.).
1564
1565 if Present (Renamed_Entity (Id)) then
1566 Id := Renamed_Entity (Id);
1567 end if;
1568
1569 -- Build a C-compatible string in case of no exception handlers,
1570 -- since this is what the last chance handler is expecting.
1571
1572 if No_Exception_Handlers_Set then
1573
1574 -- Generate an empty message if configuration pragma
1575 -- Suppress_Exception_Locations is set for this unit.
1576
1577 if Opt.Exception_Locations_Suppressed then
1578 Buf.Length := 0;
1579 end if;
1580
1581 Append (Buf, ASCII.NUL);
1582 end if;
1583
1584 if Opt.Exception_Locations_Suppressed then
1585 Buf.Length := 0;
1586 end if;
1587
1588 Str := String_From_Name_Buffer (Buf);
1589
1590 -- Convert raise to call to the Raise_Exception routine
1591
1592 Rewrite (N,
1593 Make_Procedure_Call_Statement (Loc,
1594 Name =>
1595 New_Occurrence_Of (RTE (RE_Raise_Exception), Loc),
1596 Parameter_Associations => New_List (
1597 Make_Attribute_Reference (Loc,
1598 Prefix => Name (N),
1599 Attribute_Name => Name_Identity),
1600 Make_String_Literal (Loc, Strval => Str))));
1601 end;
1602
1603 -- Case of no name present (reraise). We rewrite the raise to:
1604
1605 -- Reraise_Occurrence_Always (EO);
1606
1607 -- where EO is the current exception occurrence. If the current handler
1608 -- does not have a choice parameter specification, then we provide one.
1609
1610 else
1611 -- Bypass expansion to a run-time call when back-end exception
1612 -- handling is active, unless the target is CodePeer, where
1613 -- raising an exception is treated as an error.
1614
1615 if not CodePeer_Mode then
1616 return;
1617 end if;
1618
1619 -- Find innermost enclosing exception handler (there must be one,
1620 -- since the semantics has already verified that this raise statement
1621 -- is valid, and a raise with no arguments is only permitted in the
1622 -- context of an exception handler).
1623
1624 Ehand := Parent (N);
1625 while Nkind (Ehand) /= N_Exception_Handler loop
1626 Ehand := Parent (Ehand);
1627 end loop;
1628
1629 -- Make exception choice parameter if none present. Note that we do
1630 -- not need to put the entity on the entity chain, since no one will
1631 -- be referencing this entity by normal visibility methods.
1632
1633 if No (Choice_Parameter (Ehand)) then
1634 E := Make_Temporary (Loc, 'E');
1635 Set_Choice_Parameter (Ehand, E);
1636 Mutate_Ekind (E, E_Variable);
1637 Set_Etype (E, RTE (RE_Exception_Occurrence));
1638 Set_Scope (E, Current_Scope);
1639 end if;
1640
1641 -- Now rewrite the raise as a call to Reraise. A special case arises
1642 -- if this raise statement occurs in the context of a handler for
1643 -- all others (i.e. an at end handler). in this case we avoid
1644 -- the call to defer abort, cleanup routines are expected to be
1645 -- called in this case with aborts deferred.
1646
1647 declare
1648 Ech : constant Node_Id := First (Exception_Choices (Ehand));
1649 Ent : Entity_Id;
1650
1651 begin
1652 if Nkind (Ech) = N_Others_Choice
1653 and then All_Others (Ech)
1654 then
1655 Ent := RTE (RE_Reraise_Occurrence_No_Defer);
1656 else
1657 Ent := RTE (RE_Reraise_Occurrence_Always);
1658 end if;
1659
1660 Rewrite (N,
1661 Make_Procedure_Call_Statement (Loc,
1662 Name => New_Occurrence_Of (Ent, Loc),
1663 Parameter_Associations => New_List (
1664 New_Occurrence_Of (Choice_Parameter (Ehand), Loc))));
1665 end;
1666 end if;
1667
1668 Analyze (N);
1669 end Expand_N_Raise_Statement;
1670
1671 -----------------------------------
1672 -- Expand_N_Raise_When_Statement --
1673 -----------------------------------
1674
1675 procedure Expand_N_Raise_When_Statement (N : Node_Id) is
1676 Loc : constant Source_Ptr := Sloc (N);
1677 begin
1678 Rewrite (N,
1679 Make_If_Statement (Loc,
1680 Condition => Condition (N),
1681 Then_Statements => New_List (
1682 Make_Raise_Statement (Loc,
1683 Name => Name (N),
1684 Expression => Expression (N)))));
1685
1686 Analyze (N);
1687 end Expand_N_Raise_When_Statement;
1688
1689 ----------------------------------
1690 -- Expand_N_Raise_Storage_Error --
1691 ----------------------------------
1692
1693 procedure Expand_N_Raise_Storage_Error (N : Node_Id) is
1694 begin
1695 -- We adjust the condition to deal with the C/Fortran boolean case. This
1696 -- may well not be necessary, as all such conditions are generated by
1697 -- the expander and probably are all standard boolean, but who knows
1698 -- what strange optimization in future may require this adjustment.
1699
1700 Adjust_Condition (Condition (N));
1701
1702 -- Now deal with possible local raise handling
1703
1704 Possible_Local_Raise (N, Standard_Storage_Error);
1705 end Expand_N_Raise_Storage_Error;
1706
1707 --------------------------
1708 -- Possible_Local_Raise --
1709 --------------------------
1710
1711 procedure Possible_Local_Raise (N : Node_Id; E : Entity_Id) is
1712 begin
1713 -- Nothing to do if local raise optimization not active
1714
1715 if not Debug_Flag_Dot_G
1716 and then not Restriction_Active (No_Exception_Propagation)
1717 then
1718 return;
1719 end if;
1720
1721 -- Nothing to do if original node was an explicit raise, because in
1722 -- that case, we already generated the required warning for the raise.
1723
1724 if Nkind (Original_Node (N)) = N_Raise_Statement then
1725 return;
1726 end if;
1727
1728 -- Otherwise see if we have a local handler for the exception
1729
1730 declare
1731 H : constant Node_Id := Find_Local_Handler (E, N);
1732
1733 begin
1734 -- If so, mark that it has a local raise
1735
1736 if Present (H) then
1737 Set_Has_Local_Raise (H, True);
1738
1739 -- Otherwise, if the No_Exception_Propagation restriction is active
1740 -- and the warning is enabled, generate the appropriate warnings.
1741
1742 -- ??? Do not do it for the Call_Marker nodes inserted by the ABE
1743 -- mechanism because this generates too many false positives, or
1744 -- for generic instantiations for the same reason.
1745
1746 elsif Warn_On_Non_Local_Exception
1747 and then Restriction_Active (No_Exception_Propagation)
1748 and then Nkind (N) /= N_Call_Marker
1749 and then Nkind (N) not in N_Generic_Instantiation
1750 then
1751 Warn_No_Exception_Propagation_Active (N);
1752
1753 if Configurable_Run_Time_Mode then
1754 Error_Msg_NE
1755 ("\?.x?& may call Last_Chance_Handler", N, E);
1756 else
1757 Error_Msg_NE
1758 ("\?.x?& may result in unhandled exception", N, E);
1759 end if;
1760 end if;
1761 end;
1762 end Possible_Local_Raise;
1763
1764 ------------------------
1765 -- Find_Local_Handler --
1766 ------------------------
1767
1768 function Find_Local_Handler
1769 (Ename : Entity_Id;
1770 Nod : Node_Id) return Node_Id
1771 is
1772 N : Node_Id;
1773 P : Node_Id;
1774 H : Node_Id;
1775 C : Node_Id;
1776
1777 SSE : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
1778 -- This is used to test for wrapped actions below
1779
1780 ERaise : Entity_Id;
1781 EHandle : Entity_Id;
1782 -- The entity Id's for the exception we are raising and handling, using
1783 -- the renamed exception if a Renamed_Entity is present.
1784
1785 begin
1786 -- Never any local handler if all handlers removed
1787
1788 if Debug_Flag_Dot_X then
1789 return Empty;
1790 end if;
1791
1792 -- Get the exception we are raising, allowing for renaming
1793
1794 ERaise := Get_Renamed_Entity (Ename);
1795
1796 -- We need to check if the node we are looking at is contained in
1797 --
1798
1799 -- Loop to search up the tree
1800
1801 N := Nod;
1802 loop
1803 P := Parent (N);
1804
1805 -- If we get to the top of the tree, or to a subprogram, task, entry,
1806 -- protected body, or accept statement without having found a
1807 -- matching handler, then there is no local handler.
1808
1809 if No (P)
1810 or else Nkind (P) = N_Subprogram_Body
1811 or else Nkind (P) = N_Task_Body
1812 or else Nkind (P) = N_Protected_Body
1813 or else Nkind (P) = N_Entry_Body
1814 or else Nkind (P) = N_Accept_Statement
1815 then
1816 return Empty;
1817
1818 -- Test for handled sequence of statements with at least one
1819 -- exception handler which might be the one we are looking for.
1820
1821 -- We need to check if the node N is covered by the statement part of
1822 -- P rather than one of its exception handlers (an exception handler
1823 -- obviously does not cover its own statements).
1824
1825 -- This test is more delicate than might be thought. It is not just
1826 -- a matter of checking the Statements (P), because the node might be
1827 -- waiting to be wrapped in a transient scope, in which case it will
1828 -- end up in the block statements, even though it is not there now.
1829
1830 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
1831 and then Is_List_Member (N)
1832 and then List_Containing (N) in Statements (P)
1833 | SSE.Actions_To_Be_Wrapped (Before)
1834 | SSE.Actions_To_Be_Wrapped (After)
1835 | SSE.Actions_To_Be_Wrapped (Cleanup)
1836 then
1837 -- Loop through exception handlers and guard against pragmas
1838 -- appearing among them.
1839
1840 H := First_Non_Pragma (Exception_Handlers (P));
1841 while Present (H) loop
1842
1843 -- Guard against other constructs appearing in the list of
1844 -- exception handlers.
1845
1846 -- Loop through choices in one handler
1847
1848 C := First (Exception_Choices (H));
1849 while Present (C) loop
1850
1851 -- Deal with others case
1852
1853 if Nkind (C) = N_Others_Choice then
1854
1855 -- Matching others handler, but we need to ensure there
1856 -- is no choice parameter. If there is, then we don't
1857 -- have a local handler after all (since we do not allow
1858 -- choice parameters for local handlers).
1859
1860 if No (Choice_Parameter (H)) then
1861 return H;
1862 else
1863 return Empty;
1864 end if;
1865
1866 -- If not others must be entity name
1867
1868 else
1869 pragma Assert (Is_Entity_Name (C));
1870 pragma Assert (Present (Entity (C)));
1871
1872 -- Get exception being handled, dealing with renaming
1873
1874 EHandle := Get_Renamed_Entity (Entity (C));
1875
1876 -- If match, then check choice parameter
1877
1878 if ERaise = EHandle then
1879 if No (Choice_Parameter (H)) then
1880 return H;
1881 else
1882 return Empty;
1883 end if;
1884 end if;
1885 end if;
1886
1887 Next (C);
1888 end loop;
1889
1890 Next_Non_Pragma (H);
1891 end loop;
1892 end if;
1893
1894 N := P;
1895 end loop;
1896 end Find_Local_Handler;
1897
1898 ---------------------------------
1899 -- Get_Local_Raise_Call_Entity --
1900 ---------------------------------
1901
1902 -- Note: this is primarily provided for use by the back end in generating
1903 -- calls to Local_Raise. But it would be too late in the back end to call
1904 -- RTE if this actually caused a load/analyze of the unit. So what we do
1905 -- is to ensure there is a dummy call to this function during front end
1906 -- processing so that the unit gets loaded then, and not later.
1907
1908 Local_Raise_Call_Entity : Entity_Id;
1909 Local_Raise_Call_Entity_Set : Boolean := False;
1910
1911 function Get_Local_Raise_Call_Entity return Entity_Id is
1912 begin
1913 if not Local_Raise_Call_Entity_Set then
1914 Local_Raise_Call_Entity_Set := True;
1915
1916 if RTE_Available (RE_Local_Raise) then
1917 Local_Raise_Call_Entity := RTE (RE_Local_Raise);
1918 else
1919 Local_Raise_Call_Entity := Empty;
1920 end if;
1921 end if;
1922
1923 return Local_Raise_Call_Entity;
1924 end Get_Local_Raise_Call_Entity;
1925
1926 -----------------------------
1927 -- Get_RT_Exception_Entity --
1928 -----------------------------
1929
1930 function Get_RT_Exception_Entity (R : RT_Exception_Code) return Entity_Id is
1931 begin
1932 case Rkind (R) is
1933 when CE_Reason => return Standard_Constraint_Error;
1934 when PE_Reason => return Standard_Program_Error;
1935 when SE_Reason => return Standard_Storage_Error;
1936 end case;
1937 end Get_RT_Exception_Entity;
1938
1939 ---------------------------
1940 -- Get_RT_Exception_Name --
1941 ---------------------------
1942
1943 procedure Get_RT_Exception_Name (Code : RT_Exception_Code) is
1944 begin
1945 case Code is
1946 when CE_Access_Check_Failed =>
1947 Add_Str_To_Name_Buffer ("CE_Access_Check");
1948 when CE_Access_Parameter_Is_Null =>
1949 Add_Str_To_Name_Buffer ("CE_Null_Access_Parameter");
1950 when CE_Discriminant_Check_Failed =>
1951 Add_Str_To_Name_Buffer ("CE_Discriminant_Check");
1952 when CE_Divide_By_Zero =>
1953 Add_Str_To_Name_Buffer ("CE_Divide_By_Zero");
1954 when CE_Explicit_Raise =>
1955 Add_Str_To_Name_Buffer ("CE_Explicit_Raise");
1956 when CE_Index_Check_Failed =>
1957 Add_Str_To_Name_Buffer ("CE_Index_Check");
1958 when CE_Invalid_Data =>
1959 Add_Str_To_Name_Buffer ("CE_Invalid_Data");
1960 when CE_Length_Check_Failed =>
1961 Add_Str_To_Name_Buffer ("CE_Length_Check");
1962 when CE_Null_Exception_Id =>
1963 Add_Str_To_Name_Buffer ("CE_Null_Exception_Id");
1964 when CE_Null_Not_Allowed =>
1965 Add_Str_To_Name_Buffer ("CE_Null_Not_Allowed");
1966 when CE_Overflow_Check_Failed =>
1967 Add_Str_To_Name_Buffer ("CE_Overflow_Check");
1968 when CE_Partition_Check_Failed =>
1969 Add_Str_To_Name_Buffer ("CE_Partition_Check");
1970 when CE_Range_Check_Failed =>
1971 Add_Str_To_Name_Buffer ("CE_Range_Check");
1972 when CE_Tag_Check_Failed =>
1973 Add_Str_To_Name_Buffer ("CE_Tag_Check");
1974
1975 when PE_Access_Before_Elaboration =>
1976 Add_Str_To_Name_Buffer ("PE_Access_Before_Elaboration");
1977 when PE_Accessibility_Check_Failed =>
1978 Add_Str_To_Name_Buffer ("PE_Accessibility_Check");
1979 when PE_Address_Of_Intrinsic =>
1980 Add_Str_To_Name_Buffer ("PE_Address_Of_Intrinsic");
1981 when PE_Aliased_Parameters =>
1982 Add_Str_To_Name_Buffer ("PE_Aliased_Parameters");
1983 when PE_All_Guards_Closed =>
1984 Add_Str_To_Name_Buffer ("PE_All_Guards_Closed");
1985 when PE_Bad_Predicated_Generic_Type =>
1986 Add_Str_To_Name_Buffer ("PE_Bad_Predicated_Generic_Type");
1987 when PE_Build_In_Place_Mismatch =>
1988 Add_Str_To_Name_Buffer ("PE_Build_In_Place_Mismatch");
1989 when PE_Current_Task_In_Entry_Body =>
1990 Add_Str_To_Name_Buffer ("PE_Current_Task_In_Entry_Body");
1991 when PE_Duplicated_Entry_Address =>
1992 Add_Str_To_Name_Buffer ("PE_Duplicated_Entry_Address");
1993 when PE_Explicit_Raise =>
1994 Add_Str_To_Name_Buffer ("PE_Explicit_Raise");
1995 when PE_Finalize_Raised_Exception =>
1996 Add_Str_To_Name_Buffer ("PE_Finalize_Raised_Exception");
1997 when PE_Implicit_Return =>
1998 Add_Str_To_Name_Buffer ("PE_Implicit_Return");
1999 when PE_Misaligned_Address_Value =>
2000 Add_Str_To_Name_Buffer ("PE_Misaligned_Address_Value");
2001 when PE_Missing_Return =>
2002 Add_Str_To_Name_Buffer ("PE_Missing_Return");
2003 when PE_Non_Transportable_Actual =>
2004 Add_Str_To_Name_Buffer ("PE_Non_Transportable_Actual");
2005 when PE_Overlaid_Controlled_Object =>
2006 Add_Str_To_Name_Buffer ("PE_Overlaid_Controlled_Object");
2007 when PE_Potentially_Blocking_Operation =>
2008 Add_Str_To_Name_Buffer ("PE_Potentially_Blocking_Operation");
2009 when PE_Raise_Check_Failed =>
2010 Add_Str_To_Name_Buffer ("PE_Raise_Check");
2011 when PE_Stream_Operation_Not_Allowed =>
2012 Add_Str_To_Name_Buffer ("PE_Stream_Operation_Not_Allowed");
2013 when PE_Stubbed_Subprogram_Called =>
2014 Add_Str_To_Name_Buffer ("PE_Stubbed_Subprogram_Called");
2015 when PE_Unchecked_Union_Restriction =>
2016 Add_Str_To_Name_Buffer ("PE_Unchecked_Union_Restriction");
2017
2018 when SE_Empty_Storage_Pool =>
2019 Add_Str_To_Name_Buffer ("SE_Empty_Storage_Pool");
2020 when SE_Explicit_Raise =>
2021 Add_Str_To_Name_Buffer ("SE_Explicit_Raise");
2022 when SE_Infinite_Recursion =>
2023 Add_Str_To_Name_Buffer ("SE_Infinite_Recursion");
2024 when SE_Object_Too_Large =>
2025 Add_Str_To_Name_Buffer ("SE_Object_Too_Large");
2026 end case;
2027 end Get_RT_Exception_Name;
2028
2029 ----------------------------
2030 -- Warn_If_No_Local_Raise --
2031 ----------------------------
2032
2033 procedure Warn_If_No_Local_Raise (N : Node_Id) is
2034 begin
2035 if Restriction_Active (No_Exception_Propagation)
2036 and then Warn_On_Non_Local_Exception
2037 then
2038 Warn_No_Exception_Propagation_Active (N);
2039
2040 Error_Msg_N
2041 ("\?.x?this handler can never be entered, and has been removed", N);
2042 end if;
2043 end Warn_If_No_Local_Raise;
2044
2045 ----------------------------
2046 -- Warn_If_No_Propagation --
2047 ----------------------------
2048
2049 procedure Warn_If_No_Propagation (N : Node_Id) is
2050 begin
2051 if Restriction_Check_Required (No_Exception_Propagation)
2052 and then Warn_On_Non_Local_Exception
2053 then
2054 Warn_No_Exception_Propagation_Active (N);
2055
2056 if Configurable_Run_Time_Mode then
2057 Error_Msg_N
2058 ("\?.x?Last_Chance_Handler will be called on exception", N);
2059 else
2060 Error_Msg_N
2061 ("\?.x?execution may raise unhandled exception", N);
2062 end if;
2063 end if;
2064 end Warn_If_No_Propagation;
2065
2066 ------------------------------------------
2067 -- Warn_No_Exception_Propagation_Active --
2068 ------------------------------------------
2069
2070 procedure Warn_No_Exception_Propagation_Active (N : Node_Id) is
2071 begin
2072 Error_Msg_N
2073 ("?.x?pragma Restrictions (No_Exception_Propagation) in effect", N);
2074 end Warn_No_Exception_Propagation_Active;
2075
2076 end Exp_Ch11;