Fix discriminant check failure for unconstrained actual parameters
Fixes a bug where discriminant checks spuriously failed for unconstrained actual parameters in Ada when initialized by conditional expressions.
The Ada compiler had a bug where discriminant checks would fail for unconstrained variables passed as actual parameters when those variables were initialized using conditional expressions. This occurred because the variable’s declaration was incorrectly distributed into the dependent expressions of the conditional expression. This commit introduces a new predicate Is_Distributable_Declaration to prevent this incorrect distribution and ensure proper discriminant checks.
In Details
The Ada compiler had a bug where discriminant checks would fail for unconstrained variables passed as actual parameters when those variables were initialized using conditional expressions. This commit introduces a new predicate Is_Distributable_Declaration in exp_util.ads and exp_util.adb to prevent the incorrect distribution of the variable's declaration and ensure proper discriminant checks. Calls to local Is_Optimizable_Declaration are replaced by calls to Is_Distributable_Declaration in exp_ch4.adb and exp_ch6.adb.
For Context
In Ada, discriminant checks ensure that a variant record has a valid configuration at runtime. This commit fixes a bug in the Ada compiler related to how it handles discriminant checks for unconstrained (flexible size) variables that are initialized using conditional expressions (like if/else). The compiler was incorrectly distributing the variable's declaration, leading to spurious discriminant check failures. This fix ensures that these checks are performed correctly, preventing potential runtime errors and improving the reliability of Ada programs.