1616## MINIDXNN_ARCH_FEATURE_LEVEL: CPU architecture level (Amd64V1/V2/V3/V4)
1717function (setCxxCompileFlags target scope )
1818 # Detect compiler type using generator expressions
19- set (has_msvc $<OR :$< C_COMPILER_ID : MSVC >,$< CXX_COMPILER_ID :MSVC > >)
20- set (has_gcc $<OR :$< C_COMPILER_ID : GNU >,$< CXX_COMPILER_ID :GNU > >)
21- set (has_clang $<OR :$< C_COMPILER_ID : Clang >,$< CXX_COMPILER_ID :Clang >,$< C_COMPILER_ID : AppleClang >,$< CXX_COMPILER_ID : AppleClang > >)
22- set (has_apple_clang $<OR :$<C_COMPILER_ID : AppleClang >,$< CXX_COMPILER_ID : AppleClang > >)
19+ set (has_msvc $<CXX_COMPILER_ID :MSVC >)
20+ set (has_gcc $<CXX_COMPILER_ID :GNU >)
21+ set (has_apple_clang $<CXX_COMPILER_ID :AppleClang >)
22+ set (has_clang $<OR :$<CXX_COMPILER_ID : Clang >,${has_apple_clang} >)
2323
2424 # Check if using MSVC frontend (e.g., clang-cl)
2525 set (has_msvc_frontend 0)
@@ -132,14 +132,29 @@ function(setCxxWarningFlags target scope)
132132 # Check if extra warnings are enabled
133133 set(has_extra $<BOOL :${MINIDXNN_WARNING_EXTRA} >)
134134
135- # Detect compiler type
136- set(has_msvc $<OR :$<C_COMPILER_ID :MSVC >,$<CXX_COMPILER_ID :MSVC >>)
137- set(has_gcc $<OR :$<C_COMPILER_ID :GNU >,$<CXX_COMPILER_ID :GNU >>)
138- set(has_clang $<OR :$<C_COMPILER_ID :Clang >,$<CXX_COMPILER_ID :Clang >,$<C_COMPILER_ID :AppleClang >,$<CXX_COMPILER_ID :AppleClang >>)
135+ # Detect compiler type using generator expressions
136+ set(has_msvc $<CXX_COMPILER_ID :MSVC >)
137+ set(has_gcc $<CXX_COMPILER_ID :GNU >)
138+ set(has_apple_clang $<CXX_COMPILER_ID :AppleClang >)
139+ set(has_clang $<OR :$<CXX_COMPILER_ID :Clang >,${has_apple_clang} >)
139140
140141 # MSVC warning levels
141- set(msvc_options /W4) # Warning level 4 (high but reasonable)
142- set(msvc_options_extra /Wall) # All warnings (may be noisy)
142+ set(msvc_options /W4 /wd4244) # Warning level 4 (high but reasonable)
143+ set(msvc_options_extra /Wall
144+ /wd4514 # unreferenced inline function removed (informational)
145+ /wd4625 # copy constructor implicitly deleted (GoogleTest)
146+ /wd4626 # copy assignment implicitly deleted (GoogleTest)
147+ /wd4710 # function not inlined (compiler decision, informational)
148+ /wd4711 # function selected for automatic inline expansion (informational)
149+ /wd4820 # struct padding added (informational)
150+ /wd4866 # left-to-right evaluation order (third-party)
151+ /wd4868 # left-to-right evaluation order in braced init (third-party)
152+ /wd5026 # move constructor implicitly deleted (GoogleTest)
153+ /wd5027 # move assignment implicitly deleted (GoogleTest)
154+ /wd5045 # Spectre mitigation insertion (informational)
155+ /wd4324 # structure padded due to alignment specifier
156+ /wd5264 # 'const' variable is not used (used only with GFX)
157+ ) # All warnings with noise suppressions
143158
144159 # GCC warning options
145160 set(gcc_options -Wall
@@ -174,11 +189,35 @@ function(setCxxWarningFlags target scope)
174189 if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL " MSVC ")
175190 # Clang-CL (MSVC-compatible frontend)
176191 set(clang_options /W4)
177- set(clang_options_extra /Wall -Wno-c++-compat -Wno-c++98-compat -Wno-c++98-compat-pedantic)
192+ set(clang_options_extra /Wall -Wno-c++-compat -Wno-c++98-compat -Wno-c++98-compat-pedantic
193+ -Wno-padded # Struct padding is intentional
194+ -Wno-covered-switch-default # All enum values handled; default added for safety
195+ -Wno-global-constructors # Google Test macros require global constructors
196+ -Wno-unsafe-buffer-usage # Clang hardening opt-in; valid pointer usage
197+ -Wno-unsafe-buffer-usage-in-libc-call
198+ -Wno-unsafe-buffer-usage-in-container
199+ -Wno-weak-vtables # vtable placement hint, not a bug
200+ -Wno-ctad-maybe-unsupported # CTAD is intentional C++17/20 usage
201+ -Wno-missing-prototypes # C-only concept, not meaningful for C++
202+ -Wno-unused-template # Templates in headers may not be used in every TU
203+ -Wno-undefined-func-template # Template instantiation across TUs is by design
204+ )
178205 elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL " GNU")
179206 # Clang with GNU-compatible frontend
180207 set(clang_options -Wall -Wextra -pedantic)
181- set(clang_options_extra -Weverything -Wno-c++-compat -Wno-c++98-compat -Wno-c++98-compat-pedantic)
208+ set(clang_options_extra -Weverything -Wno-c++-compat -Wno-c++98-compat -Wno-c++98-compat-pedantic
209+ -Wno-padded # Struct padding is intentional
210+ -Wno-covered-switch-default # All enum values handled; default added for -Wswitch-default
211+ -Wno-global-constructors # Google Test macros require global constructors
212+ -Wno-unsafe-buffer-usage # Clang hardening opt-in; valid pointer usage
213+ -Wno-unsafe-buffer-usage-in-libc-call
214+ -Wno-unsafe-buffer-usage-in-container
215+ -Wno-weak-vtables # vtable placement hint, not a bug
216+ -Wno-ctad-maybe-unsupported # CTAD is intentional C++17/20 usage
217+ -Wno-missing-prototypes # C-only concept, not meaningful for C++
218+ -Wno-unused-template # Templates in headers may not be used in every TU
219+ -Wno-undefined-func-template # Template instantiation across TUs is by design
220+ )
182221 endif()
183222
184223 # Apply warning flags to target
@@ -201,33 +240,38 @@ endfunction(setCxxWarningFlags)
201240function(setSanitizerFlags target scope)
202241 # Check which sanitizers are enabled via cache options
203242 set(has_address $<BOOL :${MINIDXNN_ENABLE_SANITIZER_ADDRESS} >)
243+ set(has_undef $<BOOL :${MINIDXNN_ENABLE_SANITIZER_UNDEF_BEHAVIOR} >)
204244 #set(has_thread $<BOOL :${MINIDXNN_ENABLE_SANITIZER_THREAD} >)
205245 #set(has_memory $<BOOL :${MINIDXNN_ENABLE_SANITIZER_MEMORY} >)
206- #set(has_undef $<BOOL :${MINIDXNN_ENABLE_SANITIZER_UNDEF_BEHAVIOR} >)
207- #set(has_leak $<BOOL :${MINIDXNN_ENABLE_SANITIZER_LEAK} >)
208- #set(has_cfi $<BOOL :${MINIDXNN_ENABLE_SANITIZER_CFI} >)
209246 #set(has_safe_stack $<BOOL :${MINIDXNN_ENABLE_SANITIZER_SAFE_STACK} >)
210247
248+ # Detect compiler type using generator expressions
249+ set(has_msvc $<CXX_COMPILER_ID :MSVC >)
250+ set(has_gcc $<CXX_COMPILER_ID :GNU >)
251+ set(has_apple_clang $<CXX_COMPILER_ID :AppleClang >)
252+ set(has_clang $<OR :$<CXX_COMPILER_ID :Clang >,${has_apple_clang} >)
253+
254+ # UBSan: GCC supports a subset; Clang supports additional checks
255+ set(ubsan_gcc -fsanitize=undefined,float-divide-by-zero)
256+ set(ubsan_clang -fsanitize=undefined,float-divide-by-zero,unsigned-integer-overflow,implicit-conversion,local-bounds,nullability)
257+
211258 # Apply sanitizer compile options
212- # TODO: Support other sanitizers
213259 target_compile_options(${target} ${scope}
214260 $<${has_address} :-fsanitize =address ;-fno -omit -frame -pointer >
261+ $<${has_undef} :$<${has_gcc} :${ubsan_gcc} >
262+ $<${has_clang} :${ubsan_clang} >>
215263 #$<${has_thread} :-fsanitize =thread >
216264 #$<${has_memory} :-fsanitize =memory ;-fno -omit -frame -pointer >
217- #$<${has_undef} :-fsanitize =undefined ,float -divide -by -zero ,unsigned -integer -overflow ,implicit -conversion ,local -bounds ,nullability >
218- #$<${has_leak} :-fsanitize =leak >
219- #$<${has_cfi} :-fsanitize =cfi >
220265 #$<${has_safe_stack} :-fsanitize =safe -stack >
221266 )
222267
223268 # Apply sanitizer link options (must match compile options)
224269 target_link_options(${target} ${scope}
225270 $<${has_address} :-fsanitize =address >
271+ $<${has_undef} :$<${has_gcc} :${ubsan_gcc} >
272+ $<${has_clang} :${ubsan_clang} >>
226273 #$<${has_thread} :-fsanitize =thread >
227274 #$<${has_memory} :-fsanitize =memory >
228- #$<${has_undef} :-fsanitize =undefined ,float -divide -by -zero ,unsigned -integer -overflow ,implicit -conversion ,local -bounds ,nullability >
229- #$<${has_leak} :-fsanitize =leak >
230- #$<${has_cfi} :-fsanitize =cfi >
231275 #$<${has_safe_stack} :-fsanitize =safe -stack >
232276 )
233277endfunction(setSanitizerFlags)
0 commit comments