libcpp: Fix ICE with __VA_OPT__ [PR125048].
Corrects an internal compiler error related to macro expansion with __VA_OPT__.
This commit resolves an internal compiler error (ICE) in the C preprocessor (libcpp) when handling the __VA_OPT__ macro. The error occurred because macro expansion could reallocate internal data structures while holding pointers to them, leading to a use-after-free situation. The fix ensures that pointers to these reallocated structures are updated correctly.
In Details
A use-after-free bug in macro.cc (replace_args) is fixed. When vaopt_state::update calls expand_arg, which can reallocate pfile->line_table->info_macro.maps, the linemap_enter_macro pointer becomes dangling. This patch stores the offset into the maps array instead of the pointer itself, and recomputes the map pointer after expand_arg returns, preventing the ICE in PR125048.
- libcpp
- The C preprocessor used by GCC. It handles directives like #include, #define, and macro expansion.
- __VA_OPT__
- A preprocessor feature in C99 and later that allows conditional inclusion of tokens when variadic arguments are present in a macro.
- ICE
- Internal Compiler Error. A crash within the compiler itself, usually indicating a bug in the compiler's logic.
- use-after-free
- A memory safety bug where a program attempts to access memory after it has been freed, leading to undefined behavior or crashes.