Make UBSan findings fatal in sanitized builds#1676
Merged
bghgary merged 3 commits intoBabylonJS:masterfrom Apr 25, 2026
Merged
Conversation
This was referenced Apr 24, 2026
Fix UBSan undefined-behavior hits in bgfx_p.h (cherry-pick of bkaradzic/bgfx#3688)
BabylonJS/bgfx#60
Merged
UBSan is recoverable by default: diagnostics are printed to stderr but execution continues, so CI stays green while latent UB goes unreported. Add -fno-sanitize-recover=all to the Clang sanitizer options, and set UBSAN_OPTIONS=halt_on_error=1 as a runtime belt-and-suspenders on the macOS and Linux sanitized workflows. (MSVC only supports ASan, which already aborts on error.) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Now that BabylonJS/glslang#5 (Suppress UBSan enum check on SPIR-V mask bit-combining operators) has merged, point FetchContent at the merged-on-main SHA instead of the bghgary fork branch used for testing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Picks up the cherry-pick of bkaradzic/bgfx#3688 (default-init the SortKey ints/bools so we don't load undefined values into bitfields) via BabylonJS/bgfx.cmake#115, which bumps the bgfx submodule to BabylonJS/bgfx@7e4749e6 on update-bgfx. This is the canonical merged SHA on master; it replaces the temporary bghgary/bgfx.cmake validation pin used while bkaradzic/bgfx#3688 was in review. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ae66199 to
b814753
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the sanitized build configuration so UndefinedBehaviorSanitizer (UBSan) findings fail CI instead of only emitting stderr diagnostics, and refreshes pinned third-party dependencies to versions that eliminate current UBSan hits.
Changes:
- Make UBSan non-recoverable in sanitized builds by adding
-fno-sanitize-recover=allto Clang/GNU sanitizer compile flags in CMake. - Set
UBSAN_OPTIONSandASAN_OPTIONSin macOS/Linux GitHub Actions workflows to halt/abort on sanitizer errors and improve diagnostics. - Bump the pinned SHAs for
bgfx.cmakeandglslangto versions that address known UBSan findings.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
CMakeLists.txt |
Updates dependency pins and ensures UBSan findings are fatal when ENABLE_SANITIZERS=ON. |
.github/workflows/build-macos.yml |
Adds runtime sanitizer env options to make UBSan/ASan errors fail the job with better stack traces. |
.github/workflows/build-linux.yml |
Adds runtime sanitizer env options to make UBSan/ASan errors fail the job with better stack traces. |
bkaradzic-microsoft
approved these changes
Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Our sanitized macOS/Linux jobs enable
-fsanitize=address,undefined[,vptr], so the UB checks are active — but UBSan is recoverable by default. On a hit it prints a diagnostic to stderr and keeps running. The process doesn't abort, the test doesn't fail, CI stays green, and the diagnostic is buried in test output nobody reads.Adding
-fno-sanitize-recover=allis what converts each UBSan hit into aSIGABRT→ test failure. We were missing it.Change
Three commits:
-fno-sanitize-recover=allto the Clang sanitizeradd_compile_optionsline inCMakeLists.txt, and setUBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1:symbolize=1andASAN_OPTIONS=abort_on_error=1inbuild-macos.yml/build-linux.ymlas runtime belt-and-suspenders. (MSVC only supports ASan, which already aborts on error.)The dependency bumps in commits 2 and 3 fix every UBSan finding currently being printed (and ignored) by the sanitized jobs on
master, so this PR should be green on first run.Out of scope
nilas well-defined in Obj-C, but C++ UBSan doesn't know that. Not hit on the current pin; if a future metal-cpp bump trips it, the standard fix is a scoped-fno-sanitize=nullon metal-cpp only.-fsanitize=nullability(Apple_Nonnullattribute checks, separate fromnull) — worth considering as a follow-up once this lands and the baseline is clean.[Created by Copilot on behalf of @bghgary]