Skip to content

Commit 0306e17

Browse files
committed
dxsdk/SAL: activate compat shim on GCC/MinGW and add SAL 1 bytecount family
The existing dxsdk_sal_compat.h was gated on `_MSC_VER < 1700`, which made the entire shim body invisible to GCC/MinGW toolchains. This worked because mingw-w64's <sal.h> historically provided the SAL macros the bundled DX headers reference -- but not all mingw-w64 releases are complete. MSYS2's current mingw-w64 sal.h omits the legacy SAL 1 form `_Inout_opt_bytecount_`, which the bundled d3d11.h references, so the MXE/MinGW cross-build of gfx/common/dx_guids.c fails to parse d3d11.h. Fix the gate and extend macro coverage: * Replace the `_MSC_VER < 1700` gate with a portable form that pulls in <sal.h> via `__has_include` on non-MSVC toolchains. The shim body then runs on every toolchain, and the per-macro `#ifndef` guards prevent redefinition wherever the toolchain already provides the macro. Net effect on MSVC 2012+ and on complete mingw-w64 releases: no-op. On MSVC 2003-2010 and incomplete mingw-w64 releases: missing macros are stubbed. * Add the SAL 1 underscore-prefix bytecount/ecount family (`_In_bytecount_[_opt_]`, `_Out_bytecount_[_opt_]`, `_Inout_bytecount_[_opt_]`, `_Inout_opt_bytecount_`, and the four `_ecount_[_opt_]` equivalents). `_Inout_opt_bytecount_` is the one actually observed in the MXE/MSYS2 build log; the siblings are added together because they commonly surface in the same parse cascade once any one of them fails. * Update the file comment to document MinGW-w64 coverage and the no-op behavior on MSVC 2012+. Also propagate `#include "dxsdk_sal_compat.h"` to the bundled DX headers that didn't already have it: * gfx/include/dxsdk/d3d10.h, d3d10_1.h, d3d11.h, d3d11shader.h, d3d12.h, d3d12shader.h, d3dcompiler.h: add the shim include at line 1, ahead of the MIDL-generated preamble. The dxgi1_*.h, d3dcommon.h, and dxgi.h headers already got this in an earlier commit; d3d8.h and d3d9.h are not bundled. Downstream effect: * MXE/MSYS2 mingw-w64 cross-build: resolves the `unknown type name '_Inout_opt_bytecount_'` error in gfx/common/dx_guids.c's transitive include of d3d11.h. * MSVC 2003-2010: unchanged (every new stub is #ifndef-guarded, and the SAL 2 additions from the prior dxgi patch remain intact). * MSVC 2012+: unchanged (<sal.h> provides everything, stubs no-op).
1 parent f435158 commit 0306e17

8 files changed

Lines changed: 87 additions & 11 deletions

File tree

gfx/include/dxsdk/d3d10.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* SAL compatibility shim for legacy MSVC and some MinGW-w64 */
2+
#include "dxsdk_sal_compat.h"
3+
14
/*-------------------------------------------------------------------------------------
25
*
36
* Copyright (c) Microsoft Corporation

gfx/include/dxsdk/d3d10_1.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* SAL compatibility shim for legacy MSVC and some MinGW-w64 */
2+
#include "dxsdk_sal_compat.h"
3+
14
/*-------------------------------------------------------------------------------------
25
*
36
* Copyright (c) Microsoft Corporation

gfx/include/dxsdk/d3d11.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* SAL compatibility shim for legacy MSVC and some MinGW-w64 */
2+
#include "dxsdk_sal_compat.h"
3+
14
/*-------------------------------------------------------------------------------------
25
*
36
* Copyright (c) Microsoft Corporation

gfx/include/dxsdk/d3d11shader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* SAL compatibility shim for legacy MSVC and some MinGW-w64 */
2+
#include "dxsdk_sal_compat.h"
3+
14
//////////////////////////////////////////////////////////////////////////////
25
//
36
// Copyright (c) Microsoft Corporation. All rights reserved.

gfx/include/dxsdk/d3d12.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* SAL compatibility shim for legacy MSVC and some MinGW-w64 */
2+
#include "dxsdk_sal_compat.h"
3+
14
/*-------------------------------------------------------------------------------------
25
*
36
* Copyright (c) Microsoft Corporation

gfx/include/dxsdk/d3d12shader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* SAL compatibility shim for legacy MSVC and some MinGW-w64 */
2+
#include "dxsdk_sal_compat.h"
3+
14
//////////////////////////////////////////////////////////////////////////////
25
//
36
// Copyright (c) Microsoft Corporation. All rights reserved.

gfx/include/dxsdk/d3dcompiler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* SAL compatibility shim for legacy MSVC and some MinGW-w64 */
2+
#include "dxsdk_sal_compat.h"
3+
14
//////////////////////////////////////////////////////////////////////////////
25
//
36
// Copyright (c) Microsoft Corporation. All rights reserved.

gfx/include/dxsdk/dxsdk_sal_compat.h

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@
1414
* the buffer-size, COM-outptr, and wrapper families. We fill
1515
* in the gaps.
1616
* * 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.
1823
*
1924
* Usage: #include "dxsdk_sal_compat.h" at the top of any bundled
2025
* DirectX header (d3dcommon.h, d3d11shader.h, d3dcompiler.h, etc.)
2126
* that uses SAL annotations. Place it immediately after the include
2227
* guard and before any declarations.
2328
*
2429
* 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.
2632
*
2733
* The macros expand to nothing (or to a pass-through for the "wrapper"
2834
* forms like _Always_(x) / _When_(c,x)) so that declarations using
@@ -35,15 +41,22 @@
3541
#ifndef DXSDK_SAL_COMPAT_H
3642
#define DXSDK_SAL_COMPAT_H
3743

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>)
4557
#include <sal.h>
4658
#endif
59+
#endif
4760

4861
/* --- SAL 1 forms (double-underscore) --------------------------------- *
4962
* Present in MSVC 2005+, absent in MSVC 2003. Stub them unconditionally
@@ -126,6 +139,50 @@
126139
#ifndef __field_bcount
127140
#define __field_bcount(s)
128141
#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+
129186
#ifndef __success
130187
#define __success(c)
131188
#endif
@@ -336,6 +393,4 @@
336393
#define _Analysis_assume_(c)
337394
#endif
338395

339-
#endif /* _MSC_VER < 1700 */
340-
341396
#endif /* DXSDK_SAL_COMPAT_H */

0 commit comments

Comments
 (0)