kda created this revision.
kda added a reviewer: vitalybuka.
Herald added subscribers: ormris, hiraditya.
kda requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits.
follow up to https://reviews.llvm.org/D116633
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D116634
Files:
clang/include/clang/Driver/SanitizerArgs.h
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/SanitizerArgs.cpp
compiler-rt/test/msan/noundef_analysis.cpp
llvm/include/llvm/Transforms/Instrumentation/MemorySanitizer.h
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -493,6 +493,9 @@
MemorySanitizer(Module &M, MemorySanitizerOptions Options)
: CompileKernel(Options.Kernel), TrackOrigins(Options.TrackOrigins),
Recover(Options.Recover) {
+ if (Options.EagerChecks) {
+ ClEagerChecks = Options.EagerChecks;
+ }
initializeModule(M);
}
@@ -665,10 +668,12 @@
} // end anonymous namespace
-MemorySanitizerOptions::MemorySanitizerOptions(int TO, bool R, bool K)
+MemorySanitizerOptions::MemorySanitizerOptions(int TO, bool R, bool K,
+ bool EagerChecks)
: Kernel(getOptOrDefault(ClEnableKmsan, K)),
TrackOrigins(getOptOrDefault(ClTrackOrigins, Kernel ? 2 : TO)),
- Recover(getOptOrDefault(ClKeepGoing, Kernel || R)) {}
+ Recover(getOptOrDefault(ClKeepGoing, Kernel || R)),
+ EagerChecks(ClEagerChecks || EagerChecks) {}
PreservedAnalyses MemorySanitizerPass::run(Function &F,
FunctionAnalysisManager &FAM) {
Index: llvm/include/llvm/Transforms/Instrumentation/MemorySanitizer.h
===================================================================
--- llvm/include/llvm/Transforms/Instrumentation/MemorySanitizer.h
+++ llvm/include/llvm/Transforms/Instrumentation/MemorySanitizer.h
@@ -19,11 +19,13 @@
namespace llvm {
struct MemorySanitizerOptions {
- MemorySanitizerOptions() : MemorySanitizerOptions(0, false, false){};
- MemorySanitizerOptions(int TrackOrigins, bool Recover, bool Kernel);
+ MemorySanitizerOptions() : MemorySanitizerOptions(0, false, false, false){};
+ MemorySanitizerOptions(int TrackOrigins, bool Recover, bool Kernel,
+ bool EagerChecks);
bool Kernel;
int TrackOrigins;
bool Recover;
+ bool EagerChecks;
};
// Insert MemorySanitizer instrumentation (detection of uninitialized reads)
Index: compiler-rt/test/msan/noundef_analysis.cpp
===================================================================
--- compiler-rt/test/msan/noundef_analysis.cpp
+++ compiler-rt/test/msan/noundef_analysis.cpp
@@ -2,6 +2,8 @@
// RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
// RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan %s -fsanitize-memory-param-retval -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
struct SimpleStruct {
int md1;
Index: clang/lib/Driver/SanitizerArgs.cpp
===================================================================
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -637,6 +637,9 @@
}
}
}
+ MsanParamRetval = Args.hasFlag(
+ options::OPT_fsanitize_memory_param_retval,
+ options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
MsanUseAfterDtor =
Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
options::OPT_fno_sanitize_memory_use_after_dtor,
@@ -644,6 +647,7 @@
NeedPIE |= !(TC.getTriple().isOSLinux() &&
TC.getTriple().getArch() == llvm::Triple::x86_64);
} else {
+ MsanParamRetval = false;
MsanUseAfterDtor = false;
}
@@ -1093,6 +1097,9 @@
CmdArgs.push_back(Args.MakeArgString("-fsanitize-memory-track-origins=" +
Twine(MsanTrackOrigins)));
+ if (MsanParamRetval)
+ CmdArgs.push_back("-fsanitize-memory-param-retval");
+
if (MsanUseAfterDtor)
CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -357,8 +357,9 @@
const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts();
int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins;
bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Memory);
- PM.add(createMemorySanitizerLegacyPassPass(
- MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
+ bool EagerChecks = CGOpts.SanitizeMemoryParamRetval;
+ PM.add(createMemorySanitizerLegacyPassPass(MemorySanitizerOptions{
+ TrackOrigins, Recover, CompileKernel, EagerChecks}));
// MemorySanitizer inserts complex instrumentation that mostly follows
// the logic of the original code, but operates on "shadow" values.
@@ -1162,12 +1163,13 @@
if (LangOpts.Sanitize.has(Mask)) {
int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
+ bool EagerChecks = CodeGenOpts.SanitizeMemoryParamRetval;
- MPM.addPass(
- ModuleMemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+ MPM.addPass(ModuleMemorySanitizerPass(
+ {TrackOrigins, Recover, CompileKernel, EagerChecks}));
FunctionPassManager FPM;
- FPM.addPass(
- MemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+ FPM.addPass(MemorySanitizerPass(
+ {TrackOrigins, Recover, CompileKernel, EagerChecks}));
if (Level != OptimizationLevel::O0) {
// MemorySanitizer inserts complex instrumentation that mostly
// follows the logic of the original code, but operates on
Index: clang/include/clang/Driver/SanitizerArgs.h
===================================================================
--- clang/include/clang/Driver/SanitizerArgs.h
+++ clang/include/clang/Driver/SanitizerArgs.h
@@ -32,6 +32,7 @@
std::vector<std::string> CoverageIgnorelistFiles;
int CoverageFeatures = 0;
int MsanTrackOrigins = 0;
+ bool MsanParamRetval = false;
bool MsanUseAfterDtor = true;
bool CfiCrossDso = false;
bool CfiICallGeneralizePointers = false;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits