diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Driver/SanitizerArgs.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Driver/SanitizerArgs.cpp | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/contrib/llvm/tools/clang/lib/Driver/SanitizerArgs.cpp b/contrib/llvm/tools/clang/lib/Driver/SanitizerArgs.cpp index 30cc3f4..f4f6dad 100644 --- a/contrib/llvm/tools/clang/lib/Driver/SanitizerArgs.cpp +++ b/contrib/llvm/tools/clang/lib/Driver/SanitizerArgs.cpp @@ -49,8 +49,11 @@ enum CoverageFeature { CoverageIndirCall = 1 << 3, CoverageTraceBB = 1 << 4, CoverageTraceCmp = 1 << 5, - Coverage8bitCounters = 1 << 6, - CoverageTracePC = 1 << 7, + CoverageTraceDiv = 1 << 6, + CoverageTraceGep = 1 << 7, + Coverage8bitCounters = 1 << 8, + CoverageTracePC = 1 << 9, + CoverageTracePCGuard = 1 << 10, }; /// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any @@ -162,7 +165,8 @@ bool SanitizerArgs::needsUbsanRt() const { return ((Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) || CoverageFeatures) && !Sanitizers.has(Address) && !Sanitizers.has(Memory) && - !Sanitizers.has(Thread) && !Sanitizers.has(DataFlow) && !CfiCrossDso; + !Sanitizers.has(Thread) && !Sanitizers.has(DataFlow) && + !Sanitizers.has(Leak) && !CfiCrossDso; } bool SanitizerArgs::needsCfiRt() const { @@ -434,6 +438,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, TC.getTriple().getArch() == llvm::Triple::x86_64); } + if (AllAddedKinds & Thread) { + TsanMemoryAccess = Args.hasFlag(options::OPT_fsanitize_thread_memory_access, + options::OPT_fno_sanitize_thread_memory_access, + TsanMemoryAccess); + TsanFuncEntryExit = Args.hasFlag(options::OPT_fsanitize_thread_func_entry_exit, + options::OPT_fno_sanitize_thread_func_entry_exit, + TsanFuncEntryExit); + TsanAtomics = Args.hasFlag(options::OPT_fsanitize_thread_atomics, + options::OPT_fno_sanitize_thread_atomics, + TsanAtomics); + } + if (AllAddedKinds & CFI) { CfiCrossDso = Args.hasFlag(options::OPT_fsanitize_cfi_cross_dso, options::OPT_fno_sanitize_cfi_cross_dso, false); @@ -524,7 +540,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, << "-fsanitize-coverage=8bit-counters" << "-fsanitize-coverage=(func|bb|edge)"; // trace-pc w/o func/bb/edge implies edge. - if ((CoverageFeatures & CoverageTracePC) && + if ((CoverageFeatures & (CoverageTracePC | CoverageTracePCGuard)) && !(CoverageFeatures & CoverageTypes)) CoverageFeatures |= CoverageEdge; @@ -556,14 +572,13 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, D.Diag(clang::diag::note_drv_address_sanitizer_debug_runtime); } } - } - AsanUseAfterScope = - Args.hasArg(options::OPT_fsanitize_address_use_after_scope); - if (AsanUseAfterScope && !(AllAddedKinds & Address)) { - D.Diag(clang::diag::err_drv_argument_only_allowed_with) - << "-fsanitize-address-use-after-scope" - << "-fsanitize=address"; + if (Arg *A = Args.getLastArg( + options::OPT_fsanitize_address_use_after_scope, + options::OPT_fno_sanitize_address_use_after_scope)) { + AsanUseAfterScope = A->getOption().getID() == + options::OPT_fsanitize_address_use_after_scope; + } } // Parse -link-cxx-sanitizer flag. @@ -605,6 +620,12 @@ static void addIncludeLinkerOption(const ToolChain &TC, void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const { + // NVPTX doesn't currently support sanitizers. Bailing out here means that + // e.g. -fsanitize=address applies only to host code, which is what we want + // for now. + if (TC.getTriple().isNVPTX()) + return; + // Translate available CoverageFeatures to corresponding clang-cc1 flags. // Do it even if Sanitizers.empty() since some forms of coverage don't require // sanitizers. @@ -615,8 +636,11 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, std::make_pair(CoverageIndirCall, "-fsanitize-coverage-indirect-calls"), std::make_pair(CoverageTraceBB, "-fsanitize-coverage-trace-bb"), std::make_pair(CoverageTraceCmp, "-fsanitize-coverage-trace-cmp"), + std::make_pair(CoverageTraceDiv, "-fsanitize-coverage-trace-div"), + std::make_pair(CoverageTraceGep, "-fsanitize-coverage-trace-gep"), std::make_pair(Coverage8bitCounters, "-fsanitize-coverage-8bit-counters"), - std::make_pair(CoverageTracePC, "-fsanitize-coverage-trace-pc")}; + std::make_pair(CoverageTracePC, "-fsanitize-coverage-trace-pc"), + std::make_pair(CoverageTracePCGuard, "-fsanitize-coverage-trace-pc-guard")}; for (auto F : CoverageFlags) { if (CoverageFeatures & F.first) CmdArgs.push_back(Args.MakeArgString(F.second)); @@ -674,6 +698,22 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, if (MsanUseAfterDtor) CmdArgs.push_back(Args.MakeArgString("-fsanitize-memory-use-after-dtor")); + // FIXME: Pass these parameters as function attributes, not as -llvm flags. + if (!TsanMemoryAccess) { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-tsan-instrument-memory-accesses=0"); + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-tsan-instrument-memintrinsics=0"); + } + if (!TsanFuncEntryExit) { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-tsan-instrument-func-entry-exit=0"); + } + if (!TsanAtomics) { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-tsan-instrument-atomics=0"); + } + if (CfiCrossDso) CmdArgs.push_back(Args.MakeArgString("-fsanitize-cfi-cross-dso")); @@ -752,8 +792,11 @@ int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A) { .Case("indirect-calls", CoverageIndirCall) .Case("trace-bb", CoverageTraceBB) .Case("trace-cmp", CoverageTraceCmp) + .Case("trace-div", CoverageTraceDiv) + .Case("trace-gep", CoverageTraceGep) .Case("8bit-counters", Coverage8bitCounters) .Case("trace-pc", CoverageTracePC) + .Case("trace-pc-guard", CoverageTracePCGuard) .Default(0); if (F == 0) D.Diag(clang::diag::err_drv_unsupported_option_argument) |