+2014-07-17 Robert Dewar <dewar@adacore.com>
+
+ * gnat_rm.texi: Improve documentation of Unrestricted_Access.
+ * sinfo.ads: Document restriction on aggregates (must expand to
+ assignments if one or more assignments needs expansion, e.g. for
+ controlled types).
+ * sem_ch13.adb: All warning messages regarding bit order should
+ be info: messages.
+ * gnat_ugn.texi: Minor correction of missing @ on @code
+
+2014-07-17 Robert Dewar <dewar@adacore.com>
+
+ * restrict.ads (Implementation_Restriction): Add No_Long_Long_Integer.
+ * s-rident.ads (Partition_Boolean_Restrictions): Add
+ No_Long_Long_Integer.
+ * sem_ch3.adb (Modular_Type_Declaration): Size must be <=
+ Long_Integer'Size if restriction No_Long_Long_Integer is active.
+ (Signed_Integer_Type_Declaration): Do not allow Long_Long_Integer
+ as the implicit base type for a signed integer type declaration
+ if restriction No_Long_Long_Integer is active.
+ * sem_util.ads, sem_util.adb (Set_Entity_With_Checks): Include check for
+ No_Long_Long_Integer.
+
2014-07-17 Robert Dewar <dewar@adacore.com>
* sem_ch3.adb, a-ztexio.ads, exp_imgv.adb, casing.adb, casing.ads,
cases of porting legacy code which implicitly assumes the size of pointers,
and such code should not in any case be using this attribute.
+Another erroroneous situation arises if the attribute is
+applied to a constant. The resulting pointer can be used to access the
+constant, but the effect of trying to modify a constant in this manner
+is not well-defined. Consider this example:
+
+@smallexample @c ada
+P : constant Integer := 4;
+type R is access all Integer;
+RV : R := P'Unrestricted_Access;
+..
+RV.all := 3;
+@end smallexample
+
+@noindent
+Here we attempt to modify the constant P from 4 to 3, but the compiler may
+or may not notice this attempt, and subsequent references to P may yield
+either the value 3 or the value 4 or the assignment may blow up if the
+compiler decides to put P in read-only memory. One particular case where
+@code{Unrestricted_Access} can be used in this way is to modify the
+value of an @code{IN} parameter:
+
+@smallexample @c ada
+procedure K (S : in String) is
+ type R is access all Character;
+ RV : R := S (3)'Unrestricted_Access;
+begin
+ RV.all := 'a';
+end;
+@end smallexample
+
+@noindent
+In general this is a risky approach. It may appear to "work" but such uses of
+@code{Unrestricted_Access} are potentially non-portable, even from one version
+of @code{GNAT} to another, so are best avoided if possible.
+
@node Attribute Update
@unnumberedsec Attribute Update
@findex Update
@code{Alignment_Check},
@code{Duplicated_Tag_Check}, @code{Predicate_Check}, and
@code{Validity_Check}, as well as any checks introduced using
-@code{pragma Check_Name}. Note that code{Atomic_Synchronization}
+@code{pragma Check_Name}. Note that @code{Atomic_Synchronization}
is not automatically suppressed by use of this option.
If the code depends on certain checks being active, you can use
-- restriction to the binder.
-- The following declarations establish a mapping between restriction
- -- identifiers, and the names of corresponding restriction library units.
+ -- identifiers, and the names of corresponding restricted library units.
type Unit_Entry is record
Res_Id : Restriction_Id;
No_Implicit_Loops => True,
No_Initialize_Scalars => True,
No_Local_Protected_Objects => True,
+ No_Long_Long_Integer => True,
No_Protected_Type_Allocators => True,
No_Relative_Delay => True,
No_Requeue_Statements => True,
No_Local_Allocators, -- (RM H.4(8))
No_Local_Timing_Events, -- (RM D.7(10.2/2))
No_Local_Protected_Objects, -- Ada 2012 (D.7(10/1.3))
+ No_Long_Long_Integer, -- GNAT
No_Nested_Finalization, -- (RM D.7(4))
No_Protected_Type_Allocators, -- Ada 2012 (D.7 (10.3/2))
No_Protected_Types, -- (RM H.4(5))
and then CSZ mod System_Storage_Unit = 0
then
Error_Msg_N
- ("multi-byte field specified with non-standard"
- & " Bit_Order??", CLC);
+ ("info: multi-byte field specified with "
+ & "non-standard Bit_Order?V?", CLC);
if Bytes_Big_Endian then
Error_Msg_N
- ("bytes are not reversed "
- & "(component is big-endian)??", CLC);
+ ("\bytes are not reversed "
+ & "(component is big-endian)?V?", CLC);
else
Error_Msg_N
- ("bytes are not reversed "
- & "(component is little-endian)??", CLC);
+ ("\bytes are not reversed "
+ & "(component is little-endian)?V?", CLC);
end if;
-- Do not allow non-contiguous field
and then Warn_On_Reverse_Bit_Order
then
Error_Msg_N
- ("Bit_Order clause does not affect " &
+ ("info: Bit_Order clause does not affect " &
"byte ordering?V?", Pos);
Error_Msg_Uint_1 :=
Intval (Pos) + Intval (FB) /
System_Storage_Unit;
Error_Msg_N
- ("position normalized to ^ before bit " &
+ ("info: position normalized to ^ before bit " &
"order interpreted?V?", Pos);
end if;
if Warn_On_Reverse_Bit_Order then
Error_Msg_N
- ("multi-byte field specified with "
+ ("info: multi-byte field specified with "
& " non-standard Bit_Order?V?", CC);
if Bytes_Big_Endian then
if Bytes_Big_Endian then
Error_Msg_NE
- ("\big-endian range for "
- & "component & is ^ .. ^?V?",
- First_Bit (CC), Comp);
+ ("\big-endian range for component "
+ & "& is ^ .. ^?V?", First_Bit (CC), Comp);
else
Error_Msg_NE
- ("\little-endian range "
- & "for component & is ^ .. ^?V?",
- First_Bit (CC), Comp);
+ ("\little-endian range for component"
+ & "& is ^ .. ^?V?", First_Bit (CC), Comp);
end if;
end if;
M_Val := 2 ** System_Max_Binary_Modulus_Power;
end if;
+ if M_Val > 2 ** Standard_Long_Integer_Size then
+ Check_Restriction (No_Long_Long_Integer, Mod_Expr);
+ end if;
+
Set_Modulus (T, M_Val);
-- Create bounds for the modular type based on the modulus given in
Base_Typ := Base_Type (Standard_Long_Integer);
elsif Can_Derive_From (Standard_Long_Long_Integer) then
+ Check_Restriction (No_Long_Long_Integer, Def);
Base_Typ := Base_Type (Standard_Long_Long_Integer);
else
Check_Restriction (No_Abort_Statements, Post_Node);
end if;
+ if Val = Standard_Long_Long_Integer then
+ Check_Restriction (No_Long_Long_Integer, Post_Node);
+ end if;
+
-- Check for violation of No_Dynamic_Attachment
if Restriction_Check_Required (No_Dynamic_Attachment)
-- If restriction No_Dynamic_Attachment is set, then it checks that the
-- entity is not one of the restricted names for this restriction.
--
+ -- If restriction No_Long_Long_Integer is set, then it checks that the
+ -- entity is not Standard.Long_Long_Integer.
+ --
-- If restriction No_Implementation_Identifiers is set, then it checks
-- that the entity is not implementation defined.
-- references a subprogram that is a renaming, then the front end must
-- rewrite the attribute to refer directly to the renamed entity.
+ -- Note: syntactically the prefix of an attribute reference must be a
+ -- name, and this (somewhat artificial) requirement is enforced by the
+ -- parser. However, for many attributes, such as 'Valid, it is quite
+ -- reasonable to apply the attribute to any value, and hence to any
+ -- expression. Internally in the tree, the prefix is an expression which
+ -- does not have to be a name, and this is handled fine by the semantic
+ -- analysis and expansion, and back ends. This arises for the case of
+ -- attribute references built by the expander (e.g. 'Valid for the case
+ -- of an implicit validity check).
+
-- Note: In generated code, the Address and Unrestricted_Access
-- attributes can be applied to any expression, and the meaning is
-- to create an object containing the value (the object is in the
-- N_Attribute_Reference
-- Sloc points to apostrophe
- -- Prefix (Node3)
+ -- Prefix (Node3) (general expression, see note above)
-- Attribute_Name (Name2) identifier name from attribute designator
-- Expressions (List1) (set to No_List if no associated expressions)
-- Entity (Node4-Sem) used if the attribute yields a type
-- are not met, then the front end must translate the aggregate into
-- an appropriate set of assignments into a temporary.
- -- Note: for the record aggregate case, gigi/gcc can handle all cases of
- -- record aggregates, including those for packed, and rep-claused
+ -- Note: for the record aggregate case, gigi/gcc can handle most cases
+ -- of record aggregates, including those for packed, and rep-claused
-- records, and also variant records, providing that there are no
- -- variable length fields whose size is not known at compile time, and
- -- providing that the aggregate is presented in fully named form.
+ -- variable length fields whose size is not known at compile time,
+ -- and providing that the aggregate is presented in fully named form.
+
+ -- The other situation in which array aggregates and record aggregates
+ -- cannot be passed to the back end is if assignment to one or more
+ -- components itself needs expansion, e.g. in the case of an assignment
+ -- of an object of a controlled type. In such cases, the front end
+ -- must expand the aggregate to a series of assignments, and apply
+ -- the required expansion to the individual assignment statements.
----------------------------------------------
-- 4.3.1 Record Component Association List --