https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125048
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-16 branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:d2abcdc5727d0d4e31d6d9d5809aed25818d16a8 commit r16-9507-gd2abcdc5727d0d4e31d6d9d5809aed25818d16a8 Author: Jakub Jelinek <[email protected]> Date: Thu Aug 6 11:01:15 2026 +0200 libcpp: Fix up ICE with __VA_OPT__ [PR125048] The following testcase ICEs, because we call linemap_enter_macro and remember what it returned and then in a loop sometimes call vaopt_state::update (src) which can call expand_arg which under the hood can reallocate the pfile->line_table->info_macro.maps array. As linemap_enter_macro returns a pointer into that array, if the array is reallocated, we then dereference the freed memory. The following patch fixes it by remembering the offset into the pfile->line_table->info_macro.maps array and when we could have called expand_arg, updates the map variable so that it is correct even after possible reallocation. 2026-04-28 Jakub Jelinek <[email protected]> PR preprocessor/125048 * macro.cc (replace_args): Remember the position of map in the pfile->line_table->info_macro.maps array and if vostate is DROP, recompute map pointer as expand_arg call could have reallocated the pfile->line_table->info_macro.maps array. * c-c++-common/cpp/va-opt-11.c: New test. Reviewed-by: Jason Merrill <[email protected]> (cherry picked from commit 7b87f41690d46b869c21d0d0537b766698da3827)
