I have struggled a bit to get ASAN working on windows, but I have figured some things out so I wanted to share my findings.
Note: I have tried a number of MSVC versions (and also LLVM clang builds) but for the moment, lets keep this to Visual Studio 2022, and only using the version of clang/LLVM that comes with that install.
This is simple.cpp
#include <stdio.h>
char s[2];
int main () {
printf("1\n");
printf("2\n");
printf("3\n");
printf("4\n");
s[2] = 0;
printf("5\n");
printf("6\n");
printf("7\n");
return 0;
}
First, the obvious (MSVC) thing: cl /ZI /fsanitize=address simple.cpp /Fe:build\simple.exe
simply just doesn’t work, it just crashes, and doesn’t give any ASAN diagnostics
Second, the typical Linux/clang thing to do clang -g -O0 -fsanitize=address simple.cpp -o build\simple.exe
kinda works, but only if you are running under a debugger (see Related:ASan init calls itself (but only when not running under a debugger)), and even then you hit some annoying int 3
breaks in GetInstructionSize(...)
(best I can tell, is that its failing to calculate instruction size for some mov instructions??)
To work around these issues, I found that you can do this this:
clang-cl /Zi -fsanitize=address /c simple.cpp /Fobuild\simple.obj
cl /Zi /fsanitize=address build\simple.obj /Fe:build\simple.exe
I could only make wild speculations as to why that works while the more straightforward invocations have issues