[PATCH] D116701: Respect -fsanitize-memory-param-retval flag.
Kevin Athey via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 12 08:48:55 PST 2022
kda updated this revision to Diff 399347.
kda added a comment.
Correcting diff.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116701/new/
https://reviews.llvm.org/D116701
Files:
clang/include/clang/Driver/SanitizerArgs.h
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/SanitizerArgs.cpp
compiler-rt/test/msan/noundef_analysis.cpp
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
@@ -641,10 +641,14 @@
Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
options::OPT_fno_sanitize_memory_use_after_dtor,
MsanUseAfterDtor);
+ MsanParamRetval = Args.hasFlag(
+ options::OPT_fsanitize_memory_param_retval,
+ options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
NeedPIE |= !(TC.getTriple().isOSLinux() &&
TC.getTriple().getArch() == llvm::Triple::x86_64);
} else {
MsanUseAfterDtor = false;
+ MsanParamRetval = false;
}
if (AllAddedKinds & SanitizerKind::Thread) {
@@ -1096,6 +1100,9 @@
if (MsanUseAfterDtor)
CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
+ if (MsanParamRetval)
+ CmdArgs.push_back("-fsanitize-memory-param-retval");
+
// FIXME: Pass these parameters as function attributes, not as -llvm flags.
if (!TsanMemoryAccess) {
CmdArgs.push_back("-mllvm");
Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -358,7 +358,8 @@
int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins;
bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Memory);
PM.add(createMemorySanitizerLegacyPassPass(
- MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
+ MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel,
+ CGOpts.SanitizeMemoryParamRetval != 0}));
// MemorySanitizer inserts complex instrumentation that mostly follows
// the logic of the original code, but operates on "shadow" values.
@@ -1163,11 +1164,11 @@
int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
- MPM.addPass(
- ModuleMemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+ MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
+ CodeGenOpts.SanitizeMemoryParamRetval);
+ MPM.addPass(ModuleMemorySanitizerPass(options));
FunctionPassManager FPM;
- FPM.addPass(
- MemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+ FPM.addPass(MemorySanitizerPass(options));
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
@@ -33,6 +33,7 @@
int CoverageFeatures = 0;
int MsanTrackOrigins = 0;
bool MsanUseAfterDtor = true;
+ bool MsanParamRetval = false;
bool CfiCrossDso = false;
bool CfiICallGeneralizePointers = false;
bool CfiCanonicalJumpTables = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116701.399347.patch
Type: text/x-patch
Size: 3792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220112/2483a9c7/attachment.bin>
More information about the cfe-commits
mailing list