Making analyzer understand VC assert

Hi,

I'm trying to use Clang's static analyzer with a Visual Studio project, but I'm running into the problem that in Microsoft's headers the _wassert function is not declared as noreturn, which leads to lots of false positives. The assert declaration looks like so:

#undef assert

#define assert(_Expression) (void)( (!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression), _CRT_WIDE(__FILE__), __LINE__), 0) )

_CRTIMP void __cdecl _wassert(_In_z_ const wchar_t * _Message, _In_z_ const wchar_t *_File, _In_ unsigned _Line);

Looking through the source code there seems to be an "--assert=" flag, but it also seems not to be used.

Any advice how to handle this? Since the mingw headers (where the function is properly annotated) differ enough from Microsoft's that it would require modifications in the source code, I would prefer to not have to include them in the mix.

I noticed that there's a number of hardcoded function names in the static analyzer's NoReturnFunctionChecker, should _wassert be added to this list?

-a

+Jordan - do you know much about the NoReturnFunctionChecker and whether it would make sense to handle _wassert there? Is there some other solution that would properly handle this implementation of ‘assert’ in the static analyzer?

FWIW I tried adding _wassert to NoReturnFunctionChecker, and it appeared to do the trick.

-a

Ah, apparently assert() isn’t automatically fatal in the CRT:

When the application is linked with a debug version of the run-time libraries, assert creates a message box with three buttons: Abort, Retry, and Ignore. If the user clicks Abort, the program aborts immediately. If the user clicks Retry, the debugger is called and the user can debug the program if just-in-time (JIT) debugging is enabled. If the user clicks Ignore, assert continues with its normal execution: creating the message box with the OK button. Note that clicking Ignore when an error condition exists can result in undefined behavior.

If this was a user-owned library, we’d ask them to add attribute((analyzer_noreturn)), but as is adding _wassert to NoReturnFunctionChecker seems like the best thing to do.

Jordan

Anders,

I think this is the right approach. Please, send a patch to cfe-commits list for review.

Anna.