meson: improve -ffinite-math-only option detection and silence warning when build with -Ofast (#37638)

This commit is contained in:
Mike Yuan
2025-05-28 22:42:39 +02:00
committed by GitHub
+12 -3
View File
@@ -442,8 +442,16 @@ possible_common_link_flags = [
c_args = get_option('c_args')
# Our json library does not support -ffinite-math-only, which is enabled by -Ofast or -ffast-math.
if (('-Ofast' in c_args or '-ffast-math' in c_args or '-ffinite-math-only' in c_args) and '-fno-finite-math-only' not in c_args)
error('-Ofast, -ffast-math, or -ffinite-math-only is specified in c_args.')
have = false
foreach arg : c_args
if arg in ['-ffinite-math-only', '-ffast-math', '-Ofast']
have = true
elif arg in ['-fno-finite-math-only', '-fno-fast-math']
have = false
endif
endforeach
if have
error('-ffinite-math-only is enabled (may be implied by -ffast-math or -Ofast) in c_args.')
endif
# Disable -Wmaybe-uninitialized when compiling with -Os/-O1/-O3/etc. There are
@@ -455,7 +463,8 @@ if cc.get_id() == 'gcc' and (not '02'.contains(get_option('optimization')) or
'-Os' in c_args or
'-O1' in c_args or
'-O3' in c_args or
'-Og' in c_args)
'-Og' in c_args or
'-Ofast' in c_args)
possible_common_cc_flags += '-Wno-maybe-uninitialized'
endif