Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions cmake/common/compiler/options.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Applies the shared compiler defaults to <target> at <visibility>.
#
# Flag categories handled here:
# - Diagnostics (-W...): always on, every config
# - Language semantics (-fwrapv, -fstrict-aliasing, -fno-rtti on GCC): always on
# - Optimization-related (loop unrolling, vectorization, fast-math relaxations):
# gated to non-Debug configs because they have no effect at -O0 but still
# cost Clang/GCC pipeline time
#
# Do not add optimization-only flags here without a generator-expression gate
function(sourcemeta_add_default_options visibility target)
if(SOURCEMETA_COMPILER_MSVC)
# See https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category
Expand Down Expand Up @@ -40,22 +50,28 @@ function(sourcemeta_add_default_options visibility target)
$<$<OR:$<COMPILE_LANGUAGE:CXX>,$<COMPILE_LANGUAGE:OBJCXX>>:-Wnon-virtual-dtor>
$<$<OR:$<COMPILE_LANGUAGE:CXX>,$<COMPILE_LANGUAGE:OBJCXX>>:-Woverloaded-virtual>
$<$<OR:$<COMPILE_LANGUAGE:CXX>,$<COMPILE_LANGUAGE:OBJCXX>>:-Winvalid-offsetof>
-funroll-loops
# Semantics, not optimization: keep on for every config
-fstrict-aliasing
-ftree-vectorize

# To improve how much GCC/Clang will vectorize
# Assume that signed arithmetic overflow of addition, subtraction and
# multiplication wraps around using twos-complement representation
# See https://users.cs.utah.edu/~regehr/papers/overflow12.pdf
# See https://www.postgresql.org/message-id/1689.1134422394@sss.pgh.pa.us
-fwrapv
# Fast-math relaxations relax IEEE conformance (errno after math.h,
# signed-zero handling, reassociation), so they affect observable
# behavior and must apply to every config to keep Debug and Release
# semantics aligned
-fno-math-errno
-fno-trapping-math
-fno-signed-zeros
-freciprocal-math
-fassociative-math

# Assume that signed arithmetic overflow of addition, subtraction and
# multiplication wraps around using twos-complement representation
# See https://users.cs.utah.edu/~regehr/papers/overflow12.pdf
# See https://www.postgresql.org/message-id/1689.1134422394@sss.pgh.pa.us
-fwrapv)
# Optimization-only: emitted only when not building Debug. At -O0 these
# run analyses that never reach codegen, costing build time for no
# behavioral effect
$<$<NOT:$<CONFIG:Debug>>:-funroll-loops>
Copy link
Copy Markdown

@augmentcode augmentcode Bot May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$<$<NOT:$<CONFIG:Debug>>:...> will also enable these flags when the build configuration is empty/unspecified (e.g., single-config generators if CMAKE_BUILD_TYPE isn’t set), which may defeat the intent of avoiding extra work at -O0. Consider explicitly handling the empty-config case or documenting that a build type must be set for this gating to behave as expected.

Severity: medium

Other Locations
  • cmake/common/compiler/options.cmake:65
  • cmake/common/compiler/options.cmake:68
  • cmake/common/compiler/options.cmake:69
  • cmake/common/compiler/options.cmake:70
  • cmake/common/compiler/options.cmake:71
  • cmake/common/compiler/options.cmake:72
  • cmake/common/compiler/options.cmake:98
  • cmake/common/compiler/options.cmake:100

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

$<$<NOT:$<CONFIG:Debug>>:-ftree-vectorize>)
endif()

if(SOURCEMETA_COMPILER_LLVM)
Expand All @@ -81,9 +97,9 @@ function(sourcemeta_add_default_options visibility target)
-Wrange-loop-analysis

# Enable loop vectorization for performance reasons
-fvectorize
$<$<NOT:$<CONFIG:Debug>>:-fvectorize>
# Enable vectorization of straight-line code for performance
-fslp-vectorize)
$<$<NOT:$<CONFIG:Debug>>:-fslp-vectorize>)
elseif(SOURCEMETA_COMPILER_GCC)
target_compile_options("${target}" ${visibility}
# Newer versions of GCC (i.e. 14) seem to print a lot of false-positives here
Expand Down
Loading