Fortran: Avoid redundant call in array constructor and fix buffer overflow.
Fixes a Fortran compiler bug causing redundant function calls and a stack buffer overflow in array constructors.
This commit addresses two issues in the Fortran front-end related to array constructors. It prevents a redundant function call when no_function_call is set, and fixes a stack buffer overflow in gfc_conv_array_parameter by correctly using the explicit character type-spec length instead of inferring it from the first element.
In Details
The gfc_conv_procedure_call in trans-expr.cc was generating an unnecessary call to the pre chain when no_function_call was active and character result length was already determined. Additionally, gfc_conv_array_parameter in trans-array.cc suffered a stack buffer overflow due to an undersized length calculation; it now correctly uses the explicitly specified character type-spec length, resolving PR fortran/53296.
- array constructor
- In Fortran, a syntax used to create an array literal, initializing its elements with specified values.
- stack buffer overflow
- A type of software vulnerability that occurs when a program writes data beyond the allocated buffer on the call stack, potentially corrupting adjacent memory and leading to crashes or arbitrary code execution.
- `no_function_call`
- A compiler option or internal flag that, when set, attempts to avoid generating explicit function calls, possibly for optimization or specific code generation scenarios.
- type-spec length
- In Fortran, refers to the specified length of a character data type, which can be defined explicitly or implicitly.