From 293e84cd5c308aed79d3f9a5ce2bf67319a9147f Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 18 Feb 2026 09:18:10 -0800 Subject: [PATCH] [vm] Use /Zc:preprocessor to get __VA_OPT__ under MSVC. Needed by irregexp. TEST=ci Change-Id: Ie64ee2869ddbb5bad234aea9b49d140b96fed2be Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/481242 Reviewed-by: Alexander Markov Commit-Queue: Ryan Macnak --- runtime/BUILD.gn | 6 ++++++ runtime/bin/dartutils.cc | 4 ++-- runtime/bin/entrypoints_verification_test.cc | 9 --------- runtime/bin/native_assets_api_impl.cc | 4 ++-- runtime/platform/assert.h | 12 +----------- runtime/vm/debugger.h | 5 ----- runtime/vm/isolate_reload.h | 10 ---------- runtime/vm/log.h | 4 ---- runtime/vm/object.cc | 7 ------- runtime/vm/unit_test.h | 2 +- 10 files changed, 12 insertions(+), 51 deletions(-) diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index 769f0d2ced5..7f46c4b8c47 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -284,6 +284,12 @@ config("dart_config") { "/Gw", ] } + if (!is_clang) { + cflags += [ + # Fixes __VA_OPT__ when using MSVC. + "/Zc:preprocessor", + ] + } } else { cflags = [ "-Wno-unused-parameter", diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc index 028176a7f4c..e7280baaab1 100644 --- a/runtime/bin/dartutils.cc +++ b/runtime/bin/dartutils.cc @@ -282,9 +282,9 @@ static Dart_Handle SingleArgDart_Invoke(Dart_Handle lib, // TODO(iposva): Allocate from the zone instead of leaking error string // here. On the other hand the binary is about to exit anyway. #define SET_ERROR_MSG(error_msg, format, ...) \ - intptr_t len = snprintf(nullptr, 0, format, __VA_ARGS__); \ + intptr_t len = snprintf(nullptr, 0, format, ##__VA_ARGS__); \ char* msg = reinterpret_cast(malloc(len + 1)); \ - snprintf(msg, len + 1, format, __VA_ARGS__); \ + snprintf(msg, len + 1, format, ##__VA_ARGS__); \ *error_msg = msg static uint8_t* ReadFileFully(const char* filename, diff --git a/runtime/bin/entrypoints_verification_test.cc b/runtime/bin/entrypoints_verification_test.cc index a446f40bee3..c479c71ceec 100644 --- a/runtime/bin/entrypoints_verification_test.cc +++ b/runtime/bin/entrypoints_verification_test.cc @@ -51,21 +51,12 @@ bool IsTreeShaken(const char* name, Dart_Handle handle, const char* error) { return false; } -#if defined(_MSC_VER) -#define FATAL(fmt, ...) \ - do { \ - fprintf(stderr, "Failed at %s:%d: " fmt "!\n", __FILE__, __LINE__, \ - __VA_ARGS__); \ - abort(); \ - } while (false) -#else #define FATAL(fmt, ...) \ do { \ fprintf(stderr, "Failed at %s:%d: " fmt "!\n", __FILE__, __LINE__, \ ##__VA_ARGS__); \ abort(); \ } while (false) -#endif #define CHECK(H) \ do { \ diff --git a/runtime/bin/native_assets_api_impl.cc b/runtime/bin/native_assets_api_impl.cc index 3f460a9153a..7f5255dc31b 100644 --- a/runtime/bin/native_assets_api_impl.cc +++ b/runtime/bin/native_assets_api_impl.cc @@ -27,9 +27,9 @@ namespace dart { namespace bin { #define SET_ERROR_MSG(error_msg, format, ...) \ - intptr_t len = snprintf(nullptr, 0, format, __VA_ARGS__); \ + intptr_t len = snprintf(nullptr, 0, format, ##__VA_ARGS__); \ char* msg = reinterpret_cast(malloc(len + 1)); \ - snprintf(msg, len + 1, format, __VA_ARGS__); \ + snprintf(msg, len + 1, format, ##__VA_ARGS__); \ *error_msg = msg #if defined(DART_HOST_OS_WINDOWS) diff --git a/runtime/platform/assert.h b/runtime/platform/assert.h index 27ee57fb8fa..707ffa5e330 100644 --- a/runtime/platform/assert.h +++ b/runtime/platform/assert.h @@ -250,13 +250,8 @@ void Expect::Null(const T p) { } // namespace dart -#if defined(_MSC_VER) -#define FATAL(format, ...) \ - dart::Assert(__FILE__, __LINE__).Fail(format, __VA_ARGS__); -#else #define FATAL(format, ...) \ dart::Assert(__FILE__, __LINE__).Fail(format, ##__VA_ARGS__); -#endif #define UNIMPLEMENTED() FATAL("unimplemented code") @@ -402,13 +397,8 @@ void Expect::Null(const T p) { #define EXPECT_NULLPTR(ptr) dart::Expect(__FILE__, __LINE__).Null((ptr)) -#if defined(_MSC_VER) #define FAIL(format, ...) \ - dart::Expect(__FILE__, __LINE__).Fail(format, __VA_ARGS__); -#else -#define FAIL(format, ...) \ - dart::Expect(__FILE__, __LINE__).Fail(format, ##__VA_ARGS__); -#endif + dart::Expect(__FILE__, __LINE__).Fail(format, ##__VA_ARGS__) #endif // defined(TESTING) diff --git a/runtime/vm/debugger.h b/runtime/vm/debugger.h index e1fe7b2b28f..8f19de89116 100644 --- a/runtime/vm/debugger.h +++ b/runtime/vm/debugger.h @@ -24,13 +24,8 @@ DECLARE_FLAG(bool, verbose_debug); // 'Trace Debugger' TD_Print. -#if defined(_MSC_VER) -#define TD_Print(format, ...) \ - if (FLAG_verbose_debug) Log::Current()->Print(format, __VA_ARGS__) -#else #define TD_Print(format, ...) \ if (FLAG_verbose_debug) Log::Current()->Print(format, ##__VA_ARGS__) -#endif namespace dart { diff --git a/runtime/vm/isolate_reload.h b/runtime/vm/isolate_reload.h index 9d70ea867d0..4aa2bf5229d 100644 --- a/runtime/vm/isolate_reload.h +++ b/runtime/vm/isolate_reload.h @@ -23,22 +23,12 @@ DECLARE_FLAG(bool, trace_reload); DECLARE_FLAG(bool, trace_reload_verbose); // 'Trace Isolate Reload' TIR_Print -#if defined(_MSC_VER) -#define TIR_Print(format, ...) \ - if (FLAG_trace_reload) Log::Current()->Print(format, __VA_ARGS__) -#else #define TIR_Print(format, ...) \ if (FLAG_trace_reload) Log::Current()->Print(format, ##__VA_ARGS__) -#endif // 'Verbose Trace Isolate Reload' VTIR_Print -#if defined(_MSC_VER) -#define VTIR_Print(format, ...) \ - if (FLAG_trace_reload_verbose) Log::Current()->Print(format, __VA_ARGS__) -#else #define VTIR_Print(format, ...) \ if (FLAG_trace_reload_verbose) Log::Current()->Print(format, ##__VA_ARGS__) -#endif #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) diff --git a/runtime/vm/log.h b/runtime/vm/log.h index 712eb7527e3..ac699611597 100644 --- a/runtime/vm/log.h +++ b/runtime/vm/log.h @@ -14,11 +14,7 @@ namespace dart { class IsolateGroup; class LogBlock; -#if defined(_MSC_VER) -#define THR_Print(format, ...) Log::Current()->Print(format, __VA_ARGS__) -#else #define THR_Print(format, ...) Log::Current()->Print(format, ##__VA_ARGS__) -#endif #define THR_VPrint(format, args) Log::Current()->VPrint(format, args) diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index 72b09310871..d294371c082 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -222,17 +222,10 @@ PRECOMPILER_WSR_FIELD_DEFINITION(Function, FunctionType, signature) #undef PRECOMPILER_WSR_FIELD_DEFINITION -#if defined(_MSC_VER) -#define TRACE_TYPE_CHECKS_VERBOSE(format, ...) \ - if (FLAG_trace_type_checks_verbose) { \ - OS::PrintErr(format, __VA_ARGS__); \ - } -#else #define TRACE_TYPE_CHECKS_VERBOSE(format, ...) \ if (FLAG_trace_type_checks_verbose) { \ OS::PrintErr(format, ##__VA_ARGS__); \ } -#endif // Takes a vm internal name and makes it suitable for external user. // diff --git a/runtime/vm/unit_test.h b/runtime/vm/unit_test.h index 0a282ccaf82..1d1942b8ca9 100644 --- a/runtime/vm/unit_test.h +++ b/runtime/vm/unit_test.h @@ -224,7 +224,7 @@ #endif // defined(TARGET_ARCH_{ARM, ARM64}) #define ZONE_STR(FMT, ...) \ - OS::SCreate(Thread::Current()->zone(), FMT, __VA_ARGS__) + OS::SCreate(Thread::Current()->zone(), FMT, ##__VA_ARGS__) inline Dart_Handle NewString(const char* str) { return Dart_NewStringFromCString(str);