-- The following checks are relevant only when SPARK_Mode is on, as
-- they are not standard Ada legality rules. Internally generated
- -- temporaries are ignored.
+ -- temporaries are ignored, as well as return objects.
- if SPARK_Mode = On and then Comes_From_Source (Type_Or_Obj_Id) then
+ if SPARK_Mode = On
+ and then Comes_From_Source (Type_Or_Obj_Id)
+ and then not Is_Return_Object (Type_Or_Obj_Id)
+ then
if Is_Effectively_Volatile (Type_Or_Obj_Id) then
-- The declaration of an effectively volatile object or type must
end if;
-- Build a simple_return_statement that returns the return object when
- -- there is a statement sequence, or no expression, or the result will
- -- be built in place. Note however that we currently do this for all
- -- composite cases, even though not all are built in place.
+ -- there is a statement sequence, or no expression, or the analysis of
+ -- the return object declaration generated extra actions, or the result
+ -- will be built in place. Note however that we currently do this for
+ -- all composite cases, even though they are not built in place.
if Present (HSS)
- or else Is_Composite_Type (Ret_Typ)
or else No (Exp)
+ or else List_Length (Return_Object_Declarations (N)) > 1
+ or else Is_Composite_Type (Ret_Typ)
then
if No (HSS) then
Stmts := New_List;
end;
end if;
- -- Case where we do not build a block
-
- else
- -- We're about to drop Return_Object_Declarations on the floor, so
- -- we need to insert it, in case it got expanded into useful code.
- -- Remove side effects from expression, which may be duplicated in
- -- subsequent checks (see Expand_Simple_Function_Return).
+ -- Case where we do not need to build a block. But we're about to drop
+ -- Return_Object_Declarations on the floor, so assert that it contains
+ -- only the return object declaration.
- Insert_List_Before (N, Return_Object_Declarations (N));
- Remove_Side_Effects (Exp);
+ else pragma Assert (List_Length (Return_Object_Declarations (N)) = 1);
-- Build simple_return_statement that returns the expression directly