Building SWI-Prolog for Windows using CMake and MSVC with Address Sanitizer.
In running some test designed to look at BFR which fail with an Address Sanitizer error, Claude in looking at the output notes
ASan found a heap-use-after-free bug
Is this a plausible bug? Is this such a rare bug that it is not worth hunting down?
Asking because this bug or something like it seems to be lurking in the garbage collector or some rare sequence and with lack of more details, Claude has to try reason how the code should work, and the code is not easy to understand with the VM instructions, C macros and garbage collection so want to make sure it is a plausible bug before I spend the time, which could be days, to hopefully find the root cause and fix it.
Also since it would take me days to understand the details of the code at that level to manually work on the bug, relying on Claude for help but Claude is not good at realizing that sometimes the tools being used to solve a problem are not enough and does not know which tools would help. Also tried to use Visual Studio IDE but with all of the C macros, Claude can not give me proper commands to look at memory locations or instructions as it is can not reason correctly through all of the C macros. Even tried to generate *.i files using CMake with MSVC and that was not working as expected as the *.i files were not created.
EDIT
Claude thinks this is the fix
EDIT
FYI
Claude created a Minimal reproduction
File name: test_asan_debug_bug.pl
% Minimal reproduction for ASan heap-use-after-free bug
% Bug: callCleanupHandler uses freed memory after stack reallocation
%
% To reproduce:
% swipl -g "test_bug, halt" test_asan_debug_bug.pl
%
% Expected with ASan: heap-use-after-free in callCleanupHandler at pl-wam.c:847
test_bug :-
% This simple sequence triggers the bug:
% 1. set_prolog_flag(debug, true) causes stack growth
% 2. Stack growth reallocates memory
% 3. setup_call_cleanup has cleanup handlers that reference old memory
current_prolog_flag(debug, Old),
set_prolog_flag(debug, true),
setup_call_cleanup(true, true, true),
set_prolog_flag(debug, Old).
The CMake commands used to build the code that generated the bug
cmake .. -G "Visual Studio 18 2026" -A x64 -DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_C_FLAGS="/fsanitize=address" -DCMAKE_CXX_FLAGS="/fsanitize=address" -DINSTALL_DOCUMENTATION=OFF -DSWIPL_PACKAGES=OFF
cmake --build . --config Debug
I have not tried this yet, as in the middle of other builds and testing and only have one machine.

