summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-22 19:39:18 +0800
committerGitHub <[email protected]>2025-12-22 19:39:18 +0800
commitc3733aac1f1eb0a958446b0fcdd6c33861ce48f3 (patch)
tree490f10a33aeb281903d37eef8e14e4542603d015
parent78c5465cdbc234d7d7be3bfc76b6304767aefa44 (diff)
Refactor sanitizer flag addition in sanitizer.lua
Refactor the _add_build_sanitizer function to streamline the addition of sanitizer flags and remove redundant code for adding cflags and ldflags.
-rw-r--r--xmake/rules/c++/config/sanitizer.lua30
1 files changed, 4 insertions, 26 deletions
diff --git a/xmake/rules/c++/config/sanitizer.lua b/xmake/rules/c++/config/sanitizer.lua
index 3293a6808..79c88661a 100644
--- a/xmake/rules/c++/config/sanitizer.lua
+++ b/xmake/rules/c++/config/sanitizer.lua
@@ -26,32 +26,10 @@ import("private.utils.toolchain", {alias = "toolchain_utils"})
-- add build sanitizer
function _add_build_sanitizer(target, sourcekind, checkmode)
- -- add cflags
- local _, cc = target:tool(sourcekind)
- local flagnames = {
- cc = "cflags",
- cxx = "cxxflags",
- mm = "mflags",
- mxx = "mxflags"
- }
- local flagname = flagnames[sourcekind]
- if flagname and target:has_tool(sourcekind, "cl", "clang", "clangxx", "clang_cl", "gcc", "gxx") then
- target:add(flagname, "-fsanitize=" .. checkmode, {force = true})
- end
-
- -- add ldflags and shflags
- -- 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
-
- if target:is_plat("windows") and checkmode == "address" and not target:has_tool("cxx", "cl") then
- local ldflags = toolchain_utils.get_llvm_asan_flags(target)
- if #ldflags ~= 0 then
- target:add("ldflags", ldflags, {force = true})
- target:add("shflags", ldflags, {force = true})
- end
+ -- add sanitizer flags
+ local flags = toolchain_utils.get_sanitizer_flags(target, {checkmode = checkmode, sourcekind = sourcekind})
+ for name, value in pairs(flags) do
+ target:add(name, value, {force = true})
end
end