I am trying to see if SAL can be used to detect concurrency bugs. I prepared a project according to Sample C++ project for code analysis and tried the sample code on Code analysis for C/C++ warnings.
However, I am not getting the warnings that should appear in some of the sample codes. Specifically, C26100, C26101、C26110、C26111、C26112、C26115、C2611 and C26140 get warnings, but C26105, C26116, C26130, C26135, C26160, C26165, C26166 and C26167 do not.
For C26105, we tried the following code on C26105
#include <sal.h>
#include <Windows.h>
_Create_lock_level_(MutexLockLevel);
_Create_lock_level_(TunnelLockLevel);
_Create_lock_level_(ChannelLockLevel);
_Lock_level_order_(MutexLockLevel, TunnelLockLevel);
_Lock_level_order_(TunnelLockLevel, ChannelLockLevel);
_Has_lock_level_(MutexLockLevel) HANDLE gMutex;
struct Tunnel
{
_Has_lock_level_(TunnelLockLevel) CRITICAL_SECTION cs;
};
struct Channel
{
_Has_lock_level_(ChannelLockLevel) CRITICAL_SECTION cs;
};
void OrderInversion(Channel* pChannel, Tunnel* pTunnel)
{
EnterCriticalSection(&pChannel->cs);
// I expect Warning C26105, but no warning.
WaitForSingleObject(gMutex, INFINITE);
EnterCriticalSection(&pTunnel->cs);
LeaveCriticalSection(&pTunnel->cs);
LeaveCriticalSection(&pChannel->cs);
}
Why is this? If you have any information, I would appreciate it if you could let me know.
My environment is as follows.
- Windows 10 Pro 21H2 19044.1826
- Visual Studio Community 2022 Version 17.2.6