[clang] [analyzer] Teach analzer about ms __analyzer_assume(bool) and friends (PR #80456)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 2 12:59:55 PST 2024


Xazax-hun wrote:

Hey!

Thanks for looking into this!

Did you actually encounter this call in the wild? The reason I ask, because their definition looks like this in the current version of `sal.h`:

```
#ifndef __analysis_assume // [
#ifdef _PREFAST_ // [
#define __analysis_assume(expr) __assume(expr)
#else // ][
#define __analysis_assume(expr)
#endif // ]
#endif // ]

#ifndef _Analysis_assume_ // [
#ifdef _PREFAST_ // [
#define _Analysis_assume_(expr) __assume(expr)
#else // ][
#define _Analysis_assume_(expr)
#endif // ]
#endif // ]
```

The basic idea is, when MSVC's analyzer is invoked, `_PREFAST_` is defined, and these macros should expand to `__assume(expr)`. This makes me a bit surprised if the original names are present in the preprocessed code.

There is no difference between `__analysis_assume` and `_Analysis_assume_`. The former is following the naming conventions in SAL 1, the latter is following the conventions of SAL 2. The latter is preferred in user code, but MSVC's toolchain still supports both spellings. 

https://github.com/llvm/llvm-project/pull/80456


More information about the cfe-commits mailing list