comparison gcc/ada/exp_util.adb @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
4 -- -- 4 -- --
5 -- E X P _ U T I L -- 5 -- E X P _ U T I L --
6 -- -- 6 -- --
7 -- B o d y -- 7 -- B o d y --
8 -- -- 8 -- --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. -- 9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
10 -- -- 10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under -- 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- -- 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- -- 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- -- 14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
30 with Debug; use Debug; 30 with Debug; use Debug;
31 with Einfo; use Einfo; 31 with Einfo; use Einfo;
32 with Elists; use Elists; 32 with Elists; use Elists;
33 with Errout; use Errout; 33 with Errout; use Errout;
34 with Exp_Aggr; use Exp_Aggr; 34 with Exp_Aggr; use Exp_Aggr;
35 with Exp_Ch2; use Exp_Ch2;
35 with Exp_Ch6; use Exp_Ch6; 36 with Exp_Ch6; use Exp_Ch6;
36 with Exp_Ch7; use Exp_Ch7; 37 with Exp_Ch7; use Exp_Ch7;
37 with Exp_Ch11; use Exp_Ch11; 38 with Exp_Ch11; use Exp_Ch11;
38 with Ghost; use Ghost; 39 with Ghost; use Ghost;
39 with Inline; use Inline; 40 with Inline; use Inline;
341 342
342 if Base_Type (T) = Standard_Boolean then 343 if Base_Type (T) = Standard_Boolean then
343 return; 344 return;
344 end if; 345 end if;
345 346
346 -- Case of zero/non-zero semantics or non-standard enumeration 347 -- Case of zero/nonzero semantics or nonstandard enumeration
347 -- representation. In each case, we rewrite the node as: 348 -- representation. In each case, we rewrite the node as:
348 349
349 -- ityp!(N) /= False'Enum_Rep 350 -- ityp!(N) /= False'Enum_Rep
350 351
351 -- where ityp is an integer type with large enough size to hold any 352 -- where ityp is an integer type with large enough size to hold any
469 Set_Actions (Fnode, L); 470 Set_Actions (Fnode, L);
470 else 471 else
471 Append_List (L, Actions (Fnode)); 472 Append_List (L, Actions (Fnode));
472 end if; 473 end if;
473 end Append_Freeze_Actions; 474 end Append_Freeze_Actions;
475
476 --------------------------------------
477 -- Attr_Constrained_Statically_True --
478 --------------------------------------
479
480 function Attribute_Constrained_Static_Value (Pref : Node_Id) return Boolean
481 is
482 Ptyp : constant Entity_Id := Etype (Pref);
483 Formal_Ent : constant Entity_Id := Param_Entity (Pref);
484
485 function Is_Constrained_Aliased_View (Obj : Node_Id) return Boolean;
486 -- Ada 2005 (AI-363): Returns True if the object name Obj denotes a
487 -- view of an aliased object whose subtype is constrained.
488
489 ---------------------------------
490 -- Is_Constrained_Aliased_View --
491 ---------------------------------
492
493 function Is_Constrained_Aliased_View (Obj : Node_Id) return Boolean is
494 E : Entity_Id;
495
496 begin
497 if Is_Entity_Name (Obj) then
498 E := Entity (Obj);
499
500 if Present (Renamed_Object (E)) then
501 return Is_Constrained_Aliased_View (Renamed_Object (E));
502 else
503 return Is_Aliased (E) and then Is_Constrained (Etype (E));
504 end if;
505
506 else
507 return Is_Aliased_View (Obj)
508 and then
509 (Is_Constrained (Etype (Obj))
510 or else
511 (Nkind (Obj) = N_Explicit_Dereference
512 and then
513 not Object_Type_Has_Constrained_Partial_View
514 (Typ => Base_Type (Etype (Obj)),
515 Scop => Current_Scope)));
516 end if;
517 end Is_Constrained_Aliased_View;
518
519 -- Start of processing for Attribute_Constrained_Static_Value
520
521 begin
522 -- We are in a case where the attribute is known statically, and
523 -- implicit dereferences have been rewritten.
524
525 pragma Assert
526 (not (Present (Formal_Ent)
527 and then Ekind (Formal_Ent) /= E_Constant
528 and then Present (Extra_Constrained (Formal_Ent)))
529 and then
530 not (Is_Access_Type (Etype (Pref))
531 and then (not Is_Entity_Name (Pref)
532 or else Is_Object (Entity (Pref))))
533 and then
534 not (Nkind (Pref) = N_Identifier
535 and then Ekind (Entity (Pref)) = E_Variable
536 and then Present (Extra_Constrained (Entity (Pref)))));
537
538 if Is_Entity_Name (Pref) then
539 declare
540 Ent : constant Entity_Id := Entity (Pref);
541 Res : Boolean;
542
543 begin
544 -- (RM J.4) obsolescent cases
545
546 if Is_Type (Ent) then
547
548 -- Private type
549
550 if Is_Private_Type (Ent) then
551 Res := not Has_Discriminants (Ent)
552 or else Is_Constrained (Ent);
553
554 -- It not a private type, must be a generic actual type
555 -- that corresponded to a private type. We know that this
556 -- correspondence holds, since otherwise the reference
557 -- within the generic template would have been illegal.
558
559 else
560 if Is_Composite_Type (Underlying_Type (Ent)) then
561 Res := Is_Constrained (Ent);
562 else
563 Res := True;
564 end if;
565 end if;
566
567 else
568
569 -- If the prefix is not a variable or is aliased, then
570 -- definitely true; if it's a formal parameter without an
571 -- associated extra formal, then treat it as constrained.
572
573 -- Ada 2005 (AI-363): An aliased prefix must be known to be
574 -- constrained in order to set the attribute to True.
575
576 if not Is_Variable (Pref)
577 or else Present (Formal_Ent)
578 or else (Ada_Version < Ada_2005
579 and then Is_Aliased_View (Pref))
580 or else (Ada_Version >= Ada_2005
581 and then Is_Constrained_Aliased_View (Pref))
582 then
583 Res := True;
584
585 -- Variable case, look at type to see if it is constrained.
586 -- Note that the one case where this is not accurate (the
587 -- procedure formal case), has been handled above.
588
589 -- We use the Underlying_Type here (and below) in case the
590 -- type is private without discriminants, but the full type
591 -- has discriminants. This case is illegal, but we generate
592 -- it internally for passing to the Extra_Constrained
593 -- parameter.
594
595 else
596 -- In Ada 2012, test for case of a limited tagged type,
597 -- in which case the attribute is always required to
598 -- return True. The underlying type is tested, to make
599 -- sure we also return True for cases where there is an
600 -- unconstrained object with an untagged limited partial
601 -- view which has defaulted discriminants (such objects
602 -- always produce a False in earlier versions of
603 -- Ada). (Ada 2012: AI05-0214)
604
605 Res :=
606 Is_Constrained (Underlying_Type (Etype (Ent)))
607 or else
608 (Ada_Version >= Ada_2012
609 and then Is_Tagged_Type (Underlying_Type (Ptyp))
610 and then Is_Limited_Type (Ptyp));
611 end if;
612 end if;
613
614 return Res;
615 end;
616
617 -- Prefix is not an entity name. These are also cases where we can
618 -- always tell at compile time by looking at the form and type of the
619 -- prefix. If an explicit dereference of an object with constrained
620 -- partial view, this is unconstrained (Ada 2005: AI95-0363). If the
621 -- underlying type is a limited tagged type, then Constrained is
622 -- required to always return True (Ada 2012: AI05-0214).
623
624 else
625 return not Is_Variable (Pref)
626 or else
627 (Nkind (Pref) = N_Explicit_Dereference
628 and then
629 not Object_Type_Has_Constrained_Partial_View
630 (Typ => Base_Type (Ptyp),
631 Scop => Current_Scope))
632 or else Is_Constrained (Underlying_Type (Ptyp))
633 or else (Ada_Version >= Ada_2012
634 and then Is_Tagged_Type (Underlying_Type (Ptyp))
635 and then Is_Limited_Type (Ptyp));
636 end if;
637 end Attribute_Constrained_Static_Value;
474 638
475 ------------------------------------ 639 ------------------------------------
476 -- Build_Allocate_Deallocate_Proc -- 640 -- Build_Allocate_Deallocate_Proc --
477 ------------------------------------ 641 ------------------------------------
478 642
1931 2095
1932 -- The DIC procedure requires debug info when the assertion expression 2096 -- The DIC procedure requires debug info when the assertion expression
1933 -- is subject to Source Coverage Obligations. 2097 -- is subject to Source Coverage Obligations.
1934 2098
1935 if Generate_SCO then 2099 if Generate_SCO then
1936 Set_Needs_Debug_Info (Proc_Id); 2100 Set_Debug_Info_Needed (Proc_Id);
1937 end if; 2101 end if;
1938 2102
1939 -- Obtain all views of the input type 2103 -- Obtain all views of the input type
1940 2104
1941 Get_Views (Work_Typ, Priv_Typ, Full_Typ, Full_Base, CRec_Typ); 2105 Get_Views (Work_Typ, Priv_Typ, Full_Typ, Full_Base, CRec_Typ);
1975 Set_Ekind (Obj_Id, E_In_Parameter); 2139 Set_Ekind (Obj_Id, E_In_Parameter);
1976 Set_Etype (Obj_Id, Work_Typ); 2140 Set_Etype (Obj_Id, Work_Typ);
1977 Set_Scope (Obj_Id, Proc_Id); 2141 Set_Scope (Obj_Id, Proc_Id);
1978 2142
1979 Set_First_Entity (Proc_Id, Obj_Id); 2143 Set_First_Entity (Proc_Id, Obj_Id);
2144 Set_Last_Entity (Proc_Id, Obj_Id);
1980 2145
1981 -- Generate: 2146 -- Generate:
1982 -- procedure <Work_Typ>DIC (_object : <Work_Typ>); 2147 -- procedure <Work_Typ>DIC (_object : <Work_Typ>);
1983 2148
1984 Proc_Decl := 2149 Proc_Decl :=
3405 3570
3406 -- The invariant procedure requires debug info when the invariants are 3571 -- The invariant procedure requires debug info when the invariants are
3407 -- subject to Source Coverage Obligations. 3572 -- subject to Source Coverage Obligations.
3408 3573
3409 if Generate_SCO then 3574 if Generate_SCO then
3410 Set_Needs_Debug_Info (Proc_Id); 3575 Set_Debug_Info_Needed (Proc_Id);
3411 end if; 3576 end if;
3412 3577
3413 -- Obtain all views of the input type 3578 -- Obtain all views of the input type
3414 3579
3415 Get_Views (Work_Typ, Priv_Typ, Full_Typ, Full_Base, CRec_Typ); 3580 Get_Views (Work_Typ, Priv_Typ, Full_Typ, Full_Base, CRec_Typ);
4442 function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean is 4607 function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean is
4443 UT : Entity_Id; 4608 UT : Entity_Id;
4444 4609
4445 begin 4610 begin
4446 -- If no component clause, then everything is fine, since the back end 4611 -- If no component clause, then everything is fine, since the back end
4447 -- never bit-misaligns by default, even if there is a pragma Packed for 4612 -- never misaligns from byte boundaries by default, even if there is a
4448 -- the record. 4613 -- pragma Pack for the record.
4449 4614
4450 if No (Comp) or else No (Component_Clause (Comp)) then 4615 if No (Comp) or else No (Component_Clause (Comp)) then
4451 return False; 4616 return False;
4452 end if; 4617 end if;
4453 4618
4490 (E : Entity_Id) return Entity_Id 4655 (E : Entity_Id) return Entity_Id
4491 is 4656 is
4492 begin 4657 begin
4493 -- E is the package or generic package which is externally axiomatized 4658 -- E is the package or generic package which is externally axiomatized
4494 4659
4495 if Ekind_In (E, E_Generic_Package, E_Package) 4660 if Is_Package_Or_Generic_Package (E)
4496 and then Has_Annotate_Pragma_For_External_Axiomatization (E) 4661 and then Has_Annotate_Pragma_For_External_Axiomatization (E)
4497 then 4662 then
4498 return E; 4663 return E;
4499 end if; 4664 end if;
4500 4665
4606 -- Start of processing for Corresponding_Runtime_Package 4771 -- Start of processing for Corresponding_Runtime_Package
4607 4772
4608 begin 4773 begin
4609 pragma Assert (Is_Concurrent_Type (Typ)); 4774 pragma Assert (Is_Concurrent_Type (Typ));
4610 4775
4611 if Ekind (Typ) in Protected_Kind then 4776 if Is_Protected_Type (Typ) then
4612 if Has_Entries (Typ) 4777 if Has_Entries (Typ)
4613 4778
4614 -- A protected type without entries that covers an interface and 4779 -- A protected type without entries that covers an interface and
4615 -- overrides the abstract routines with protected procedures is 4780 -- overrides the abstract routines with protected procedures is
4616 -- considered equivalent to a protected type with entries in the 4781 -- considered equivalent to a protected type with entries in the
4937 Make_Or_Else (Sloc (Cond1), 5102 Make_Or_Else (Sloc (Cond1),
4938 Left_Opnd => Cond, 5103 Left_Opnd => Cond,
4939 Right_Opnd => Cond1); 5104 Right_Opnd => Cond1);
4940 end if; 5105 end if;
4941 end Evolve_Or_Else; 5106 end Evolve_Or_Else;
4942
4943 -----------------------------------
4944 -- Exceptions_In_Finalization_OK --
4945 -----------------------------------
4946
4947 function Exceptions_In_Finalization_OK return Boolean is
4948 begin
4949 return
4950 not (Restriction_Active (No_Exception_Handlers) or else
4951 Restriction_Active (No_Exception_Propagation) or else
4952 Restriction_Active (No_Exceptions));
4953 end Exceptions_In_Finalization_OK;
4954 5107
4955 ----------------------------------------- 5108 -----------------------------------------
4956 -- Expand_Static_Predicates_In_Choices -- 5109 -- Expand_Static_Predicates_In_Choices --
4957 ----------------------------------------- 5110 -----------------------------------------
4958 5111
5077 -- an array (or string), because it is safe to compute the bounds. It is 5230 -- an array (or string), because it is safe to compute the bounds. It is
5078 -- in fact required to do so even in a generic context, because there 5231 -- in fact required to do so even in a generic context, because there
5079 -- may be constants that depend on the bounds of a string literal, both 5232 -- may be constants that depend on the bounds of a string literal, both
5080 -- standard string types and more generally arrays of characters. 5233 -- standard string types and more generally arrays of characters.
5081 5234
5082 -- In GNATprove mode, these extra subtypes are not needed 5235 -- In GNATprove mode, these extra subtypes are not needed, unless Exp is
5083 5236 -- a static expression. In that case, the subtype will be constrained
5084 if GNATprove_Mode then 5237 -- while the original type might be unconstrained, so expanding the type
5238 -- is necessary both for passing legality checks in GNAT and for precise
5239 -- analysis in GNATprove.
5240
5241 if GNATprove_Mode and then not Is_Static_Expression (Exp) then
5085 return; 5242 return;
5086 end if; 5243 end if;
5087 5244
5088 if not Expander_Active 5245 if not Expander_Active
5089 and then (No (Etype (Exp)) or else not Is_String_Type (Etype (Exp))) 5246 and then (No (Etype (Exp)) or else not Is_String_Type (Etype (Exp)))
5104 Constraints => New_List 5261 Constraints => New_List
5105 (New_Occurrence_Of (Slice_Type, Loc))))); 5262 (New_Occurrence_Of (Slice_Type, Loc)))));
5106 5263
5107 -- This subtype indication may be used later for constraint checks 5264 -- This subtype indication may be used later for constraint checks
5108 -- we better make sure that if a variable was used as a bound of 5265 -- we better make sure that if a variable was used as a bound of
5109 -- of the original slice, its value is frozen. 5266 -- the original slice, its value is frozen.
5110 5267
5111 Evaluate_Slice_Bounds (Exp); 5268 Evaluate_Slice_Bounds (Exp);
5112 end; 5269 end;
5113 5270
5114 elsif Ekind (Exp_Typ) = E_String_Literal_Subtype then 5271 elsif Ekind (Exp_Typ) = E_String_Literal_Subtype then
5352 ---------------------- 5509 ----------------------
5353 -- Finalize_Address -- 5510 -- Finalize_Address --
5354 ---------------------- 5511 ----------------------
5355 5512
5356 function Finalize_Address (Typ : Entity_Id) return Entity_Id is 5513 function Finalize_Address (Typ : Entity_Id) return Entity_Id is
5514 Btyp : constant Entity_Id := Base_Type (Typ);
5357 Utyp : Entity_Id := Typ; 5515 Utyp : Entity_Id := Typ;
5358 5516
5359 begin 5517 begin
5360 -- Handle protected class-wide or task class-wide types 5518 -- Handle protected class-wide or task class-wide types
5361 5519
5391 -- now known to be protected, the finalization routine is the one 5549 -- now known to be protected, the finalization routine is the one
5392 -- defined on the corresponding record of the ancestor (corresponding 5550 -- defined on the corresponding record of the ancestor (corresponding
5393 -- records do not automatically inherit operations, but maybe they 5551 -- records do not automatically inherit operations, but maybe they
5394 -- should???) 5552 -- should???)
5395 5553
5396 if Is_Untagged_Derivation (Typ) then 5554 if Is_Untagged_Derivation (Btyp) then
5397 if Is_Protected_Type (Typ) then 5555 if Is_Protected_Type (Btyp) then
5398 Utyp := Corresponding_Record_Type (Root_Type (Base_Type (Typ))); 5556 Utyp := Corresponding_Record_Type (Root_Type (Btyp));
5399 5557
5400 else 5558 else
5401 Utyp := Underlying_Type (Root_Type (Base_Type (Typ))); 5559 Utyp := Underlying_Type (Root_Type (Btyp));
5402 5560
5403 if Is_Protected_Type (Utyp) then 5561 if Is_Protected_Type (Utyp) then
5404 Utyp := Corresponding_Record_Type (Utyp); 5562 Utyp := Corresponding_Record_Type (Utyp);
5405 end if; 5563 end if;
5406 end if; 5564 end if;
5624 Op := Node (Prim); 5782 Op := Node (Prim);
5625 5783
5626 -- We can retrieve primitive operations by name if it is an internal 5784 -- We can retrieve primitive operations by name if it is an internal
5627 -- name. For equality we must check that both of its operands have 5785 -- name. For equality we must check that both of its operands have
5628 -- the same type, to avoid confusion with user-defined equalities 5786 -- the same type, to avoid confusion with user-defined equalities
5629 -- than may have a non-symmetric signature. 5787 -- than may have a asymmetric signature.
5630 5788
5631 exit when Chars (Op) = Name 5789 exit when Chars (Op) = Name
5632 and then 5790 and then
5633 (Name /= Name_Op_Eq 5791 (Name /= Name_Op_Eq
5634 or else Etype (First_Formal (Op)) = Etype (Last_Formal (Op))); 5792 or else Etype (First_Formal (Op)) = Etype (Last_Formal (Op)));
6635 6793
6636 -------------------- 6794 --------------------
6637 -- Homonym_Number -- 6795 -- Homonym_Number --
6638 -------------------- 6796 --------------------
6639 6797
6640 function Homonym_Number (Subp : Entity_Id) return Nat is 6798 function Homonym_Number (Subp : Entity_Id) return Pos is
6641 Count : Nat; 6799 Hom : Entity_Id := Homonym (Subp);
6642 Hom : Entity_Id; 6800 Count : Pos := 1;
6643 6801
6644 begin 6802 begin
6645 Count := 1;
6646 Hom := Homonym (Subp);
6647 while Present (Hom) loop 6803 while Present (Hom) loop
6648 if Scope (Hom) = Scope (Subp) then 6804 if Scope (Hom) = Scope (Subp) then
6649 Count := Count + 1; 6805 Count := Count + 1;
6650 end if; 6806 end if;
6651 6807
6700 6856
6701 ------------------- 6857 -------------------
6702 -- Insert_Action -- 6858 -- Insert_Action --
6703 ------------------- 6859 -------------------
6704 6860
6705 procedure Insert_Action (Assoc_Node : Node_Id; Ins_Action : Node_Id) is 6861 procedure Insert_Action
6862 (Assoc_Node : Node_Id;
6863 Ins_Action : Node_Id;
6864 Spec_Expr_OK : Boolean := False)
6865 is
6706 begin 6866 begin
6707 if Present (Ins_Action) then 6867 if Present (Ins_Action) then
6708 Insert_Actions (Assoc_Node, New_List (Ins_Action)); 6868 Insert_Actions
6869 (Assoc_Node => Assoc_Node,
6870 Ins_Actions => New_List (Ins_Action),
6871 Spec_Expr_OK => Spec_Expr_OK);
6709 end if; 6872 end if;
6710 end Insert_Action; 6873 end Insert_Action;
6711 6874
6712 -- Version with check(s) suppressed 6875 -- Version with check(s) suppressed
6713 6876
6714 procedure Insert_Action 6877 procedure Insert_Action
6715 (Assoc_Node : Node_Id; Ins_Action : Node_Id; Suppress : Check_Id) 6878 (Assoc_Node : Node_Id;
6879 Ins_Action : Node_Id;
6880 Suppress : Check_Id;
6881 Spec_Expr_OK : Boolean := False)
6716 is 6882 is
6717 begin 6883 begin
6718 Insert_Actions (Assoc_Node, New_List (Ins_Action), Suppress); 6884 Insert_Actions
6885 (Assoc_Node => Assoc_Node,
6886 Ins_Actions => New_List (Ins_Action),
6887 Suppress => Suppress,
6888 Spec_Expr_OK => Spec_Expr_OK);
6719 end Insert_Action; 6889 end Insert_Action;
6720 6890
6721 ------------------------- 6891 -------------------------
6722 -- Insert_Action_After -- 6892 -- Insert_Action_After --
6723 ------------------------- 6893 -------------------------
6732 6902
6733 -------------------- 6903 --------------------
6734 -- Insert_Actions -- 6904 -- Insert_Actions --
6735 -------------------- 6905 --------------------
6736 6906
6737 procedure Insert_Actions (Assoc_Node : Node_Id; Ins_Actions : List_Id) is 6907 procedure Insert_Actions
6908 (Assoc_Node : Node_Id;
6909 Ins_Actions : List_Id;
6910 Spec_Expr_OK : Boolean := False)
6911 is
6738 N : Node_Id; 6912 N : Node_Id;
6739 P : Node_Id; 6913 P : Node_Id;
6740 6914
6741 Wrapped_Node : Node_Id := Empty; 6915 Wrapped_Node : Node_Id := Empty;
6742 6916
6743 begin 6917 begin
6744 if No (Ins_Actions) or else Is_Empty_List (Ins_Actions) then 6918 if No (Ins_Actions) or else Is_Empty_List (Ins_Actions) then
6745 return; 6919 return;
6746 end if; 6920 end if;
6921
6922 -- Insert the action when the context is "Handling of Default and Per-
6923 -- Object Expressions" only when requested by the caller.
6924
6925 if Spec_Expr_OK then
6926 null;
6747 6927
6748 -- Ignore insert of actions from inside default expression (or other 6928 -- Ignore insert of actions from inside default expression (or other
6749 -- similar "spec expression") in the special spec-expression analyze 6929 -- similar "spec expression") in the special spec-expression analyze
6750 -- mode. Any insertions at this point have no relevance, since we are 6930 -- mode. Any insertions at this point have no relevance, since we are
6751 -- only doing the analyze to freeze the types of any static expressions. 6931 -- only doing the analyze to freeze the types of any static expressions.
6752 -- See section "Handling of Default Expressions" in the spec of package 6932 -- See section "Handling of Default and Per-Object Expressions" in the
6753 -- Sem for further details. 6933 -- spec of package Sem for further details.
6754 6934
6755 if In_Spec_Expression then 6935 elsif In_Spec_Expression then
6756 return; 6936 return;
6757 end if; 6937 end if;
6758 6938
6759 -- If the action derives from stuff inside a record, then the actions 6939 -- If the action derives from stuff inside a record, then the actions
6760 -- are attached to the current scope, to be inserted and analyzed on 6940 -- are attached to the current scope, to be inserted and analyzed on
6804 (Attribute_Name (Assoc_Node))) 6984 (Attribute_Name (Assoc_Node)))
6805 then 6985 then
6806 N := Assoc_Node; 6986 N := Assoc_Node;
6807 P := Parent (Assoc_Node); 6987 P := Parent (Assoc_Node);
6808 6988
6809 -- Non-subexpression case. Note that N is initially Empty in this case 6989 -- Nonsubexpression case. Note that N is initially Empty in this case
6810 -- (N is only guaranteed Non-Empty in the subexpr case). 6990 -- (N is only guaranteed non-Empty in the subexpr case).
6811 6991
6812 else 6992 else
6813 N := Empty; 6993 N := Empty;
6814 P := Assoc_Node; 6994 P := Assoc_Node;
6815 end if; 6995 end if;
7060 | N_Private_Extension_Declaration 7240 | N_Private_Extension_Declaration
7061 | N_Private_Type_Declaration 7241 | N_Private_Type_Declaration
7062 | N_Procedure_Instantiation 7242 | N_Procedure_Instantiation
7063 | N_Protected_Body 7243 | N_Protected_Body
7064 | N_Protected_Body_Stub 7244 | N_Protected_Body_Stub
7065 | N_Protected_Type_Declaration
7066 | N_Single_Task_Declaration 7245 | N_Single_Task_Declaration
7067 | N_Subprogram_Body 7246 | N_Subprogram_Body
7068 | N_Subprogram_Body_Stub 7247 | N_Subprogram_Body_Stub
7069 | N_Subprogram_Declaration 7248 | N_Subprogram_Declaration
7070 | N_Subprogram_Renaming_Declaration 7249 | N_Subprogram_Renaming_Declaration
7071 | N_Subtype_Declaration 7250 | N_Subtype_Declaration
7072 | N_Task_Body 7251 | N_Task_Body
7073 | N_Task_Body_Stub 7252 | N_Task_Body_Stub
7074 | N_Task_Type_Declaration
7075 7253
7076 -- Use clauses can appear in lists of declarations 7254 -- Use clauses can appear in lists of declarations
7077 7255
7078 | N_Use_Package_Clause 7256 | N_Use_Package_Clause
7079 | N_Use_Type_Clause 7257 | N_Use_Type_Clause
7132 7310
7133 else 7311 else
7134 Insert_List_Before_And_Analyze (P, Ins_Actions); 7312 Insert_List_Before_And_Analyze (P, Ins_Actions);
7135 return; 7313 return;
7136 end if; 7314 end if;
7315
7316 -- the expansion of Task and protected type declarations can
7317 -- create declarations for temporaries which, like other actions
7318 -- are inserted and analyzed before the current declaraation.
7319 -- However, the current scope is the synchronized type, and
7320 -- for unnesting it is critical that the proper scope for these
7321 -- generated entities be the enclosing one.
7322
7323 when N_Task_Type_Declaration
7324 | N_Protected_Type_Declaration =>
7325
7326 Push_Scope (Scope (Current_Scope));
7327 Insert_List_Before_And_Analyze (P, Ins_Actions);
7328 Pop_Scope;
7329 return;
7137 7330
7138 -- A special case, N_Raise_xxx_Error can act either as a statement 7331 -- A special case, N_Raise_xxx_Error can act either as a statement
7139 -- or a subexpression. We tell the difference by looking at the 7332 -- or a subexpression. We tell the difference by looking at the
7140 -- Etype. It is set to Standard_Void_Type in the statement case. 7333 -- Etype. It is set to Standard_Void_Type in the statement case.
7141 7334
7414 end Insert_Actions; 7607 end Insert_Actions;
7415 7608
7416 -- Version with check(s) suppressed 7609 -- Version with check(s) suppressed
7417 7610
7418 procedure Insert_Actions 7611 procedure Insert_Actions
7419 (Assoc_Node : Node_Id; 7612 (Assoc_Node : Node_Id;
7420 Ins_Actions : List_Id; 7613 Ins_Actions : List_Id;
7421 Suppress : Check_Id) 7614 Suppress : Check_Id;
7615 Spec_Expr_OK : Boolean := False)
7422 is 7616 is
7423 begin 7617 begin
7424 if Suppress = All_Checks then 7618 if Suppress = All_Checks then
7425 declare 7619 declare
7426 Sva : constant Suppress_Array := Scope_Suppress.Suppress; 7620 Sva : constant Suppress_Array := Scope_Suppress.Suppress;
7427 begin 7621 begin
7428 Scope_Suppress.Suppress := (others => True); 7622 Scope_Suppress.Suppress := (others => True);
7429 Insert_Actions (Assoc_Node, Ins_Actions); 7623 Insert_Actions (Assoc_Node, Ins_Actions, Spec_Expr_OK);
7430 Scope_Suppress.Suppress := Sva; 7624 Scope_Suppress.Suppress := Sva;
7431 end; 7625 end;
7432 7626
7433 else 7627 else
7434 declare 7628 declare
7435 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress); 7629 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
7436 begin 7630 begin
7437 Scope_Suppress.Suppress (Suppress) := True; 7631 Scope_Suppress.Suppress (Suppress) := True;
7438 Insert_Actions (Assoc_Node, Ins_Actions); 7632 Insert_Actions (Assoc_Node, Ins_Actions, Spec_Expr_OK);
7439 Scope_Suppress.Suppress (Suppress) := Svg; 7633 Scope_Suppress.Suppress (Suppress) := Svg;
7440 end; 7634 end;
7441 end if; 7635 end if;
7442 end Insert_Actions; 7636 end Insert_Actions;
7443 7637
8218 return False; 8412 return False;
8219 elsif not Has_Specified_Layout (U) then 8413 elsif not Has_Specified_Layout (U) then
8220 return False; 8414 return False;
8221 end if; 8415 end if;
8222 8416
8223 -- Here we have a tagged type, see if it has any unlayed out fields 8417 -- Here we have a tagged type, see if it has any component (other than
8224 -- other than a possible tag and parent fields. If so, we return False. 8418 -- tag and parent) with no component_clause. If so, we return False.
8225 8419
8226 Comp := First_Component (U); 8420 Comp := First_Component (U);
8227 while Present (Comp) loop 8421 while Present (Comp) loop
8228 if not Is_Tag (Comp) 8422 if not Is_Tag (Comp)
8229 and then Chars (Comp) /= Name_uParent 8423 and then Chars (Comp) /= Name_uParent
8233 else 8427 else
8234 Next_Component (Comp); 8428 Next_Component (Comp);
8235 end if; 8429 end if;
8236 end loop; 8430 end loop;
8237 8431
8238 -- All components are layed out 8432 -- All components have clauses
8239 8433
8240 return True; 8434 return True;
8241 end Is_Fully_Repped_Tagged_Type; 8435 end Is_Fully_Repped_Tagged_Type;
8242 8436
8243 ---------------------------------- 8437 ----------------------------------
8313 C : constant Entity_Id := Entity (Selector_Name (N)); 8507 C : constant Entity_Id := Entity (Selector_Name (N));
8314 M : Nat; 8508 M : Nat;
8315 S : Nat; 8509 S : Nat;
8316 8510
8317 begin 8511 begin
8318 -- If component reference is for an array with non-static bounds, 8512 -- If component reference is for an array with nonstatic bounds,
8319 -- then it is always aligned: we can only process unaligned arrays 8513 -- then it is always aligned: we can only process unaligned arrays
8320 -- with static bounds (more precisely compile time known bounds). 8514 -- with static bounds (more precisely compile time known bounds).
8321 8515
8322 if Is_Array_Type (T) 8516 if Is_Array_Type (T)
8323 and then not Compile_Time_Known_Bounds (T) 8517 and then not Compile_Time_Known_Bounds (T)
8453 8647
8454 if Nkind (N) /= N_Slice then 8648 if Nkind (N) /= N_Slice then
8455 return False; 8649 return False;
8456 end if; 8650 end if;
8457 8651
8458 -- We only need to worry if the target has strict alignment
8459
8460 if not Target_Strict_Alignment then
8461 return False;
8462 end if;
8463
8464 -- If it is a slice, then look at the array type being sliced 8652 -- If it is a slice, then look at the array type being sliced
8465 8653
8466 declare 8654 declare
8467 Sarr : constant Node_Id := Prefix (N); 8655 Sarr : constant Node_Id := Prefix (N);
8468 -- Prefix of the slice, i.e. the array being sliced 8656 -- Prefix of the slice, i.e. the array being sliced
8502 Ptyp := Etype (Prefix (Pref)); 8690 Ptyp := Etype (Prefix (Pref));
8503 8691
8504 -- We are definitely in trouble if the record in question 8692 -- We are definitely in trouble if the record in question
8505 -- has an alignment, and either we know this alignment is 8693 -- has an alignment, and either we know this alignment is
8506 -- inconsistent with the alignment of the slice, or we don't 8694 -- inconsistent with the alignment of the slice, or we don't
8507 -- know what the alignment of the slice should be. 8695 -- know what the alignment of the slice should be. But this
8508 8696 -- really matters only if the target has strict alignment.
8509 if Known_Alignment (Ptyp) 8697
8698 if Target_Strict_Alignment
8699 and then Known_Alignment (Ptyp)
8510 and then (Unknown_Alignment (Styp) 8700 and then (Unknown_Alignment (Styp)
8511 or else Alignment (Styp) > Alignment (Ptyp)) 8701 or else Alignment (Styp) > Alignment (Ptyp))
8512 then 8702 then
8513 return True; 8703 return True;
8514 end if; 8704 end if;
9035 if not Has_Discriminants (Root_Typ) 9225 if not Has_Discriminants (Root_Typ)
9036 or else Is_Constrained (Root_Typ) 9226 or else Is_Constrained (Root_Typ)
9037 then 9227 then
9038 Constr_Root := Root_Typ; 9228 Constr_Root := Root_Typ;
9039 9229
9040 -- At this point in the expansion, non-limited view of the type 9230 -- At this point in the expansion, nonlimited view of the type
9041 -- must be available, otherwise the error will be reported later. 9231 -- must be available, otherwise the error will be reported later.
9042 9232
9043 if From_Limited_With (Constr_Root) 9233 if From_Limited_With (Constr_Root)
9044 and then Present (Non_Limited_View (Constr_Root)) 9234 and then Present (Non_Limited_View (Constr_Root))
9045 then 9235 then
9196 pragma Assert (Has_Invariants (Typ)); 9386 pragma Assert (Has_Invariants (Typ));
9197 9387
9198 Proc_Id := Invariant_Procedure (Typ); 9388 Proc_Id := Invariant_Procedure (Typ);
9199 pragma Assert (Present (Proc_Id)); 9389 pragma Assert (Present (Proc_Id));
9200 9390
9201 return 9391 -- Ignore the invariant if that policy is in effect
9202 Make_Procedure_Call_Statement (Loc, 9392
9203 Name => New_Occurrence_Of (Proc_Id, Loc), 9393 if Invariants_Ignored (Typ) then
9204 Parameter_Associations => New_List (Relocate_Node (Expr))); 9394 return Make_Null_Statement (Loc);
9395 else
9396 return
9397 Make_Procedure_Call_Statement (Loc,
9398 Name => New_Occurrence_Of (Proc_Id, Loc),
9399 Parameter_Associations => New_List (Relocate_Node (Expr)));
9400 end if;
9205 end Make_Invariant_Call; 9401 end Make_Invariant_Call;
9206 9402
9207 ------------------------ 9403 ------------------------
9208 -- Make_Literal_Range -- 9404 -- Make_Literal_Range --
9209 ------------------------ 9405 ------------------------
9311 9507
9312 -- Case of calling normal predicate function 9508 -- Case of calling normal predicate function
9313 9509
9314 -- If the type is tagged, the expression may be class-wide, in which 9510 -- If the type is tagged, the expression may be class-wide, in which
9315 -- case it has to be converted to its root type, given that the 9511 -- case it has to be converted to its root type, given that the
9316 -- generated predicate function is not dispatching. The conversion 9512 -- generated predicate function is not dispatching. The conversion is
9317 -- is type-safe and does not need validation, which matters when 9513 -- type-safe and does not need validation, which matters when private
9318 -- private extensions are involved. 9514 -- extensions are involved.
9319 9515
9320 if Is_Tagged_Type (Typ) then 9516 if Is_Tagged_Type (Typ) then
9321 Call := 9517 Call :=
9322 Make_Function_Call (Loc, 9518 Make_Function_Call (Loc,
9323 Name => New_Occurrence_Of (Func_Id, Loc), 9519 Name => New_Occurrence_Of (Func_Id, Loc),
9520 if Predicate_Checks_Suppressed (Empty) then 9716 if Predicate_Checks_Suppressed (Empty) then
9521 return Make_Null_Statement (Loc); 9717 return Make_Null_Statement (Loc);
9522 end if; 9718 end if;
9523 9719
9524 -- Do not generate a check within an internal subprogram (stream 9720 -- Do not generate a check within an internal subprogram (stream
9525 -- functions and the like, including including predicate functions). 9721 -- functions and the like, including predicate functions).
9526 9722
9527 if Within_Internal_Subprogram then 9723 if Within_Internal_Subprogram then
9528 return Make_Null_Statement (Loc); 9724 return Make_Null_Statement (Loc);
9529 end if; 9725 end if;
9530 9726
9808 Typ_Elmt : Elmt_Id) return Node_Or_Entity_Id; 10004 Typ_Elmt : Elmt_Id) return Node_Or_Entity_Id;
9809 -- Subsidiary to Map_Discriminants. Find the value of discriminant Discr 10005 -- Subsidiary to Map_Discriminants. Find the value of discriminant Discr
9810 -- in the derivation chain starting from parent type Par_Typ leading to 10006 -- in the derivation chain starting from parent type Par_Typ leading to
9811 -- derived type Deriv_Typ. The returned value is one of the following: 10007 -- derived type Deriv_Typ. The returned value is one of the following:
9812 -- 10008 --
9813 -- * An entity which is either a discriminant or a non-discriminant 10009 -- * An entity which is either a discriminant or a nondiscriminant
9814 -- name, and renames/constraints Discr. 10010 -- name, and renames/constraints Discr.
9815 -- 10011 --
9816 -- * An expression which constraints Discr 10012 -- * An expression which constraints Discr
9817 -- 10013 --
9818 -- Typ_Elmt is an element of the derivation chain created by routine 10014 -- Typ_Elmt is an element of the derivation chain created by routine
10522 10718
10523 return True; 10719 return True;
10524 end if; 10720 end if;
10525 end Needs_Constant_Address; 10721 end Needs_Constant_Address;
10526 10722
10527 ------------------------
10528 -- Needs_Finalization --
10529 ------------------------
10530
10531 function Needs_Finalization (Typ : Entity_Id) return Boolean is
10532 function Has_Some_Controlled_Component
10533 (Input_Typ : Entity_Id) return Boolean;
10534 -- Determine whether type Input_Typ has at least one controlled
10535 -- component.
10536
10537 -----------------------------------
10538 -- Has_Some_Controlled_Component --
10539 -----------------------------------
10540
10541 function Has_Some_Controlled_Component
10542 (Input_Typ : Entity_Id) return Boolean
10543 is
10544 Comp : Entity_Id;
10545
10546 begin
10547 -- When a type is already frozen and has at least one controlled
10548 -- component, or is manually decorated, it is sufficient to inspect
10549 -- flag Has_Controlled_Component.
10550
10551 if Has_Controlled_Component (Input_Typ) then
10552 return True;
10553
10554 -- Otherwise inspect the internals of the type
10555
10556 elsif not Is_Frozen (Input_Typ) then
10557 if Is_Array_Type (Input_Typ) then
10558 return Needs_Finalization (Component_Type (Input_Typ));
10559
10560 elsif Is_Record_Type (Input_Typ) then
10561 Comp := First_Component (Input_Typ);
10562 while Present (Comp) loop
10563 if Needs_Finalization (Etype (Comp)) then
10564 return True;
10565 end if;
10566
10567 Next_Component (Comp);
10568 end loop;
10569 end if;
10570 end if;
10571
10572 return False;
10573 end Has_Some_Controlled_Component;
10574
10575 -- Start of processing for Needs_Finalization
10576
10577 begin
10578 -- Certain run-time configurations and targets do not provide support
10579 -- for controlled types.
10580
10581 if Restriction_Active (No_Finalization) then
10582 return False;
10583
10584 -- C++ types are not considered controlled. It is assumed that the non-
10585 -- Ada side will handle their clean up.
10586
10587 elsif Convention (Typ) = Convention_CPP then
10588 return False;
10589
10590 -- Class-wide types are treated as controlled because derivations from
10591 -- the root type may introduce controlled components.
10592
10593 elsif Is_Class_Wide_Type (Typ) then
10594 return True;
10595
10596 -- Concurrent types are controlled as long as their corresponding record
10597 -- is controlled.
10598
10599 elsif Is_Concurrent_Type (Typ)
10600 and then Present (Corresponding_Record_Type (Typ))
10601 and then Needs_Finalization (Corresponding_Record_Type (Typ))
10602 then
10603 return True;
10604
10605 -- Otherwise the type is controlled when it is either derived from type
10606 -- [Limited_]Controlled and not subject to aspect Disable_Controlled, or
10607 -- contains at least one controlled component.
10608
10609 else
10610 return
10611 Is_Controlled (Typ) or else Has_Some_Controlled_Component (Typ);
10612 end if;
10613 end Needs_Finalization;
10614
10615 ---------------------------- 10723 ----------------------------
10616 -- New_Class_Wide_Subtype -- 10724 -- New_Class_Wide_Subtype --
10617 ---------------------------- 10725 ----------------------------
10618 10726
10619 function New_Class_Wide_Subtype 10727 function New_Class_Wide_Subtype
10769 declare 10877 declare
10770 P : constant Node_Id := Prefix (N); 10878 P : constant Node_Id := Prefix (N);
10771 Ptyp : constant Entity_Id := Etype (P); 10879 Ptyp : constant Entity_Id := Etype (P);
10772 10880
10773 begin 10881 begin
10774 -- If we know the component size and it is less than 64, then 10882 -- If we know the component size and it is not larger than 64,
10775 -- we are definitely OK. The back end always does assignment of 10883 -- then we are definitely OK. The back end does the assignment
10776 -- misaligned small objects correctly. 10884 -- of misaligned small objects correctly.
10777 10885
10778 if Known_Static_Component_Size (Ptyp) 10886 if Known_Static_Component_Size (Ptyp)
10779 and then Component_Size (Ptyp) <= 64 10887 and then Component_Size (Ptyp) <= 64
10780 then 10888 then
10781 return False; 10889 return False;
10794 declare 10902 declare
10795 P : constant Node_Id := Prefix (N); 10903 P : constant Node_Id := Prefix (N);
10796 Comp : constant Entity_Id := Entity (Selector_Name (N)); 10904 Comp : constant Entity_Id := Entity (Selector_Name (N));
10797 10905
10798 begin 10906 begin
10799 -- If there is no component clause, then we are in the clear 10907 -- This is the crucial test: if the component itself causes
10800 -- since the back end will never misalign a large component 10908 -- trouble, then we can stop and return True.
10801 -- unless it is forced to do so. In the clear means we need
10802 -- only the recursive test on the prefix.
10803 10909
10804 if Component_May_Be_Bit_Aligned (Comp) then 10910 if Component_May_Be_Bit_Aligned (Comp) then
10805 return True; 10911 return True;
10912
10913 -- Otherwise, we need to test the prefix, to see if we are
10914 -- selecting from a possibly unaligned component.
10915
10806 else 10916 else
10807 return Possible_Bit_Aligned_Component (P); 10917 return Possible_Bit_Aligned_Component (P);
10808 end if; 10918 end if;
10809 end; 10919 end;
10810 10920
10813 10923
10814 when N_Slice => 10924 when N_Slice =>
10815 return Possible_Bit_Aligned_Component (Prefix (N)); 10925 return Possible_Bit_Aligned_Component (Prefix (N));
10816 10926
10817 -- For an unchecked conversion, check whether the expression may 10927 -- For an unchecked conversion, check whether the expression may
10818 -- be bit-aligned. 10928 -- be bit aligned.
10819 10929
10820 when N_Unchecked_Type_Conversion => 10930 when N_Unchecked_Type_Conversion =>
10821 return Possible_Bit_Aligned_Component (Expression (N)); 10931 return Possible_Bit_Aligned_Component (Expression (N));
10822 10932
10823 -- If we have none of the above, it means that we have fallen off the 10933 -- If we have none of the above, it means that we have fallen off the
11301 end if; 11411 end if;
11302 11412
11303 -- Generate: 11413 -- Generate:
11304 -- Rnn : Exp_Type renames Expr; 11414 -- Rnn : Exp_Type renames Expr;
11305 11415
11306 if Renaming_Req then 11416 -- In GNATprove mode, we prefer to use renamings for intermediate
11417 -- variables to definition of constants, due to the implicit move
11418 -- operation that such a constant definition causes as part of the
11419 -- support in GNATprove for ownership pointers. Hence, we generate
11420 -- a renaming for a reference to an object of a nonscalar type.
11421
11422 if Renaming_Req
11423 or else (GNATprove_Mode
11424 and then Is_Object_Reference (Exp)
11425 and then not Is_Scalar_Type (Exp_Type))
11426 then
11307 E := 11427 E :=
11308 Make_Object_Renaming_Declaration (Loc, 11428 Make_Object_Renaming_Declaration (Loc,
11309 Defining_Identifier => Def_Id, 11429 Defining_Identifier => Def_Id,
11310 Subtype_Mark => New_Occurrence_Of (Exp_Type, Loc), 11430 Subtype_Mark => New_Occurrence_Of (Exp_Type, Loc),
11311 Name => Relocate_Node (Exp)); 11431 Name => Relocate_Node (Exp));
11423 Insert_Action (Exp, E); 11543 Insert_Action (Exp, E);
11424 end if; 11544 end if;
11425 11545
11426 -- For expressions that denote names, we can use a renaming scheme. 11546 -- For expressions that denote names, we can use a renaming scheme.
11427 -- This is needed for correctness in the case of a volatile object of 11547 -- This is needed for correctness in the case of a volatile object of
11428 -- a non-volatile type because the Make_Reference call of the "default" 11548 -- a nonvolatile type because the Make_Reference call of the "default"
11429 -- approach would generate an illegal access value (an access value 11549 -- approach would generate an illegal access value (an access value
11430 -- cannot designate such an object - see Analyze_Reference). 11550 -- cannot designate such an object - see Analyze_Reference).
11431 11551
11432 elsif Is_Name_Reference (Exp) 11552 elsif Is_Name_Reference (Exp)
11433 11553
11445 Defining_Identifier => Def_Id, 11565 Defining_Identifier => Def_Id,
11446 Subtype_Mark => New_Occurrence_Of (Exp_Type, Loc), 11566 Subtype_Mark => New_Occurrence_Of (Exp_Type, Loc),
11447 Name => Relocate_Node (Exp))); 11567 Name => Relocate_Node (Exp)));
11448 11568
11449 -- If this is a packed reference, or a selected component with 11569 -- If this is a packed reference, or a selected component with
11450 -- a non-standard representation, a reference to the temporary 11570 -- a nonstandard representation, a reference to the temporary
11451 -- will be replaced by a copy of the original expression (see 11571 -- will be replaced by a copy of the original expression (see
11452 -- Exp_Ch2.Expand_Renaming). Otherwise the temporary must be 11572 -- Exp_Ch2.Expand_Renaming). Otherwise the temporary must be
11453 -- elaborated by gigi, and is of course not to be replaced in-line 11573 -- elaborated by gigi, and is of course not to be replaced in-line
11454 -- by the expression it renames, which would defeat the purpose of 11574 -- by the expression it renames, which would defeat the purpose of
11455 -- removing the side effect. 11575 -- removing the side effect.
11659 -- copy may be used in a context where this flag must be set (otherwise 11779 -- copy may be used in a context where this flag must be set (otherwise
11660 -- why would the flag be set in the first place). 11780 -- why would the flag be set in the first place).
11661 11781
11662 Set_Assignment_OK (Res, Assignment_OK (Exp)); 11782 Set_Assignment_OK (Res, Assignment_OK (Exp));
11663 11783
11784 -- Preserve the Do_Range_Check flag in all copies
11785
11786 Set_Do_Range_Check (Res, Do_Range_Check (Exp));
11787
11664 -- Finally rewrite the original expression and we are done 11788 -- Finally rewrite the original expression and we are done
11665 11789
11666 Rewrite (Exp, Res); 11790 Rewrite (Exp, Res);
11667 Analyze_And_Resolve (Exp, Exp_Type); 11791 Analyze_And_Resolve (Exp, Exp_Type);
11668 11792
12051 At_Lib_Level : constant Boolean := 12175 At_Lib_Level : constant Boolean :=
12052 Lib_Level 12176 Lib_Level
12053 and then Nkind_In (N, N_Package_Body, 12177 and then Nkind_In (N, N_Package_Body,
12054 N_Package_Specification); 12178 N_Package_Specification);
12055 -- N is at the library level if the top-most context is a package and 12179 -- N is at the library level if the top-most context is a package and
12056 -- the path taken to reach N does not inlcude non-package constructs. 12180 -- the path taken to reach N does not include nonpackage constructs.
12057 12181
12058 begin 12182 begin
12059 case Nkind (N) is 12183 case Nkind (N) is
12060 when N_Accept_Statement 12184 when N_Accept_Statement
12061 | N_Block_Statement 12185 | N_Block_Statement
12124 Obj_Typ : Entity_Id; 12248 Obj_Typ : Entity_Id;
12125 Pack_Id : Entity_Id; 12249 Pack_Id : Entity_Id;
12126 Typ : Entity_Id; 12250 Typ : Entity_Id;
12127 12251
12128 begin 12252 begin
12129 if No (L) 12253 if No (L) or else Is_Empty_List (L) then
12130 or else Is_Empty_List (L)
12131 then
12132 return False; 12254 return False;
12133 end if; 12255 end if;
12134 12256
12135 Decl := First (L); 12257 Decl := First (L);
12136 while Present (Decl) loop 12258 while Present (Decl) loop
12738 Name => New_Occurrence_Of (Ent, Loc), 12860 Name => New_Occurrence_Of (Ent, Loc),
12739 Expression => Make_Integer_Literal (Loc, Uint_1)); 12861 Expression => Make_Integer_Literal (Loc, Uint_1));
12740 12862
12741 -- Mark the assignment statement as elaboration code. This allows 12863 -- Mark the assignment statement as elaboration code. This allows
12742 -- the early call region mechanism (see Sem_Elab) to properly 12864 -- the early call region mechanism (see Sem_Elab) to properly
12743 -- ignore such assignments even though they are non-preelaborable 12865 -- ignore such assignments even though they are nonpreelaborable
12744 -- code. 12866 -- code.
12745 12867
12746 Set_Is_Elaboration_Code (Asn); 12868 Set_Is_Elaboration_Code (Asn);
12747 12869
12748 if Nkind (Parent (N)) = N_Subunit then 12870 if Nkind (Parent (N)) = N_Subunit then
13398 -- No such check is required for AND and OR, since for both these cases 13520 -- No such check is required for AND and OR, since for both these cases
13399 -- False op False = False, and True op True = True, and no check is 13521 -- False op False = False, and True op True = True, and no check is
13400 -- required for the case of False .. False, since False xor False = False. 13522 -- required for the case of False .. False, since False xor False = False.
13401 -- See also Silly_Boolean_Array_Not_Test 13523 -- See also Silly_Boolean_Array_Not_Test
13402 13524
13403 procedure Silly_Boolean_Array_Xor_Test (N : Node_Id; T : Entity_Id) is 13525 procedure Silly_Boolean_Array_Xor_Test
13526 (N : Node_Id;
13527 R : Node_Id;
13528 T : Entity_Id)
13529 is
13404 Loc : constant Source_Ptr := Sloc (N); 13530 Loc : constant Source_Ptr := Sloc (N);
13405 CT : constant Entity_Id := Component_Type (T); 13531 CT : constant Entity_Id := Component_Type (T);
13406 13532
13407 begin 13533 begin
13408 -- The check we install is 13534 -- The check we install is
13419 13545
13420 Insert_Action (N, 13546 Insert_Action (N,
13421 Make_Raise_Constraint_Error (Loc, 13547 Make_Raise_Constraint_Error (Loc,
13422 Condition => 13548 Condition =>
13423 Make_And_Then (Loc, 13549 Make_And_Then (Loc,
13424 Left_Opnd => 13550 Left_Opnd =>
13425 Make_And_Then (Loc, 13551 Make_And_Then (Loc,
13426 Left_Opnd => 13552 Left_Opnd =>
13427 Convert_To (Standard_Boolean, 13553 Convert_To (Standard_Boolean,
13428 Make_Attribute_Reference (Loc, 13554 Make_Attribute_Reference (Loc,
13429 Prefix => New_Occurrence_Of (CT, Loc), 13555 Prefix => New_Occurrence_Of (CT, Loc),
13430 Attribute_Name => Name_First)), 13556 Attribute_Name => Name_First)),
13431 13557
13433 Convert_To (Standard_Boolean, 13559 Convert_To (Standard_Boolean,
13434 Make_Attribute_Reference (Loc, 13560 Make_Attribute_Reference (Loc,
13435 Prefix => New_Occurrence_Of (CT, Loc), 13561 Prefix => New_Occurrence_Of (CT, Loc),
13436 Attribute_Name => Name_Last))), 13562 Attribute_Name => Name_Last))),
13437 13563
13438 Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))), 13564 Right_Opnd => Make_Non_Empty_Check (Loc, R)),
13439 Reason => CE_Range_Check_Failed)); 13565 Reason => CE_Range_Check_Failed));
13440 end Silly_Boolean_Array_Xor_Test; 13566 end Silly_Boolean_Array_Xor_Test;
13441 13567
13442 -------------------------- 13568 --------------------------
13443 -- Target_Has_Fixed_Ops -- 13569 -- Target_Has_Fixed_Ops --
13444 -------------------------- 13570 --------------------------
13551 E : Entity_Id; 13677 E : Entity_Id;
13552 13678
13553 begin 13679 begin
13554 E := First_Component_Or_Discriminant (Typ); 13680 E := First_Component_Or_Discriminant (Typ);
13555 while Present (E) loop 13681 while Present (E) loop
13556 if Component_May_Be_Bit_Aligned (E) 13682 -- This is the crucial test: if the component itself causes
13557 or else Type_May_Have_Bit_Aligned_Components (Etype (E)) 13683 -- trouble, then we can stop and return True.
13558 then 13684
13685 if Component_May_Be_Bit_Aligned (E) then
13686 return True;
13687 end if;
13688
13689 -- Otherwise, we need to test its type, to see if it may
13690 -- itself contain a troublesome component.
13691
13692 if Type_May_Have_Bit_Aligned_Components (Etype (E)) then
13559 return True; 13693 return True;
13560 end if; 13694 end if;
13561 13695
13562 Next_Component_Or_Discriminant (E); 13696 Next_Component_Or_Discriminant (E);
13563 end loop; 13697 end loop;