Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 1 | //===--- SanitizerArgs.cpp - Arguments for sanitizer tools ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Alexey Samsonov | 609213f9 | 2013-08-19 09:14:21 +0000 | [diff] [blame] | 9 | #include "clang/Driver/SanitizerArgs.h" |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 10 | #include "clang/Driver/Driver.h" |
| 11 | #include "clang/Driver/DriverDiagnostic.h" |
| 12 | #include "clang/Driver/Options.h" |
| 13 | #include "clang/Driver/ToolChain.h" |
Evgeniy Stepanov | 2bfcaab | 2014-03-20 14:58:36 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/StringExtras.h" |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringSwitch.h" |
| 16 | #include "llvm/Support/FileSystem.h" |
| 17 | #include "llvm/Support/Path.h" |
Alexey Samsonov | 0c127d7 | 2013-08-19 13:59:22 +0000 | [diff] [blame] | 18 | #include "llvm/Transforms/Utils/SpecialCaseList.h" |
Ahmed Charles | dfca6f9 | 2014-03-09 11:36:40 +0000 | [diff] [blame] | 19 | #include <memory> |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace clang::driver; |
| 22 | using namespace llvm::opt; |
| 23 | |
Alexey Samsonov | bb14f34 | 2013-08-08 11:32:17 +0000 | [diff] [blame] | 24 | void SanitizerArgs::clear() { |
| 25 | Kind = 0; |
| 26 | BlacklistFile = ""; |
Evgeniy Stepanov | 2bfcaab | 2014-03-20 14:58:36 +0000 | [diff] [blame] | 27 | MsanTrackOrigins = 0; |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 28 | AsanZeroBaseShadow = false; |
Alexey Samsonov | bb14f34 | 2013-08-08 11:32:17 +0000 | [diff] [blame] | 29 | UbsanTrapOnError = false; |
Alexey Samsonov | bdfa6c2 | 2014-04-01 13:31:10 +0000 | [diff] [blame] | 30 | AsanSharedRuntime = false; |
Alexey Samsonov | bb14f34 | 2013-08-08 11:32:17 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | SanitizerArgs::SanitizerArgs() { |
| 34 | clear(); |
| 35 | } |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 36 | |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 37 | SanitizerArgs::SanitizerArgs(const ToolChain &TC, |
| 38 | const llvm::opt::ArgList &Args) { |
Alexey Samsonov | bb14f34 | 2013-08-08 11:32:17 +0000 | [diff] [blame] | 39 | clear(); |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 40 | unsigned AllAdd = 0; // All kinds of sanitizers that were turned on |
| 41 | // at least once (possibly, disabled further). |
| 42 | unsigned AllRemove = 0; // During the loop below, the accumulated set of |
| 43 | // sanitizers disabled by the current sanitizer |
| 44 | // argument or any argument after it. |
| 45 | unsigned DiagnosedKinds = 0; // All Kinds we have diagnosed up to now. |
| 46 | // Used to deduplicate diagnostics. |
| 47 | const Driver &D = TC.getDriver(); |
| 48 | for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend(); |
| 49 | I != E; ++I) { |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 50 | unsigned Add, Remove; |
| 51 | if (!parse(D, Args, *I, Add, Remove, true)) |
| 52 | continue; |
| 53 | (*I)->claim(); |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 54 | |
| 55 | AllAdd |= expandGroups(Add); |
| 56 | AllRemove |= expandGroups(Remove); |
| 57 | |
| 58 | // Avoid diagnosing any sanitizer which is disabled later. |
| 59 | Add &= ~AllRemove; |
| 60 | // At this point we have not expanded groups, so any unsupported sanitizers |
| 61 | // in Add are those which have been explicitly enabled. Diagnose them. |
| 62 | Add = filterUnsupportedKinds(TC, Add, Args, *I, /*DiagnoseErrors=*/true, |
| 63 | DiagnosedKinds); |
| 64 | Add = expandGroups(Add); |
| 65 | // Group expansion may have enabled a sanitizer which is disabled later. |
| 66 | Add &= ~AllRemove; |
| 67 | // Silently discard any unsupported sanitizers implicitly enabled through |
| 68 | // group expansion. |
| 69 | Add = filterUnsupportedKinds(TC, Add, Args, *I, /*DiagnoseErrors=*/false, |
| 70 | DiagnosedKinds); |
| 71 | |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 72 | Kind |= Add; |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | UbsanTrapOnError = |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 76 | Args.hasFlag(options::OPT_fsanitize_undefined_trap_on_error, |
| 77 | options::OPT_fno_sanitize_undefined_trap_on_error, false); |
| 78 | |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 79 | // Warn about undefined sanitizer options that require runtime support. |
| 80 | if (UbsanTrapOnError && notAllowedWithTrap()) { |
Alexey Samsonov | cb3f812 | 2014-03-20 10:48:29 +0000 | [diff] [blame] | 81 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 82 | << lastArgumentForKind(D, Args, NotAllowedWithTrap) |
| 83 | << "-fsanitize-undefined-trap-on-error"; |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | // Only one runtime library can be used at once. |
| 87 | bool NeedsAsan = needsAsanRt(); |
| 88 | bool NeedsTsan = needsTsanRt(); |
| 89 | bool NeedsMsan = needsMsanRt(); |
| 90 | bool NeedsLsan = needsLeakDetection(); |
| 91 | if (NeedsAsan && NeedsTsan) |
| 92 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 93 | << lastArgumentForKind(D, Args, NeedsAsanRt) |
| 94 | << lastArgumentForKind(D, Args, NeedsTsanRt); |
| 95 | if (NeedsAsan && NeedsMsan) |
| 96 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 97 | << lastArgumentForKind(D, Args, NeedsAsanRt) |
| 98 | << lastArgumentForKind(D, Args, NeedsMsanRt); |
| 99 | if (NeedsTsan && NeedsMsan) |
| 100 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 101 | << lastArgumentForKind(D, Args, NeedsTsanRt) |
| 102 | << lastArgumentForKind(D, Args, NeedsMsanRt); |
| 103 | if (NeedsLsan && NeedsTsan) |
| 104 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 105 | << lastArgumentForKind(D, Args, NeedsLeakDetection) |
| 106 | << lastArgumentForKind(D, Args, NeedsTsanRt); |
| 107 | if (NeedsLsan && NeedsMsan) |
| 108 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 109 | << lastArgumentForKind(D, Args, NeedsLeakDetection) |
| 110 | << lastArgumentForKind(D, Args, NeedsMsanRt); |
Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 111 | // FIXME: Currently -fsanitize=leak is silently ignored in the presence of |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 112 | // -fsanitize=address. Perhaps it should print an error, or perhaps |
| 113 | // -f(-no)sanitize=leak should change whether leak detection is enabled by |
| 114 | // default in ASan? |
| 115 | |
| 116 | // If -fsanitize contains extra features of ASan, it should also |
| 117 | // explicitly contain -fsanitize=address (probably, turned off later in the |
| 118 | // command line). |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 119 | if ((Kind & AddressFull) != 0 && (AllAdd & Address) == 0) |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 120 | D.Diag(diag::warn_drv_unused_sanitizer) |
| 121 | << lastArgumentForKind(D, Args, AddressFull) |
| 122 | << "-fsanitize=address"; |
| 123 | |
| 124 | // Parse -f(no-)sanitize-blacklist options. |
| 125 | if (Arg *BLArg = Args.getLastArg(options::OPT_fsanitize_blacklist, |
| 126 | options::OPT_fno_sanitize_blacklist)) { |
| 127 | if (BLArg->getOption().matches(options::OPT_fsanitize_blacklist)) { |
| 128 | std::string BLPath = BLArg->getValue(); |
Alexey Samsonov | 0c127d7 | 2013-08-19 13:59:22 +0000 | [diff] [blame] | 129 | if (llvm::sys::fs::exists(BLPath)) { |
| 130 | // Validate the blacklist format. |
| 131 | std::string BLError; |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 132 | std::unique_ptr<llvm::SpecialCaseList> SCL( |
Alexey Samsonov | 0c127d7 | 2013-08-19 13:59:22 +0000 | [diff] [blame] | 133 | llvm::SpecialCaseList::create(BLPath, BLError)); |
| 134 | if (!SCL.get()) |
| 135 | D.Diag(diag::err_drv_malformed_sanitizer_blacklist) << BLError; |
| 136 | else |
| 137 | BlacklistFile = BLPath; |
| 138 | } else { |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 139 | D.Diag(diag::err_drv_no_such_file) << BLPath; |
Alexey Samsonov | 0c127d7 | 2013-08-19 13:59:22 +0000 | [diff] [blame] | 140 | } |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 141 | } |
| 142 | } else { |
| 143 | // If no -fsanitize-blacklist option is specified, try to look up for |
| 144 | // blacklist in the resource directory. |
| 145 | std::string BLPath; |
| 146 | if (getDefaultBlacklistForKind(D, Kind, BLPath) && |
| 147 | llvm::sys::fs::exists(BLPath)) |
| 148 | BlacklistFile = BLPath; |
| 149 | } |
| 150 | |
Evgeniy Stepanov | 2bfcaab | 2014-03-20 14:58:36 +0000 | [diff] [blame] | 151 | // Parse -f[no-]sanitize-memory-track-origins[=level] options. |
| 152 | if (NeedsMsan) { |
| 153 | if (Arg *A = |
| 154 | Args.getLastArg(options::OPT_fsanitize_memory_track_origins_EQ, |
| 155 | options::OPT_fsanitize_memory_track_origins, |
| 156 | options::OPT_fno_sanitize_memory_track_origins)) { |
| 157 | if (A->getOption().matches(options::OPT_fsanitize_memory_track_origins)) { |
| 158 | MsanTrackOrigins = 1; |
| 159 | } else if (A->getOption().matches( |
| 160 | options::OPT_fno_sanitize_memory_track_origins)) { |
| 161 | MsanTrackOrigins = 0; |
| 162 | } else { |
| 163 | StringRef S = A->getValue(); |
| 164 | if (S.getAsInteger(0, MsanTrackOrigins) || MsanTrackOrigins < 0 || |
| 165 | MsanTrackOrigins > 2) { |
| 166 | D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << S; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
Alexey Samsonov | bdfa6c2 | 2014-04-01 13:31:10 +0000 | [diff] [blame] | 172 | if (NeedsAsan) { |
| 173 | AsanSharedRuntime = |
| 174 | (TC.getTriple().getEnvironment() == llvm::Triple::Android) || |
| 175 | Args.hasArg(options::OPT_shared_libasan); |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 176 | AsanZeroBaseShadow = |
Evgeniy Stepanov | d04b861 | 2014-01-16 10:19:31 +0000 | [diff] [blame] | 177 | (TC.getTriple().getEnvironment() == llvm::Triple::Android); |
Alexey Samsonov | bdfa6c2 | 2014-04-01 13:31:10 +0000 | [diff] [blame] | 178 | } |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 181 | void SanitizerArgs::addArgs(const llvm::opt::ArgList &Args, |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 182 | llvm::opt::ArgStringList &CmdArgs) const { |
| 183 | if (!Kind) |
| 184 | return; |
| 185 | SmallString<256> SanitizeOpt("-fsanitize="); |
| 186 | #define SANITIZER(NAME, ID) \ |
| 187 | if (Kind & ID) \ |
| 188 | SanitizeOpt += NAME ","; |
| 189 | #include "clang/Basic/Sanitizers.def" |
| 190 | SanitizeOpt.pop_back(); |
| 191 | CmdArgs.push_back(Args.MakeArgString(SanitizeOpt)); |
| 192 | if (!BlacklistFile.empty()) { |
| 193 | SmallString<64> BlacklistOpt("-fsanitize-blacklist="); |
| 194 | BlacklistOpt += BlacklistFile; |
| 195 | CmdArgs.push_back(Args.MakeArgString(BlacklistOpt)); |
| 196 | } |
| 197 | |
| 198 | if (MsanTrackOrigins) |
Evgeniy Stepanov | 2bfcaab | 2014-03-20 14:58:36 +0000 | [diff] [blame] | 199 | CmdArgs.push_back(Args.MakeArgString("-fsanitize-memory-track-origins=" + |
| 200 | llvm::utostr(MsanTrackOrigins))); |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 201 | |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 202 | // Workaround for PR16386. |
| 203 | if (needsMsanRt()) |
| 204 | CmdArgs.push_back(Args.MakeArgString("-fno-assume-sane-operator-new")); |
| 205 | } |
| 206 | |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 207 | unsigned SanitizerArgs::parse(const char *Value) { |
| 208 | unsigned ParsedKind = llvm::StringSwitch<SanitizeKind>(Value) |
| 209 | #define SANITIZER(NAME, ID) .Case(NAME, ID) |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 210 | #define SANITIZER_GROUP(NAME, ID, ALIAS) .Case(NAME, ID##Group) |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 211 | #include "clang/Basic/Sanitizers.def" |
| 212 | .Default(SanitizeKind()); |
Kostya Serebryany | bedc616 | 2013-09-23 09:52:37 +0000 | [diff] [blame] | 213 | // Assume -fsanitize=address implies -fsanitize=init-order,use-after-return. |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 214 | // FIXME: This should be either specified in Sanitizers.def, or go away when |
Kostya Serebryany | bedc616 | 2013-09-23 09:52:37 +0000 | [diff] [blame] | 215 | // we get rid of "-fsanitize=init-order,use-after-return" flags at all. |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 216 | if (ParsedKind & Address) |
Kostya Serebryany | bedc616 | 2013-09-23 09:52:37 +0000 | [diff] [blame] | 217 | ParsedKind |= InitOrder | UseAfterReturn; |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 218 | return ParsedKind; |
| 219 | } |
| 220 | |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 221 | unsigned SanitizerArgs::expandGroups(unsigned Kinds) { |
| 222 | #define SANITIZER(NAME, ID) |
| 223 | #define SANITIZER_GROUP(NAME, ID, ALIAS) if (Kinds & ID##Group) Kinds |= ID; |
| 224 | #include "clang/Basic/Sanitizers.def" |
| 225 | return Kinds; |
| 226 | } |
| 227 | |
| 228 | void SanitizerArgs::filterUnsupportedMask(const ToolChain &TC, unsigned &Kinds, |
| 229 | unsigned Mask, |
| 230 | const llvm::opt::ArgList &Args, |
| 231 | const llvm::opt::Arg *A, |
| 232 | bool DiagnoseErrors, |
| 233 | unsigned &DiagnosedKinds) { |
| 234 | unsigned MaskedKinds = Kinds & Mask; |
| 235 | if (!MaskedKinds) |
| 236 | return; |
| 237 | Kinds &= ~Mask; |
| 238 | // Do we have new kinds to diagnose? |
| 239 | if (DiagnoseErrors && (DiagnosedKinds & MaskedKinds) != MaskedKinds) { |
| 240 | // Only diagnose the new kinds. |
| 241 | std::string Desc = |
| 242 | describeSanitizeArg(Args, A, MaskedKinds & ~DiagnosedKinds); |
| 243 | TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target) |
| 244 | << Desc << TC.getTriple().str(); |
| 245 | DiagnosedKinds |= MaskedKinds; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | unsigned SanitizerArgs::filterUnsupportedKinds(const ToolChain &TC, |
| 250 | unsigned Kinds, |
| 251 | const llvm::opt::ArgList &Args, |
| 252 | const llvm::opt::Arg *A, |
| 253 | bool DiagnoseErrors, |
| 254 | unsigned &DiagnosedKinds) { |
| 255 | bool IsLinux = TC.getTriple().getOS() == llvm::Triple::Linux; |
| 256 | bool IsX86 = TC.getTriple().getArch() == llvm::Triple::x86; |
| 257 | bool IsX86_64 = TC.getTriple().getArch() == llvm::Triple::x86_64; |
| 258 | if (!(IsLinux && IsX86_64)) { |
| 259 | filterUnsupportedMask(TC, Kinds, Thread | Memory | DataFlow, Args, A, |
| 260 | DiagnoseErrors, DiagnosedKinds); |
| 261 | } |
| 262 | if (!(IsLinux && (IsX86 || IsX86_64))) { |
| 263 | filterUnsupportedMask(TC, Kinds, Function, Args, A, DiagnoseErrors, |
| 264 | DiagnosedKinds); |
| 265 | } |
| 266 | return Kinds; |
| 267 | } |
| 268 | |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 269 | unsigned SanitizerArgs::parse(const Driver &D, const llvm::opt::Arg *A, |
| 270 | bool DiagnoseErrors) { |
| 271 | unsigned Kind = 0; |
| 272 | for (unsigned I = 0, N = A->getNumValues(); I != N; ++I) { |
| 273 | if (unsigned K = parse(A->getValue(I))) |
| 274 | Kind |= K; |
| 275 | else if (DiagnoseErrors) |
| 276 | D.Diag(diag::err_drv_unsupported_option_argument) |
| 277 | << A->getOption().getName() << A->getValue(I); |
| 278 | } |
| 279 | return Kind; |
| 280 | } |
| 281 | |
| 282 | bool SanitizerArgs::parse(const Driver &D, const llvm::opt::ArgList &Args, |
| 283 | const llvm::opt::Arg *A, unsigned &Add, |
| 284 | unsigned &Remove, bool DiagnoseErrors) { |
| 285 | Add = 0; |
| 286 | Remove = 0; |
Alexey Samsonov | e123799 | 2014-03-21 07:15:47 +0000 | [diff] [blame] | 287 | if (A->getOption().matches(options::OPT_fsanitize_EQ)) { |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 288 | Add = parse(D, A, DiagnoseErrors); |
| 289 | } else if (A->getOption().matches(options::OPT_fno_sanitize_EQ)) { |
| 290 | Remove = parse(D, A, DiagnoseErrors); |
| 291 | } else { |
| 292 | // Flag is not relevant to sanitizers. |
| 293 | return false; |
| 294 | } |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 295 | return true; |
| 296 | } |
| 297 | |
| 298 | std::string SanitizerArgs::lastArgumentForKind(const Driver &D, |
| 299 | const llvm::opt::ArgList &Args, |
| 300 | unsigned Kind) { |
| 301 | for (llvm::opt::ArgList::const_reverse_iterator I = Args.rbegin(), |
| 302 | E = Args.rend(); |
| 303 | I != E; ++I) { |
| 304 | unsigned Add, Remove; |
| 305 | if (parse(D, Args, *I, Add, Remove, false) && |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 306 | (expandGroups(Add) & Kind)) |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 307 | return describeSanitizeArg(Args, *I, Kind); |
| 308 | Kind &= ~Remove; |
| 309 | } |
| 310 | llvm_unreachable("arg list didn't provide expected value"); |
| 311 | } |
| 312 | |
| 313 | std::string SanitizerArgs::describeSanitizeArg(const llvm::opt::ArgList &Args, |
| 314 | const llvm::opt::Arg *A, |
| 315 | unsigned Mask) { |
| 316 | if (!A->getOption().matches(options::OPT_fsanitize_EQ)) |
| 317 | return A->getAsString(Args); |
| 318 | |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 319 | std::string Sanitizers; |
| 320 | for (unsigned I = 0, N = A->getNumValues(); I != N; ++I) { |
| 321 | if (expandGroups(parse(A->getValue(I))) & Mask) { |
| 322 | if (!Sanitizers.empty()) |
| 323 | Sanitizers += ","; |
| 324 | Sanitizers += A->getValue(I); |
| 325 | } |
| 326 | } |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 327 | |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 328 | assert(!Sanitizers.empty() && "arg didn't provide expected value"); |
| 329 | return "-fsanitize=" + Sanitizers; |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | bool SanitizerArgs::getDefaultBlacklistForKind(const Driver &D, unsigned Kind, |
| 333 | std::string &BLPath) { |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame^] | 334 | const char *BlacklistFile = nullptr; |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 335 | if (Kind & NeedsAsanRt) |
| 336 | BlacklistFile = "asan_blacklist.txt"; |
| 337 | else if (Kind & NeedsMsanRt) |
| 338 | BlacklistFile = "msan_blacklist.txt"; |
| 339 | else if (Kind & NeedsTsanRt) |
| 340 | BlacklistFile = "tsan_blacklist.txt"; |
Peter Collingbourne | 276be3c | 2013-08-14 18:54:18 +0000 | [diff] [blame] | 341 | else if (Kind & NeedsDfsanRt) |
| 342 | BlacklistFile = "dfsan_abilist.txt"; |
| 343 | |
Alexey Samsonov | cf05596 | 2013-08-08 10:11:02 +0000 | [diff] [blame] | 344 | if (BlacklistFile) { |
| 345 | SmallString<64> Path(D.ResourceDir); |
| 346 | llvm::sys::path::append(Path, BlacklistFile); |
| 347 | BLPath = Path.str(); |
| 348 | return true; |
| 349 | } |
| 350 | return false; |
| 351 | } |