Skip to content

Commit

Permalink
preprocessor tweak - use new Standard Conforming Preprocessor when bu…
Browse files Browse the repository at this point in the history
…ilding with MSVC, addresses #7042
  • Loading branch information
AnastaZIuk committed Dec 19, 2024
1 parent 6c2b9f3 commit 068610b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND MSVC AND NOT CMAKE_C_COMPILER_ARCHI
add_link_options(/DEBUGTYPE:CV,FIXUP,PDATA /INCREMENTAL:NO)
endif()

if(MSVC)
# use new Standard Conforming Preprocessor
# https://learn.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview?view=msvc-170
add_compile_options(/Zc:preprocessor)
endif()

# enable control flow guard
if(WIN32)
if(MSVC)
Expand Down
25 changes: 25 additions & 0 deletions include/dxc/Support/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ inline void OutputDebugFormatA(const char *pszFormat, ...) {
// This prints 'Hello World (i > 10)' and breaks in the debugger if the
// assertion doesn't hold.
//

#if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL
#define DXASSERT_ARGS(exp, fmt, ...) \
do { \
if (!(exp)) { \
Expand All @@ -304,6 +306,19 @@ inline void OutputDebugFormatA(const char *pszFormat, ...) {
__debugbreak(); \
} \
} while (0)
#else
#define DXASSERT_ARGS(exp, fmt, ...) \
do { \
if (!(exp)) { \
OutputDebugFormatA("Error: \t%s\nFile:\n%s(%d)\nFunc:\t%s.\n\t" fmt \
"\n", \
"!(" #exp ")", __FILE__, __LINE__, \
__FUNCTION__ __VA_OPT__(, ) __VA_ARGS__); \
__debugbreak(); \
} \
} while (0)
#endif

#define DXASSERT(exp, msg) DXASSERT_ARGS(exp, msg)

#define DXASSERT_LOCALVAR(local, exp, msg) DXASSERT(exp, msg)
Expand All @@ -325,13 +340,23 @@ inline void OutputDebugFormatA(const char *pszFormat, ...) {

#define DXVERIFY_NOMSG assert

#if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL
#define DXASSERT_ARGS(expr, fmt, ...) \
do { \
if (!(expr)) { \
fprintf(stderr, fmt, __VA_ARGS__); \
assert(false); \
} \
} while (0)
#else
#define DXASSERT_ARGS(expr, fmt, ...) \
do { \
if (!(expr)) { \
fprintf(stderr, fmt __VA_OPT__(, ) __VA_ARGS__); \
assert(false); \
} \
} while (0)
#endif

#define DXASSERT(expr, msg) \
do { \
Expand Down

0 comments on commit 068610b

Please sign in to comment.