Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use new Standard Conforming Preprocessor when building with MSVC #7043

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ 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
# TODO: update sources for all targets to compile (we checked "dxcompiler" only)
option(LLVM_BUILD_WITH_NEW_MSVC_PREPROCESSOR "Enable MSVC new Standard Conforming Preprocessor" OFF)
if(LLVM_BUILD_WITH_NEW_MSVC_PREPROCESSOR)
add_compile_options(/Zc:preprocessor)
endif()
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
Loading