[llvm-branch-commits] [clang] [clang][msan] Support -fsanitize-merge=memory to merge warning blocks (PR #238870)
Vitaly Buka via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 4 08:56:53 PST 2026
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/238870
Wire `CodeGenOpts.SanitizeMergeHandlers.has(Mask)` to
`MemorySanitizerOptions::MergeChecks` when scheduling
`MemorySanitizerPass`.
This reduces `.text` size by ~0.5% on `clang` and up to 4.8% on large
binaries with exceptions enabled.
Related to https://github.com/rust-lang/rust/issues/165040 (reducing
MSan binary size to offset the size overhead of fixing that issue).
Assisted-by: Gemini
>From b3d84c06d6e6bc2d353c1b2486107472ad3814d5 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 4 Nov 2026 08:56:40 -0800
Subject: [PATCH] [spr] update
Created using spr 2.0.0-beta.2
---
clang/lib/CodeGen/BackendUtil.cpp | 6 ++++--
clang/test/CodeGen/sanitize-memory-merge.c | 1 -
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index e04934548176f8..9e8d44e24ce432 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -680,8 +680,10 @@ static void addSanitizers(const Triple &TargetTriple,
int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
- MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
- CodeGenOpts.SanitizeMemoryParamRetval);
+ MemorySanitizerOptions options(
+ TrackOrigins, Recover, CompileKernel,
+ CodeGenOpts.SanitizeMemoryParamRetval,
+ CodeGenOpts.SanitizeMergeHandlers.has(Mask));
MPM.addPass(MemorySanitizerPass(options));
if (Level != OptimizationLevel::O0) {
// MemorySanitizer inserts complex instrumentation that mostly follows
diff --git a/clang/test/CodeGen/sanitize-memory-merge.c b/clang/test/CodeGen/sanitize-memory-merge.c
index c3f33aaeea66bc..4d5e2a88ea681b 100644
--- a/clang/test/CodeGen/sanitize-memory-merge.c
+++ b/clang/test/CodeGen/sanitize-memory-merge.c
@@ -10,7 +10,6 @@
// MERGE-LABEL: define dso_local noundef range(i32 0, 3) i32 @two_checks(
// MERGE-SAME: ptr nofree noundef readonly captures(none) [[P:%.*]], ptr nofree noundef readonly captures(none) [[Q:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
// MERGE: call void @__msan_warning_noreturn() #[[ATTR2:[0-9]+]]
-// MERGE: call void @__msan_warning_noreturn() #[[ATTR2]]
//
int two_checks(int *p, int *q) {
if (*p)
More information about the llvm-branch-commits
mailing list