diff --git a/include/AST/SourceCode.h b/include/AST/SourceCode.h index 9f9e0d9b..15c11d77 100644 --- a/include/AST/SourceCode.h +++ b/include/AST/SourceCode.h @@ -39,10 +39,10 @@ namespace clice { struct LocalSourceRange { /// The begin position offset to the source file. - uint32_t begin = -1; + uint32_t begin = static_cast(-1); /// The end position offset to the source file. - uint32_t end = -1; + uint32_t end = static_cast(-1); constexpr bool operator== (const LocalSourceRange& other) const = default; diff --git a/include/Support/Enum.h b/include/Support/Enum.h index c4ae997c..3303ec16 100644 --- a/include/Support/Enum.h +++ b/include/Support/Enum.h @@ -232,8 +232,8 @@ public: } template ... Kinds> - bool is_one_of(Kinds... kinds) const { - return (operator& (kinds) || ...); + constexpr bool is_one_of(Kinds... kinds) const { + return (((*this) & (kinds)) || ...); } private: diff --git a/include/Support/JSON.h b/include/Support/JSON.h index bbd75893..b08c1254 100644 --- a/include/Support/JSON.h +++ b/include/Support/JSON.h @@ -298,6 +298,7 @@ template constexpr inline bool is_optional_v> = true; template + requires (!sequence_range) struct Serde { template static json::Value serialize(const T& t) { diff --git a/include/Support/Struct.h b/include/Support/Struct.h index 9bc5b893..57265f60 100644 --- a/include/Support/Struct.h +++ b/include/Support/Struct.h @@ -146,9 +146,12 @@ using member_types = template using member_type = std::tuple_element_t::to_tuple>; +template +concept TupleLike = requires { std::tuple_size::value; }; + /// Specialize for aggregate class. template - requires std::is_aggregate_v + requires std::is_aggregate_v && (!TupleLike) struct Struct { constexpr inline static bool reflectable_struct = true; @@ -318,12 +321,11 @@ struct Struct> { }(std::make_index_sequence{}); }; -template - requires requires { std::tuple_size::value; } -struct Struct { +template +struct Struct { constexpr inline static bool reflectable_struct = true; - constexpr inline static std::size_t member_count = std::tuple_size_v; + constexpr inline static std::size_t member_count = std::tuple_size_v; template constexpr static auto collect_members(Object&& object) { diff --git a/src/Async/FileSystem.cpp b/src/Async/FileSystem.cpp index 493d1d28..f2a3561e 100644 --- a/src/Async/FileSystem.cpp +++ b/src/Async/FileSystem.cpp @@ -134,12 +134,24 @@ Result open(std::string path, Mode mode) { }; } +// MSVC seems to have a bug that it will try to optimize the function with tail call +// but it leads to "C4737: Unable to perform required tail call. Performance may be degraded." +// Discovered in MSVC 14.44.35207 +// Adding /EHa won't help. +// Related: +// https://developercommunity.visualstudio.com/t/coroutine-compilation-resulting-in-error-c4737-una/1510427 +#ifdef _MSC_VER +#pragma optimize("g", off) +#endif Result read(const handle& handle, char* buffer, std::size_t size) { co_return co_await awaiter::read{ .file = handle.value(), .bufs = {uv_buf_init(buffer, size)}, }; } +#ifdef _MSC_VER +#pragma optimize("g", on) +#endif Result read(std::string path, Mode mode) { /// First stat the file to check if it exists, and to get the size @@ -180,12 +192,24 @@ Result read(std::string path, Mode mode) { co_return content; } +// MSVC seems to have a bug that it will try to optimize the function with tail call +// but it leads to "C4737: Unable to perform required tail call. Performance may be degraded." +// Discovered in MSVC 14.44.35207 +// Adding /EHa won't help. +// Related: +// https://developercommunity.visualstudio.com/t/coroutine-compilation-resulting-in-error-c4737-una/1510427 +#ifdef _MSC_VER +#pragma optimize("g", off) +#endif Result write(const handle& handle, char* buffer, std::size_t size) { co_return co_await awaiter::write{ .file = handle.value(), .bufs = {uv_buf_init(buffer, size)}, }; } +#ifdef _MSC_VER +#pragma optimize("g", on) +#endif Result write(std::string path, char* buffer, std::size_t size, Mode mode) { auto file = co_await open(path, mode); diff --git a/xmake.lua b/xmake.lua index 530dc07f..4be6171d 100644 --- a/xmake.lua +++ b/xmake.lua @@ -159,8 +159,14 @@ rule("clice_build_config") on_load(function (target) target:add("cxflags", "-fno-rtti", {tools = {"clang", "gcc"}}) target:add("cxflags", "/GR-", {tools = {"clang_cl", "cl"}}) + -- Fix MSVC Non-standard preprocessor caused error C1189 + -- While compiling Command.cpp, MSVC won't expand Options macro correctly + -- Output: D:\Desktop\code\clice\build\.packages\l\llvm\20.1.5\cc2aa9f1d09a4b71b6fa3bf0011f6387\include\clang/Driver/Options.inc(3590): error C2365: “clang::driver::options::OPT_”: redefinition; previous definition was 'enumerator' + target:add("cxflags", "/Zc:preprocessor", {tools = {"cl"}}) + target:set("exceptions", "no-cxx") - if target:is_plat("windows") then + + if target:is_plat("windows") and not target:toolchain("msvc") then target:set("toolset", "ar", "llvm-ar") if target:toolchain("clang-cl") then target:set("toolset", "ld", "lld-link")