Fix ICE with maybe_warn_nodiscard on non-dependent calls.
C++ compiler avoids ICE when `maybe_warn_nodiscard` encounters non-dependent calls.
This commit resolves an Internal Compiler Error (ICE) that occurred when the maybe_warn_nodiscard function was invoked on non-dependent calls. The issue arose because cp_get_fndecl_from_callee attempted to fold templated callees using constant evaluation, which expects non-templated trees. The fix replaces maybe_constant_init with fold_non_dependent_expr to correctly instantiate templated trees before folding, thus preventing the ICE.
In Details
An ICE was triggered in maybe_warn_nodiscard when processing calls that were not dependent on template parameters. The function cp_get_fndecl_from_callee within cvts.cc was attempting to fold the callee via constant evaluation, but this required non-templated GIMPLE trees. By switching the call to fold_non_dependent_expr, the templated trees are now instantiated first, allowing them to be correctly processed by constant evaluation, thus avoiding the ICE.
- Internal Compiler Error (ICE)
- An unrecoverable error within the compiler itself, indicating a bug in the compiler's logic.
- maybe_warn_nodiscard
- A compiler function that checks and potentially warns about the misuse of functions marked with the
[[nodiscard]]attribute. - non-dependent call
- In the context of C++ templates, a function call whose behavior or resolution does not depend on the template arguments.
- constant evaluation
- The process by which the compiler determines the value of an expression at compile time rather than at runtime.
- GIMPLE
- GCC's internal representation (IR) used between the front-end and the optimization passes. It's a three-address code form.