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