From 749d449e2ff77f43771467b986aa203546f3a808 Mon Sep 17 00:00:00 2001 From: DownerCase Date: Fri, 20 Jun 2025 18:11:48 +0100 Subject: fix: Do not add -fsanitize flags to msvc linker msvc's link.exe does not have an `fsanitize` flag. It was not causing build failures by was creating warning messages like: LINK : warning LNK4044: unrecognized option '/fsanitize=address'; ignored --- xmake/core/package/package.lua | 3 ++- xmake/rules/c++/build_sanitizer/config.lua | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index df2be796c..9a1835950 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2431,7 +2431,8 @@ function _instance:_generate_sanitizer_configs(checkmode, sourcekind) end -- add ldflags and shflags - if self:has_tool("ld", "link", "clang", "clangxx", "gcc", "gxx") then + -- msvc does not have an fsanitize linker flag, so the 'link' tool is excluded + if self:has_tool("ld", "clang", "clangxx", "gcc", "gxx") then configs.ldflags = "-fsanitize=" .. checkmode configs.shflags = "-fsanitize=" .. checkmode end diff --git a/xmake/rules/c++/build_sanitizer/config.lua b/xmake/rules/c++/build_sanitizer/config.lua index b2480eb73..1a82090fe 100644 --- a/xmake/rules/c++/build_sanitizer/config.lua +++ b/xmake/rules/c++/build_sanitizer/config.lua @@ -41,7 +41,8 @@ function _add_build_sanitizer(target, sourcekind, checkmode) end -- add ldflags and shflags - if target:has_tool("ld", "link", "clang", "clangxx", "gcc", "gxx") then + -- msvc does not have an fsanitize linker flag, so the 'link' tool is excluded + if target:has_tool("ld", "clang", "clangxx", "gcc", "gxx") then target:add("ldflags", "-fsanitize=" .. checkmode, {force = true}) target:add("shflags", "-fsanitize=" .. checkmode, {force = true}) end -- cgit v1.3.1