[Ada] Proper freezing for dispatching expression functions.
authorEd Schonberg <schonberg@adacore.com>
Tue, 7 Jun 2022 20:22:04 +0000 (13:22 -0700)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 12 Jul 2022 12:24:12 +0000 (12:24 +0000)
commitbe4ab2ae015e1e18a4e5b57ab5d87e6f30e6749e
treefe03293b2872fc585388b403d3cc33fd9edef1ee
parenta8d17a88a52d2f773423adb55399d23ed5ea03c8
[Ada] Proper freezing for dispatching expression functions.

In the case of an expression function that is a primitive function of a
tagged type, freezing the tagged type needs to freeze the function (and
its return expression). A bug in this area could result in incorrect
behavior both at compile time and at run time. At compile time, freezing
rule violations could go undetected so that an illegal program could be
incorrectly accepted. At run time, a dispatching call to the primitive
function could end up dispatching through a not-yet-initialized slot in
the dispatch table, typically (although not always) resulting in a
segmentation fault.

gcc/ada/

* freeze.adb (Check_Expression_Function.Find_Constant): Add a
check that a type that is referenced as the prefix of an
attribute is fully declared.
(Freeze_And_Append): Do not freeze the profile when freezing an
expression function.
(Freeze_Entity): When a tagged type is frozen, also freeze any
primitive operations of the type that are expression functions.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Do not prevent
freezing associated with an expression function body if the
function is a dispatching op.
gcc/ada/freeze.adb
gcc/ada/sem_ch6.adb