Fix internal error on function call returning extension of limited interface
commit8f80b9f0904eb98b41913068ce7dc021c2f35ecc
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 9 Jan 2024 10:06:23 +0000 (9 11:06 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Tue, 9 Jan 2024 10:06:23 +0000 (9 11:06 +0100)
tree8c6a32273d3d3af695e122d0b6aeb58d15887993
parent436ce7a3510000e0939094592fc12353e17527f1
Fix internal error on function call returning extension of limited interface

The problem occurs when this function call is the expression of a return in
a function returning the limited interface; in this peculiar case, there is
a mismatch between the callee, which has BIP formals but is not a BIP call,
and the caller, which is a BIP function, that is spotted by an assertion.

This is fixed by restoring the semantics of Is_Build_In_Place_Function_Call,
which returns again true only for calls to BIP functions, introducing the
Is_Function_Call_With_BIP_Formals predicate, which also returns true for
calls to functions with BIP formals that are not BIP functions, and moving
down the assertion in Expand_Simple_Function_Return.

gcc/ada/
PR ada/112781
* exp_ch6.ads (Is_Build_In_Place_Function): Adjust description.
* exp_ch6.adb (Is_True_Build_In_Place_Function_Call): Delete.
(Is_Function_Call_With_BIP_Formals): New predicate.
(Is_Build_In_Place_Function_Call): Restore original semantics.
(Expand_Call_Helper): Adjust conditions guarding the calls to
Add_Dummy_Build_In_Place_Actuals to above renaming.
(Expand_N_Extended_Return_Statement): Adjust to above renaming.
(Expand_Simple_Function_Return): Likewise.  Move the assertion
to after the transformation into an extended return statement.
(Make_Build_In_Place_Call_In_Allocator): Remove unreachable code.
(Make_Build_In_Place_Call_In_Assignment): Likewise.

gcc/testsuite/
* gnat.dg/bip_prim_func2.adb: New test.
* gnat.dg/bip_prim_func2_pkg.ads, gnat.dg/bip_prim_func2_pkg.adb:
New helper package.
gcc/ada/exp_ch6.adb
gcc/ada/exp_ch6.ads
gcc/testsuite/gnat.dg/bip_prim_func2.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/bip_prim_func2_pkg.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/bip_prim_func2_pkg.ads [new file with mode: 0644]