[clang] [compiler-rt] [UBSan] Add -fsanitize=uninitialized-read check (ISO C 6.3.2.1p2) (PR #207529)
Thurston Dang via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 10 22:43:01 PDT 2026
thurstond wrote:
> Cost is one alloca + one store per write + one load/branch per read, for candidate scalars only. Given -fsanitize=undefined is supposed to stay cheap, wanted to check before implementing: fine as part of the Undefined group, or would you rather this sit behind its own flag?
The allocas would make this check unusual by UBSan standards, let alone `-fsanitize=undefined`: "UndefinedBehaviorSanitizer (UBSan) is a fast undefined behavior detector. ... The checks have small runtime cost and no impact on address space layout" (https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html)
----
The current implementation of this check is targeted towards ISO C23 6.3.2.1p2, which is not obvious from the check name (`-fsanitize=uninitialized-check`), and would potentially confuse users of other C or C++ dialects why the check doesn't work as expected. It would be better if the check implemented the semantics for the appropriate dialect per the `CGF.getLangOpts()`.
Users may also be confused by the difference between `-fsanitize=uninitialized-check` and `-fsanitize=memory` (arguably the former is a better description of what MemorySanitizer actually does).
Instead of an extra UBSan check, is it possible for the front-end to instead add appropriate annotations/attributes to make MemorySanitizer work correctly for this C23?
https://github.com/llvm/llvm-project/pull/207529
More information about the cfe-commits
mailing list