locked
Problem with SAL Concurrency Rules RRS feed

  • Question

  • Hi,

    Are there any known issues with the SAL concurrency annotations/rules in Visual Studio 2013?

    I have created a minimal working example that should trigger a concurrency related warning when performing the code analysis.

    The expected warning is not reported by Visual Studio/the compiler though. Interestingly, other non-concurrency related problems are reported by the compiler.

    My environment & settings:

    * Visual Studio Professional 2013
    * The example code is actually based on the example provided in the MSDN for compiler warning C26110

    * I have already tried with both rule sets "Microsoft All Rules" and "Microsoft Native Recommended Rules". I used "Configure Code Analysis for Solution" to apply the rules for the entire solution.

    * Based on an example (see below), running the code analysis (Build -> Run Code Analysis On Solution) gives me the expected  warnings for C6011 and C6276. But no warning for the concurrency problem that I expected.

    I am already wondering whether there is anything else I have to activate in Visual Studio to enable concurrency warnings in the compiler analysis.

    Thanks for any help

    The example:

    #include <Windows.h>
    #include <sal.h>
    
    typedef struct _DATA
    {
      CRITICAL_SECTION cs;
      int d;
    } DATA;
    
    _Requires_lock_held_(p->cs)
    void LockRequired(DATA* p)
    {
      p->d = 0;
    }
    
    
    void LockNotHeld(DATA* p)
    {
      LockRequired(p); // should trigger warning C26110 
    }
    
    
    int main()
    {
      DATA myData;
      LockNotHeld(&myData);
    
      // C6011 triggered
      int* a = NULL;
      *a = 3;
    
      // C6276 triggered
      LPWSTR pSrc;
      pSrc = (LPWSTR)"a";
    
      return 0;
    }

    Friday, May 9, 2014 6:38 AM

All replies

  • I was able to get 'C26110 Caller failing to hold lock' with Build -> Run Code Analysis On Solution. I should note that I am using VS2013 Ultimate.
    Tuesday, May 13, 2014 12:21 AM
  • Can somebody (maybe from Microsoft) confirm that the SAL Concurrency rules are only shipped with the Visual Studio Ultimate Edition compiler?
    Tuesday, May 27, 2014 6:52 AM