|
14 | 14 | * the buffer-size, COM-outptr, and wrapper families. We fill |
15 | 15 | * in the gaps. |
16 | 16 | * * MSVC 2012+ (_MSC_VER >= 1700): full SAL 2 in <sal.h>. The |
17 | | - * whole shim is skipped. |
| 17 | + * shim's <sal.h> include picks it up; every stub below is |
| 18 | + * guarded with #ifndef, so the shim adds nothing. |
| 19 | + * * MinGW-w64 (GCC, Clang): ships its own <sal.h>. Coverage has |
| 20 | + * varied across releases; some are missing legacy SAL 1 |
| 21 | + * "bytecount"/"ecount" forms like _Inout_opt_bytecount_. The |
| 22 | + * shim fills in any gaps via the same #ifndef-guarded stubs. |
18 | 23 | * |
19 | 24 | * Usage: #include "dxsdk_sal_compat.h" at the top of any bundled |
20 | 25 | * DirectX header (d3dcommon.h, d3d11shader.h, d3dcompiler.h, etc.) |
21 | 26 | * that uses SAL annotations. Place it immediately after the include |
22 | 27 | * guard and before any declarations. |
23 | 28 | * |
24 | 29 | * Every macro is wrapped in #ifndef so we only fill in what the |
25 | | - * toolchain is missing, avoiding C4005 redefinition warnings. |
| 30 | + * toolchain is missing, avoiding C4005 redefinition warnings on |
| 31 | + * MSVC and -Wmacro-redefined on Clang. |
26 | 32 | * |
27 | 33 | * The macros expand to nothing (or to a pass-through for the "wrapper" |
28 | 34 | * forms like _Always_(x) / _When_(c,x)) so that declarations using |
|
35 | 41 | #ifndef DXSDK_SAL_COMPAT_H |
36 | 42 | #define DXSDK_SAL_COMPAT_H |
37 | 43 |
|
38 | | -/* Only kick in on pre-VS2012 MSVC, which lacks full SAL 2. |
39 | | - * _MSC_VER 1700 == VS2012, first to ship full SAL 2 broadly. */ |
40 | | -#if defined(_MSC_VER) && _MSC_VER < 1700 |
41 | | - |
42 | | -/* <sal.h> first appeared in MSVC 2005 (_MSC_VER 1400). |
43 | | - * MSVC 2003 and earlier have no sal.h, so don't try to include it. */ |
44 | | -#if _MSC_VER >= 1400 |
| 44 | +/* The shim activates on any toolchain whose SAL header set is |
| 45 | + * incomplete -- which in practice means pre-VS2012 MSVC *and* some |
| 46 | + * MinGW-w64 releases whose <sal.h> omits legacy SAL 1 forms like |
| 47 | + * _Inout_opt_bytecount_. Per-macro #ifndef guards below make this a |
| 48 | + * no-op on toolchains that already have proper definitions, so |
| 49 | + * activating unconditionally is safe. |
| 50 | + * |
| 51 | + * We still try to include <sal.h> where it exists, so that the |
| 52 | + * #ifndef guards pick up whatever the toolchain does provide. */ |
| 53 | +#if defined(_MSC_VER) && _MSC_VER >= 1400 |
| 54 | +#include <sal.h> |
| 55 | +#elif defined(__has_include) |
| 56 | +#if __has_include(<sal.h>) |
45 | 57 | #include <sal.h> |
46 | 58 | #endif |
| 59 | +#endif |
47 | 60 |
|
48 | 61 | /* --- SAL 1 forms (double-underscore) --------------------------------- * |
49 | 62 | * Present in MSVC 2005+, absent in MSVC 2003. Stub them unconditionally |
|
126 | 139 | #ifndef __field_bcount |
127 | 140 | #define __field_bcount(s) |
128 | 141 | #endif |
| 142 | + |
| 143 | +/* SAL 1 underscore-prefix bytecount/ecount family. |
| 144 | + * Some mingw-w64 releases of <sal.h> omit these. MSVC 2005-2010 may |
| 145 | + * also not define all of them depending on SP level. */ |
| 146 | +#ifndef _In_bytecount_ |
| 147 | +#define _In_bytecount_(s) |
| 148 | +#endif |
| 149 | +#ifndef _In_bytecount_opt_ |
| 150 | +#define _In_bytecount_opt_(s) |
| 151 | +#endif |
| 152 | +#ifndef _Out_bytecount_ |
| 153 | +#define _Out_bytecount_(s) |
| 154 | +#endif |
| 155 | +#ifndef _Out_bytecount_opt_ |
| 156 | +#define _Out_bytecount_opt_(s) |
| 157 | +#endif |
| 158 | +#ifndef _Inout_bytecount_ |
| 159 | +#define _Inout_bytecount_(s) |
| 160 | +#endif |
| 161 | +#ifndef _Inout_bytecount_opt_ |
| 162 | +#define _Inout_bytecount_opt_(s) |
| 163 | +#endif |
| 164 | +#ifndef _Inout_opt_bytecount_ |
| 165 | +#define _Inout_opt_bytecount_(s) |
| 166 | +#endif |
| 167 | +#ifndef _In_ecount_ |
| 168 | +#define _In_ecount_(s) |
| 169 | +#endif |
| 170 | +#ifndef _In_ecount_opt_ |
| 171 | +#define _In_ecount_opt_(s) |
| 172 | +#endif |
| 173 | +#ifndef _Out_ecount_ |
| 174 | +#define _Out_ecount_(s) |
| 175 | +#endif |
| 176 | +#ifndef _Out_ecount_opt_ |
| 177 | +#define _Out_ecount_opt_(s) |
| 178 | +#endif |
| 179 | +#ifndef _Inout_ecount_ |
| 180 | +#define _Inout_ecount_(s) |
| 181 | +#endif |
| 182 | +#ifndef _Inout_ecount_opt_ |
| 183 | +#define _Inout_ecount_opt_(s) |
| 184 | +#endif |
| 185 | + |
129 | 186 | #ifndef __success |
130 | 187 | #define __success(c) |
131 | 188 | #endif |
|
336 | 393 | #define _Analysis_assume_(c) |
337 | 394 | #endif |
338 | 395 |
|
339 | | -#endif /* _MSC_VER < 1700 */ |
340 | | - |
341 | 396 | #endif /* DXSDK_SAL_COMPAT_H */ |
0 commit comments