clang-cl mysteriously shuts up with --analyze

When I try to build a simple C program (attached), clang-cl warns about some - unrelated to this question - linking issue:

C:\Users\Alexander Riccio\Documents\basically_flawed_c_program>clang-cl basically_flawed_c_program.c
basically_flawed_c_program-1f4f44.obj : error LNK2019: unresolved external symbol malloc referenced in function main
basically_flawed_c_program-1f4f44.obj : error LNK2019: unresolved external symbol free referenced in function main
LINK : error LNK2001: unresolved external symbol mainCRTStartup
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\libcmt.lib : warning LNK4272: library machine type ‘X86’ conflicts with target machine type ‘x64’
basically_flawed_c_program.exe : fatal error LNK1120: 3 unresolved externals
clang-cl.exe: error: linker command failed with exit code 1120 (use -v to see invocation)

…but when I pass --analyze to clang-cl, it shuts up entirely:

C:\Users\Alexander Riccio\Documents\basically_flawed_c_program>clang-cl --analyze basically_flawed_c_program.c

C:\Users\Alexander Riccio\Documents\basically_flawed_c_program>

What’s going on here??

I’m more interested in why the --analyze flag shuts clang-cl up, than I am the strange linker error; but bonus points if you know what’s going on there too.

I’m also attaching the verbose invocations of the two commands.

clang-cl-verbose-invoke.txt (6.3 KB)

basically_flawed_c_program.c (208 Bytes)

When you call clang with “–analyze”, the driver is only going analyze your program with static analysis; it is not going to fully compile or link it. This explains why you do not see the linker error.

Cheers,
Anna.

I don’t think it’s possible. The way scan-build invokes is by invoking clang twice - once for compilation and once for analysis

Uggh. That seems awfully silly? And actually, it’s not compatible with cl.exe, which runs /analyze alongside compilation, and prints warnings to the console.

Is there some reason for that? I imagine that it’d be easier for all users to simply invoke clang once to compile and analyze.