[cfe-users] Making analyzer understand VC assert

Jordan Rose jordan_rose at apple.com
Mon Nov 11 08:52:45 PST 2013


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


On Nov 11, 2013, at 8:25 , Anders Montonen <Anders.Montonen at iki.fi> wrote:

> FWIW I tried adding _wassert to NoReturnFunctionChecker, and it appeared to do the trick.
> 
> -a
> 
> On Mon, 11 Nov 2013, David Blaikie wrote:
> 
>> +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?
>> On Mon, Nov 11, 2013 at 3:01 AM, Anders Montonen <Anders.Montonen at iki.fi>
>> wrote:
>>      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
>> 
>>      _______________________________________________
>>      cfe-users mailing list
>>      cfe-users at cs.uiuc.edu
>>      http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20131111/1c803190/attachment.html>


More information about the cfe-users mailing list