Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ab41eef

Browse files
committedSep 16, 2021
[NewPM] Use a separate struct for ModuleMemorySanitizerPass
Split MemorySanitizerPass into MemorySanitizerPass (as a function pass) and ModuleMemorySanitizerPass (as a module pass). Main reason is to make sure that we have a unique mapping from ClassName to PassName in the new passmanager framework, making it possible to correctly identify the passes when dealing with options such as -print-after and -print-pipeline-passes. This is a follow-up to D105006 and D105007.
1 parent 05ea321 commit ab41eef

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed
 

‎clang/lib/CodeGen/BackendUtil.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ static void addSanitizers(const Triple &TargetTriple,
11191119
bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
11201120

11211121
MPM.addPass(
1122-
MemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
1122+
ModuleMemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
11231123
FunctionPassManager FPM;
11241124
FPM.addPass(
11251125
MemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));

‎llvm/include/llvm/Transforms/Instrumentation/MemorySanitizer.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,26 @@ struct MemorySanitizerPass : public PassInfoMixin<MemorySanitizerPass> {
4040
MemorySanitizerPass(MemorySanitizerOptions Options) : Options(Options) {}
4141

4242
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
43-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
4443
void printPipeline(raw_ostream &OS,
4544
function_ref<StringRef(StringRef)> MapClassName2PassName);
4645
static bool isRequired() { return true; }
4746

47+
private:
48+
MemorySanitizerOptions Options;
49+
};
50+
51+
/// A module pass for msan instrumentation.
52+
///
53+
/// Instruments functions to detect unitialized reads. This function pass
54+
/// inserts calls to runtime library functions. If the functions aren't declared
55+
/// yet, the pass inserts the declarations. Otherwise the existing globals are
56+
/// used.
57+
struct ModuleMemorySanitizerPass : public PassInfoMixin<ModuleMemorySanitizerPass> {
58+
ModuleMemorySanitizerPass(MemorySanitizerOptions Options) : Options(Options) {}
59+
60+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
61+
static bool isRequired() { return true; }
62+
4863
private:
4964
MemorySanitizerOptions Options;
5065
};

‎llvm/lib/Passes/PassRegistry.def

+1-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ MODULE_PASS("verify", VerifierPass())
110110
MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass())
111111
MODULE_PASS("dfsan", DataFlowSanitizerPass())
112112
MODULE_PASS("asan-module", ModuleAddressSanitizerPass(/*CompileKernel=*/false, false, true, false))
113-
MODULE_PASS("msan-module", MemorySanitizerPass({}))
113+
MODULE_PASS("msan-module", ModuleMemorySanitizerPass({}))
114114
MODULE_PASS("tsan-module", ThreadSanitizerPass())
115115
MODULE_PASS("kasan-module", ModuleAddressSanitizerPass(/*CompileKernel=*/true, false, true, false))
116116
MODULE_PASS("sancov-module", ModuleSanitizerCoveragePass())
@@ -335,7 +335,6 @@ FUNCTION_PASS("verify<scalar-evolution>", ScalarEvolutionVerifierPass())
335335
FUNCTION_PASS("view-cfg", CFGViewerPass())
336336
FUNCTION_PASS("view-cfg-only", CFGOnlyViewerPass())
337337
FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
338-
FUNCTION_PASS("msan", MemorySanitizerPass({}))
339338
FUNCTION_PASS("tsan", ThreadSanitizerPass())
340339
FUNCTION_PASS("memprof", MemProfilerPass())
341340
#undef FUNCTION_PASS

‎llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,8 @@ PreservedAnalyses MemorySanitizerPass::run(Function &F,
673673
return PreservedAnalyses::all();
674674
}
675675

676-
PreservedAnalyses MemorySanitizerPass::run(Module &M,
677-
ModuleAnalysisManager &AM) {
676+
PreservedAnalyses
677+
ModuleMemorySanitizerPass::run(Module &M, ModuleAnalysisManager &AM) {
678678
if (Options.Kernel)
679679
return PreservedAnalyses::all();
680680
insertModuleCtor(M);

‎llvm/test/Other/new-pm-print-pipeline.ll

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@
4040
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(early-cse<>,early-cse<memssa>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-12
4141
; CHECK-12: function(early-cse<>,early-cse<memssa>)
4242

43-
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(msan<>,msan<recover;kernel;track-origins=5>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-13
44-
;;; XXX: msan-module? this is one of the places where the ClassName to pass-name mapping fails.
45-
; CHECK-13: function(msan-module<track-origins=0>,msan-module<recover;kernel;track-origins=5>)
43+
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='msan-module,function(msan,msan<>,msan<recover;kernel;track-origins=5>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-13
44+
; CHECK-13: msan-module,function(msan<track-origins=0>,msan<track-origins=0>,msan<recover;kernel;track-origins=5>)
4645

4746
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='module(hwasan<>,hwasan<kernel;recover>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-14
4847
; CHECK-14: hwasan<>,hwasan<kernel;recover>

0 commit comments

Comments
 (0)
Please sign in to comment.