llvm.org GIT mirror llvm / 6307ec9
[msan, NFC] Move option parsing into constructor git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374480 91177308-0d34-0410-b5e6-96231b3b80d8 Vitaly Buka 1 year, 1 month ago
2 changed file(s) with 17 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
1818 namespace llvm {
1919
2020 struct MemorySanitizerOptions {
21 MemorySanitizerOptions() = default;
22 MemorySanitizerOptions(int TrackOrigins, bool Recover, bool Kernel)
23 : TrackOrigins(TrackOrigins), Recover(Recover), Kernel(Kernel) {}
24 int TrackOrigins = 0;
25 bool Recover = false;
26 bool Kernel = false;
21 MemorySanitizerOptions() : MemorySanitizerOptions(0, false, false){};
22 MemorySanitizerOptions(int TrackOrigins, bool Recover, bool Kernel);
23 bool Kernel;
24 int TrackOrigins;
25 bool Recover;
2726 };
2827
2928 // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
461461 /// the module.
462462 class MemorySanitizer {
463463 public:
464 MemorySanitizer(Module &M, MemorySanitizerOptions Options) {
465 this->CompileKernel =
466 ClEnableKmsan.getNumOccurrences() > 0 ? ClEnableKmsan : Options.Kernel;
467 if (ClTrackOrigins.getNumOccurrences() > 0)
468 this->TrackOrigins = ClTrackOrigins;
469 else
470 this->TrackOrigins = this->CompileKernel ? 2 : Options.TrackOrigins;
471 this->Recover = ClKeepGoing.getNumOccurrences() > 0
472 ? ClKeepGoing
473 : (this->CompileKernel | Options.Recover);
464 MemorySanitizer(Module &M, MemorySanitizerOptions Options)
465 : CompileKernel(Options.Kernel), TrackOrigins(Options.TrackOrigins),
466 Recover(Options.Recover) {
474467 initializeModule(M);
475468 }
476469
622615 MemorySanitizerOptions Options;
623616 };
624617
618 template T getOptOrDefault(const cl::opt &Opt, T Default) {
619 return (Opt.getNumOccurrences() > 0) ? Opt : Default;
620 }
621
625622 } // end anonymous namespace
623
624 MemorySanitizerOptions::MemorySanitizerOptions(int TO, bool R, bool K)
625 : Kernel(getOptOrDefault(ClEnableKmsan, K)),
626 TrackOrigins(getOptOrDefault(ClTrackOrigins, Kernel ? 2 : TO)),
627 Recover(getOptOrDefault(ClKeepGoing, Kernel || R)) {}
626628
627629 PreservedAnalyses MemorySanitizerPass::run(Function &F,
628630 FunctionAnalysisManager &FAM) {