This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Tested on i686-linux, committed on trunk
The compiler issues an error (or crashes, if assertions are enabled) on
an explicit dereference of a remote access-to-class-wide value used as
as the controlling prefix in a dispatching call. Such uses are legal per
RM-E.2.2(16/1). The code to validate such dereferences already accounted
for the case of controlling parameters, and is now extended to return
immediately in the case where the dereference is a prefix of a selected
component that has not yet been analyzed). The condition is now checked
again when the selected component is analyzed if it is determined that
it is not part of a prefixed call. In addition, the condition for checking
explicit dereferences in Validate_Remote_Access_To_Class_Wide_Type is
relaxed so that dereferences that do not come from source are no longer
exempt from checking (such cases are apparently obsolete). This change
ensures that cases of implicit dereferences expanded to explicit derefs
get checked here as well (catching cases of illegal prefixed calls to
class-wide operations).
The following test must flag only the four lines marked ERROR when compiled
with -gnat05:
remote_deref_checks.adb:23:16: invalid dereference of a remote access-to-class-wide value
remote_deref_checks.adb:25:12: invalid dereference of a remote access-to-class-wide value
remote_deref_checks.adb:27:15: invalid dereference of a remote access-to-class-wide value
remote_deref_checks.adb:29:19: invalid dereference of a remote access-to-class-wide value
package Remote_Deref_Checks is
pragma Remote_Types;
type Tagged_Type is tagged limited private;
function Prim_Func (Obj : Tagged_Type) return Integer;
function CW_Func (Obj : Tagged_Type'Class) return Integer;
type Acc_To_Class_Wide is access all Tagged_Type'Class;
private
type Tagged_Type is tagged limited record
Int : Integer;
end record;
end Remote_Deref_Checks;
package body Remote_Deref_Checks is
Acc : Acc_To_Class_Wide;
I : Integer;
function Prim_Func (Obj : Tagged_Type) return Integer is
begin
return Obj.Int;
end Prim_Func;
function CW_Func (Obj : Tagged_Type'Class) return Integer is
begin
return Obj.Int;
end CW_Func;
procedure Proc is
begin
I := Acc.all.Prim_Func; -- OK
I := Acc.Prim_Func; -- OK
I := Acc.all.CW_Func; -- ERROR
I := Acc.CW_Func; -- ERROR
I := Acc.Int; -- ERROR
I := Acc.all.Int; -- ERROR
end Proc;
end Remote_Deref_Checks;
Also,
When a type is derived from a private type and the derived type has specified
stream attributes, the compiler incorrectly flags any uses of those stream
attributes. The stream attribute definition clauses are attached to the
derived type's underlying type rather than the (private) derived type
and are missed by Has_Stream_Attribute_Definition. The fix is to use
the derived type's full view for the traversal over representation items.
Tested by ACATS 3.0 test CD10002.
Finally, Ada2005 clarifies the legality rules for static preelaboration.
In particular it stipulates that a controlled type with a user-defined
Initialize procedure is does not have static preelaboration. This patch adds
the needed check.
Examples can be found in Acats tests BA21003 and BA21A01.
2008-04-08 Gary Dismukes <dismukes@adacore.com>
Ed Schonberg <schonberg@adacore.com>
Robert Dewar <dewar@adacore.com>
* sem_cat.adb (Validate_RCI_Subprogram_Declaration): Add tests of
Has_Stream_Attribute_ Definition when checking for available stream
attributes on parameters of a limited type in Ada 2005. Necessary for
proper recognition of visible stream attribute clauses.
(Has_Stream_Attribute_Definition): If the type is derived from a
private type, then use the derived type's underlying type for checking
whether it has stream attributes.
(Validate_Object_Declaration): The check for a user-defined Initialize
procedure applies also to types with controlled components or a
controlled ancestor.
Reject an object declaration in a preelaborated unit if the type is a
controlled type with an overriding Initialize procedure.
(Validate_Remote_Access_To_Class_Wide_Type): Return without further
checking when the parent of a dereference is a selected component and
the name has not been analyzed.
* sem_ch4.adb (Analyze_Selected_Component): Add checking for selected
prefixes that are invalid explicit dereferences of remote
access-to-class-wide values, first checking whether the selected
component is a prefixed form of call to a tagged operation.
(Analyze_Call): Remove code that issues an error for limited function
calls in illegal contexts, as we now support all of the contexts that
were forbidden here.
Allow a function call that returns a task.and appears as the
prefix of a selected component.
(Analyze_Reference): Give error message if we try to make a 'Reference
for an object that is atomic/aliased without its type having the
corresponding attribute.
(Analyze_Call): Remove condition checking for attributes to allow
calls to functions with inherently limited results as prefixes of
attributes. Remove related comment about Class attributes.
(Analyze_Selected_Component): If the prefix is a remote type, check
whether this is a prefixed call before reporting an error.
(Complete_Object_Operation): If the controlling formal is an access to
variable reject an actual that is a constant or an access to one.
(Try_Object_Operation): If prefix is a tagged protected object,retrieve
primitive operations from base type.
* exp_ch4.adb (Expand_N_Indexed_Component): Test for prefix that is a
build-in-place
function call and call Make_Build_In_Place_Call_In_Anonymous_Context.
(Expand_N_Selected_Component): Test for prefix that is a build-in-place
function call and call Make_Build_In_Place_Call_In_Anonymous_Context.
(Expand_N_Slice): Test for prefix that is a build-in-place function call
and call Make_Build_In_Place_Call_In_Anonymous_Context.
(Analyze_Call): Remove code that issues an error for limited function
calls in illegal contexts, as we now support all of the contexts that
were forbidden here.
New calling sequence for Get_Simple_Init_Val
(Expand_Boolean_Operator): Add call to Silly_Boolean_Array_Xor_Test
(Expand_N_Op_Not): Add call to Silly_Boolan_Array_Not_Test
Attachment:
difs
Description: Text document
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |