clang  8.0.0svn
SanitizerArgs.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
10 #include "ToolChains/CommonArgs.h"
11 #include "clang/Basic/Sanitizers.h"
12 #include "clang/Driver/Driver.h"
14 #include "clang/Driver/Options.h"
15 #include "clang/Driver/ToolChain.h"
16 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/Support/FileSystem.h"
19 #include "llvm/Support/Path.h"
20 #include "llvm/Support/SpecialCaseList.h"
21 #include "llvm/Support/TargetParser.h"
22 #include <memory>
23 
24 using namespace clang;
25 using namespace clang::SanitizerKind;
26 using namespace clang::driver;
27 using namespace llvm::opt;
28 
29 enum : SanitizerMask {
30  NeedsUbsanRt = Undefined | Integer | ImplicitConversion | Nullability | CFI,
31  NeedsUbsanCxxRt = Vptr | CFI,
34  RequiresPIE = DataFlow | HWAddress | Scudo,
35  NeedsUnwindTables = Address | HWAddress | Thread | Memory | DataFlow,
36  SupportsCoverage = Address | HWAddress | KernelAddress | KernelHWAddress |
37  Memory | Leak | Undefined | Integer | ImplicitConversion |
38  Nullability | DataFlow | Fuzzer | FuzzerNoLink,
39  RecoverableByDefault = Undefined | Integer | ImplicitConversion | Nullability,
40  Unrecoverable = Unreachable | Return,
41  AlwaysRecoverable = KernelAddress | KernelHWAddress,
43  NeedsLTO = CFI,
44  TrappingSupported = (Undefined & ~Vptr) | UnsignedIntegerOverflow |
45  ImplicitConversion | Nullability | LocalBounds | CFI,
48  CFIVCall | CFINVCall | CFIMFCall | CFIDerivedCast | CFIUnrelatedCast,
50 };
51 
53  CoverageFunc = 1 << 0,
54  CoverageBB = 1 << 1,
55  CoverageEdge = 1 << 2,
57  CoverageTraceBB = 1 << 4, // Deprecated.
58  CoverageTraceCmp = 1 << 5,
59  CoverageTraceDiv = 1 << 6,
60  CoverageTraceGep = 1 << 7,
61  Coverage8bitCounters = 1 << 8, // Deprecated.
62  CoverageTracePC = 1 << 9,
64  CoverageNoPrune = 1 << 11,
66  CoveragePCTable = 1 << 13,
67  CoverageStackDepth = 1 << 14,
68 };
69 
70 /// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any
71 /// invalid components. Returns a SanitizerMask.
72 static SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A,
73  bool DiagnoseErrors);
74 
75 /// Parse -f(no-)?sanitize-coverage= flag values, diagnosing any invalid
76 /// components. Returns OR of members of \c CoverageFeature enumeration.
77 static int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A);
78 
79 /// Produce an argument string from ArgList \p Args, which shows how it
80 /// provides some sanitizer kind from \p Mask. For example, the argument list
81 /// "-fsanitize=thread,vptr -fsanitize=address" with mask \c NeedsUbsanRt
82 /// would produce "-fsanitize=vptr".
83 static std::string lastArgumentForMask(const Driver &D,
84  const llvm::opt::ArgList &Args,
85  SanitizerMask Mask);
86 
87 /// Produce an argument string from argument \p A, which shows how it provides
88 /// a value in \p Mask. For instance, the argument
89 /// "-fsanitize=address,alignment" with mask \c NeedsUbsanRt would produce
90 /// "-fsanitize=alignment".
91 static std::string describeSanitizeArg(const llvm::opt::Arg *A,
92  SanitizerMask Mask);
93 
94 /// Produce a string containing comma-separated names of sanitizers in \p
95 /// Sanitizers set.
96 static std::string toString(const clang::SanitizerSet &Sanitizers);
97 
98 static void addDefaultBlacklists(const Driver &D, SanitizerMask Kinds,
99  std::vector<std::string> &BlacklistFiles) {
100  struct Blacklist {
101  const char *File;
102  SanitizerMask Mask;
103  } Blacklists[] = {{"asan_blacklist.txt", Address},
104  {"hwasan_blacklist.txt", HWAddress},
105  {"msan_blacklist.txt", Memory},
106  {"tsan_blacklist.txt", Thread},
107  {"dfsan_abilist.txt", DataFlow},
108  {"cfi_blacklist.txt", CFI},
109  {"ubsan_blacklist.txt", Undefined | Integer | Nullability}};
110 
111  for (auto BL : Blacklists) {
112  if (!(Kinds & BL.Mask))
113  continue;
114 
116  llvm::sys::path::append(Path, "share", BL.File);
117  if (llvm::sys::fs::exists(Path))
118  BlacklistFiles.push_back(Path.str());
119  else if (BL.Mask == CFI)
120  // If cfi_blacklist.txt cannot be found in the resource dir, driver
121  // should fail.
122  D.Diag(clang::diag::err_drv_no_such_file) << Path;
123  }
124 }
125 
126 /// Sets group bits for every group that has at least one representative already
127 /// enabled in \p Kinds.
129 #define SANITIZER(NAME, ID)
130 #define SANITIZER_GROUP(NAME, ID, ALIAS) \
131  if (Kinds & SanitizerKind::ID) \
132  Kinds |= SanitizerKind::ID##Group;
133 #include "clang/Basic/Sanitizers.def"
134  return Kinds;
135 }
136 
138  const llvm::opt::ArgList &Args) {
139  SanitizerMask TrapRemove = 0; // During the loop below, the accumulated set of
140  // sanitizers disabled by the current sanitizer
141  // argument or any argument after it.
142  SanitizerMask TrappingKinds = 0;
143  SanitizerMask TrappingSupportedWithGroups = setGroupBits(TrappingSupported);
144 
145  for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
146  I != E; ++I) {
147  const auto *Arg = *I;
148  if (Arg->getOption().matches(options::OPT_fsanitize_trap_EQ)) {
149  Arg->claim();
150  SanitizerMask Add = parseArgValues(D, Arg, true);
151  Add &= ~TrapRemove;
152  if (SanitizerMask InvalidValues = Add & ~TrappingSupportedWithGroups) {
153  SanitizerSet S;
154  S.Mask = InvalidValues;
155  D.Diag(diag::err_drv_unsupported_option_argument) << "-fsanitize-trap"
156  << toString(S);
157  }
158  TrappingKinds |= expandSanitizerGroups(Add) & ~TrapRemove;
159  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) {
160  Arg->claim();
161  TrapRemove |= expandSanitizerGroups(parseArgValues(D, Arg, true));
162  } else if (Arg->getOption().matches(
163  options::OPT_fsanitize_undefined_trap_on_error)) {
164  Arg->claim();
165  TrappingKinds |=
166  expandSanitizerGroups(UndefinedGroup & ~TrapRemove) & ~TrapRemove;
167  } else if (Arg->getOption().matches(
168  options::OPT_fno_sanitize_undefined_trap_on_error)) {
169  Arg->claim();
170  TrapRemove |= expandSanitizerGroups(UndefinedGroup);
171  }
172  }
173 
174  // Apply default trapping behavior.
175  TrappingKinds |= TrappingDefault & ~TrapRemove;
176 
177  return TrappingKinds;
178 }
179 
180 bool SanitizerArgs::needsUbsanRt() const {
181  // All of these include ubsan.
182  if (needsAsanRt() || needsMsanRt() || needsHwasanRt() || needsTsanRt() ||
183  needsDfsanRt() || needsLsanRt() || needsCfiDiagRt() ||
184  (needsScudoRt() && !requiresMinimalRuntime()))
185  return false;
186 
187  return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) ||
188  CoverageFeatures;
189 }
190 
191 bool SanitizerArgs::needsCfiRt() const {
192  return !(Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso &&
193  !ImplicitCfiRuntime;
194 }
195 
196 bool SanitizerArgs::needsCfiDiagRt() const {
197  return (Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso &&
198  !ImplicitCfiRuntime;
199 }
200 
201 bool SanitizerArgs::requiresPIE() const {
202  return NeedPIE || (Sanitizers.Mask & RequiresPIE);
203 }
204 
205 bool SanitizerArgs::needsUnwindTables() const {
206  return Sanitizers.Mask & NeedsUnwindTables;
207 }
208 
209 SanitizerArgs::SanitizerArgs(const ToolChain &TC,
210  const llvm::opt::ArgList &Args) {
211  SanitizerMask AllRemove = 0; // During the loop below, the accumulated set of
212  // sanitizers disabled by the current sanitizer
213  // argument or any argument after it.
214  SanitizerMask AllAddedKinds = 0; // Mask of all sanitizers ever enabled by
215  // -fsanitize= flags (directly or via group
216  // expansion), some of which may be disabled
217  // later. Used to carefully prune
218  // unused-argument diagnostics.
219  SanitizerMask DiagnosedKinds = 0; // All Kinds we have diagnosed up to now.
220  // Used to deduplicate diagnostics.
221  SanitizerMask Kinds = 0;
222  const SanitizerMask Supported = setGroupBits(TC.getSupportedSanitizers());
223 
224  CfiCrossDso = Args.hasFlag(options::OPT_fsanitize_cfi_cross_dso,
225  options::OPT_fno_sanitize_cfi_cross_dso, false);
226 
227  ToolChain::RTTIMode RTTIMode = TC.getRTTIMode();
228 
229  const Driver &D = TC.getDriver();
230  SanitizerMask TrappingKinds = parseSanitizeTrapArgs(D, Args);
231  SanitizerMask InvalidTrappingKinds = TrappingKinds & NotAllowedWithTrap;
232 
233  MinimalRuntime =
234  Args.hasFlag(options::OPT_fsanitize_minimal_runtime,
235  options::OPT_fno_sanitize_minimal_runtime, MinimalRuntime);
236 
237  // The object size sanitizer should not be enabled at -O0.
238  Arg *OptLevel = Args.getLastArg(options::OPT_O_Group);
239  bool RemoveObjectSizeAtO0 =
240  !OptLevel || OptLevel->getOption().matches(options::OPT_O0);
241 
242  for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
243  I != E; ++I) {
244  const auto *Arg = *I;
245  if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) {
246  Arg->claim();
247  SanitizerMask Add = parseArgValues(D, Arg, /*AllowGroups=*/true);
248 
249  if (RemoveObjectSizeAtO0) {
250  AllRemove |= SanitizerKind::ObjectSize;
251 
252  // The user explicitly enabled the object size sanitizer. Warn that
253  // that this does nothing at -O0.
254  if (Add & SanitizerKind::ObjectSize)
255  D.Diag(diag::warn_drv_object_size_disabled_O0)
256  << Arg->getAsString(Args);
257  }
258 
259  AllAddedKinds |= expandSanitizerGroups(Add);
260 
261  // Avoid diagnosing any sanitizer which is disabled later.
262  Add &= ~AllRemove;
263  // At this point we have not expanded groups, so any unsupported
264  // sanitizers in Add are those which have been explicitly enabled.
265  // Diagnose them.
266  if (SanitizerMask KindsToDiagnose =
267  Add & InvalidTrappingKinds & ~DiagnosedKinds) {
268  std::string Desc = describeSanitizeArg(*I, KindsToDiagnose);
269  D.Diag(diag::err_drv_argument_not_allowed_with)
270  << Desc << "-fsanitize-trap=undefined";
271  DiagnosedKinds |= KindsToDiagnose;
272  }
273  Add &= ~InvalidTrappingKinds;
274 
275  if (MinimalRuntime) {
276  if (SanitizerMask KindsToDiagnose =
277  Add & NotAllowedWithMinimalRuntime & ~DiagnosedKinds) {
278  std::string Desc = describeSanitizeArg(*I, KindsToDiagnose);
279  D.Diag(diag::err_drv_argument_not_allowed_with)
280  << Desc << "-fsanitize-minimal-runtime";
281  DiagnosedKinds |= KindsToDiagnose;
282  }
284  }
285 
286  // FIXME: Make CFI on member function calls compatible with cross-DSO CFI.
287  // There are currently two problems:
288  // - Virtual function call checks need to pass a pointer to the function
289  // address to llvm.type.test and a pointer to the address point to the
290  // diagnostic function. Currently we pass the same pointer to both
291  // places.
292  // - Non-virtual function call checks may need to check multiple type
293  // identifiers.
294  // Fixing both of those may require changes to the cross-DSO CFI
295  // interface.
296  if (CfiCrossDso && (Add & CFIMFCall & ~DiagnosedKinds)) {
297  D.Diag(diag::err_drv_argument_not_allowed_with)
298  << "-fsanitize=cfi-mfcall"
299  << "-fsanitize-cfi-cross-dso";
300  Add &= ~CFIMFCall;
301  DiagnosedKinds |= CFIMFCall;
302  }
303 
304  if (SanitizerMask KindsToDiagnose = Add & ~Supported & ~DiagnosedKinds) {
305  std::string Desc = describeSanitizeArg(*I, KindsToDiagnose);
306  D.Diag(diag::err_drv_unsupported_opt_for_target)
307  << Desc << TC.getTriple().str();
308  DiagnosedKinds |= KindsToDiagnose;
309  }
310  Add &= Supported;
311 
312  // Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups
313  // so we don't error out if -fno-rtti and -fsanitize=undefined were
314  // passed.
315  if ((Add & Vptr) && (RTTIMode == ToolChain::RM_Disabled)) {
316  if (const llvm::opt::Arg *NoRTTIArg = TC.getRTTIArg()) {
317  assert(NoRTTIArg->getOption().matches(options::OPT_fno_rtti) &&
318  "RTTI disabled without -fno-rtti option?");
319  // The user explicitly passed -fno-rtti with -fsanitize=vptr, but
320  // the vptr sanitizer requires RTTI, so this is a user error.
321  D.Diag(diag::err_drv_argument_not_allowed_with)
322  << "-fsanitize=vptr" << NoRTTIArg->getAsString(Args);
323  } else {
324  // The vptr sanitizer requires RTTI, but RTTI is disabled (by
325  // default). Warn that the vptr sanitizer is being disabled.
326  D.Diag(diag::warn_drv_disabling_vptr_no_rtti_default);
327  }
328 
329  // Take out the Vptr sanitizer from the enabled sanitizers
330  AllRemove |= Vptr;
331  }
332 
333  Add = expandSanitizerGroups(Add);
334  // Group expansion may have enabled a sanitizer which is disabled later.
335  Add &= ~AllRemove;
336  // Silently discard any unsupported sanitizers implicitly enabled through
337  // group expansion.
338  Add &= ~InvalidTrappingKinds;
339  if (MinimalRuntime) {
341  }
342  if (CfiCrossDso)
343  Add &= ~CFIMFCall;
344  Add &= Supported;
345 
346  if (Add & Fuzzer)
347  Add |= FuzzerNoLink;
348 
349  // Enable coverage if the fuzzing flag is set.
350  if (Add & FuzzerNoLink) {
351  CoverageFeatures |= CoverageInline8bitCounters | CoverageIndirCall |
353  // Due to TLS differences, stack depth tracking is only enabled on Linux
354  if (TC.getTriple().isOSLinux())
355  CoverageFeatures |= CoverageStackDepth;
356  }
357 
358  Kinds |= Add;
359  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_EQ)) {
360  Arg->claim();
361  SanitizerMask Remove = parseArgValues(D, Arg, true);
362  AllRemove |= expandSanitizerGroups(Remove);
363  }
364  }
365 
366  std::pair<SanitizerMask, SanitizerMask> IncompatibleGroups[] = {
367  std::make_pair(Address, Thread | Memory),
368  std::make_pair(Thread, Memory),
369  std::make_pair(Leak, Thread | Memory),
370  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
371  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
372  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
373  KernelAddress),
374  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
375  KernelAddress | Efficiency),
376  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
377  KernelAddress | Efficiency),
378  std::make_pair(ShadowCallStack, Address | HWAddress | Leak | Thread |
379  Memory | KernelAddress | Efficiency |
380  SafeStack),
381  std::make_pair(KernelHWAddress, Address | HWAddress | Leak | Thread |
382  Memory | KernelAddress | Efficiency |
383  SafeStack | ShadowCallStack)};
384 
385  // Enable toolchain specific default sanitizers if not explicitly disabled.
386  SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
387 
388  // Disable default sanitizers that are incompatible with explicitly requested
389  // ones.
390  for (auto G : IncompatibleGroups) {
391  SanitizerMask Group = G.first;
392  if ((Default & Group) && (Kinds & G.second))
393  Default &= ~Group;
394  }
395 
396  Kinds |= Default;
397 
398  // We disable the vptr sanitizer if it was enabled by group expansion but RTTI
399  // is disabled.
400  if ((Kinds & Vptr) && (RTTIMode == ToolChain::RM_Disabled)) {
401  Kinds &= ~Vptr;
402  }
403 
404  // Check that LTO is enabled if we need it.
405  if ((Kinds & NeedsLTO) && !D.isUsingLTO()) {
406  D.Diag(diag::err_drv_argument_only_allowed_with)
407  << lastArgumentForMask(D, Args, Kinds & NeedsLTO) << "-flto";
408  }
409 
410  if ((Kinds & ShadowCallStack) &&
411  TC.getTriple().getArch() == llvm::Triple::aarch64 &&
412  !llvm::AArch64::isX18ReservedByDefault(TC.getTriple()) &&
413  !Args.hasArg(options::OPT_ffixed_x18)) {
414  D.Diag(diag::err_drv_argument_only_allowed_with)
415  << lastArgumentForMask(D, Args, Kinds & ShadowCallStack)
416  << "-ffixed-x18";
417  }
418 
419  // Report error if there are non-trapping sanitizers that require
420  // c++abi-specific parts of UBSan runtime, and they are not provided by the
421  // toolchain. We don't have a good way to check the latter, so we just
422  // check if the toolchan supports vptr.
423  if (~Supported & Vptr) {
424  SanitizerMask KindsToDiagnose = Kinds & ~TrappingKinds & NeedsUbsanCxxRt;
425  // The runtime library supports the Microsoft C++ ABI, but only well enough
426  // for CFI. FIXME: Remove this once we support vptr on Windows.
427  if (TC.getTriple().isOSWindows())
428  KindsToDiagnose &= ~CFI;
429  if (KindsToDiagnose) {
430  SanitizerSet S;
431  S.Mask = KindsToDiagnose;
432  D.Diag(diag::err_drv_unsupported_opt_for_target)
433  << ("-fno-sanitize-trap=" + toString(S)) << TC.getTriple().str();
434  Kinds &= ~KindsToDiagnose;
435  }
436  }
437 
438  // Warn about incompatible groups of sanitizers.
439  for (auto G : IncompatibleGroups) {
440  SanitizerMask Group = G.first;
441  if (Kinds & Group) {
442  if (SanitizerMask Incompatible = Kinds & G.second) {
443  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
444  << lastArgumentForMask(D, Args, Group)
445  << lastArgumentForMask(D, Args, Incompatible);
446  Kinds &= ~Incompatible;
447  }
448  }
449  }
450  // FIXME: Currently -fsanitize=leak is silently ignored in the presence of
451  // -fsanitize=address. Perhaps it should print an error, or perhaps
452  // -f(-no)sanitize=leak should change whether leak detection is enabled by
453  // default in ASan?
454 
455  // Parse -f(no-)?sanitize-recover flags.
457  SanitizerMask DiagnosedUnrecoverableKinds = 0;
458  SanitizerMask DiagnosedAlwaysRecoverableKinds = 0;
459  for (const auto *Arg : Args) {
460  const char *DeprecatedReplacement = nullptr;
461  if (Arg->getOption().matches(options::OPT_fsanitize_recover)) {
462  DeprecatedReplacement =
463  "-fsanitize-recover=undefined,integer' or '-fsanitize-recover=all";
465  Arg->claim();
466  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_recover)) {
467  DeprecatedReplacement = "-fno-sanitize-recover=undefined,integer' or "
468  "'-fno-sanitize-recover=all";
470  Arg->claim();
471  } else if (Arg->getOption().matches(options::OPT_fsanitize_recover_EQ)) {
472  SanitizerMask Add = parseArgValues(D, Arg, true);
473  // Report error if user explicitly tries to recover from unrecoverable
474  // sanitizer.
475  if (SanitizerMask KindsToDiagnose =
476  Add & Unrecoverable & ~DiagnosedUnrecoverableKinds) {
477  SanitizerSet SetToDiagnose;
478  SetToDiagnose.Mask |= KindsToDiagnose;
479  D.Diag(diag::err_drv_unsupported_option_argument)
480  << Arg->getOption().getName() << toString(SetToDiagnose);
481  DiagnosedUnrecoverableKinds |= KindsToDiagnose;
482  }
483  RecoverableKinds |= expandSanitizerGroups(Add);
484  Arg->claim();
485  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_recover_EQ)) {
486  SanitizerMask Remove = parseArgValues(D, Arg, true);
487  // Report error if user explicitly tries to disable recovery from
488  // always recoverable sanitizer.
489  if (SanitizerMask KindsToDiagnose =
490  Remove & AlwaysRecoverable & ~DiagnosedAlwaysRecoverableKinds) {
491  SanitizerSet SetToDiagnose;
492  SetToDiagnose.Mask |= KindsToDiagnose;
493  D.Diag(diag::err_drv_unsupported_option_argument)
494  << Arg->getOption().getName() << toString(SetToDiagnose);
495  DiagnosedAlwaysRecoverableKinds |= KindsToDiagnose;
496  }
497  RecoverableKinds &= ~expandSanitizerGroups(Remove);
498  Arg->claim();
499  }
500  if (DeprecatedReplacement) {
501  D.Diag(diag::warn_drv_deprecated_arg) << Arg->getAsString(Args)
502  << DeprecatedReplacement;
503  }
504  }
505  RecoverableKinds &= Kinds;
506  RecoverableKinds &= ~Unrecoverable;
507 
508  TrappingKinds &= Kinds;
509  RecoverableKinds &= ~TrappingKinds;
510 
511  // Setup blacklist files.
512  // Add default blacklist from resource directory.
513  addDefaultBlacklists(D, Kinds, BlacklistFiles);
514  // Parse -f(no-)sanitize-blacklist options.
515  for (const auto *Arg : Args) {
516  if (Arg->getOption().matches(options::OPT_fsanitize_blacklist)) {
517  Arg->claim();
518  std::string BLPath = Arg->getValue();
519  if (llvm::sys::fs::exists(BLPath)) {
520  BlacklistFiles.push_back(BLPath);
521  ExtraDeps.push_back(BLPath);
522  } else {
523  D.Diag(clang::diag::err_drv_no_such_file) << BLPath;
524  }
525  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_blacklist)) {
526  Arg->claim();
527  BlacklistFiles.clear();
528  ExtraDeps.clear();
529  }
530  }
531  // Validate blacklists format.
532  {
533  std::string BLError;
534  std::unique_ptr<llvm::SpecialCaseList> SCL(
535  llvm::SpecialCaseList::create(BlacklistFiles, BLError));
536  if (!SCL.get())
537  D.Diag(clang::diag::err_drv_malformed_sanitizer_blacklist) << BLError;
538  }
539 
540  // Parse -f[no-]sanitize-memory-track-origins[=level] options.
541  if (AllAddedKinds & Memory) {
542  if (Arg *A =
543  Args.getLastArg(options::OPT_fsanitize_memory_track_origins_EQ,
544  options::OPT_fsanitize_memory_track_origins,
545  options::OPT_fno_sanitize_memory_track_origins)) {
546  if (A->getOption().matches(options::OPT_fsanitize_memory_track_origins)) {
547  MsanTrackOrigins = 2;
548  } else if (A->getOption().matches(
549  options::OPT_fno_sanitize_memory_track_origins)) {
550  MsanTrackOrigins = 0;
551  } else {
552  StringRef S = A->getValue();
553  if (S.getAsInteger(0, MsanTrackOrigins) || MsanTrackOrigins < 0 ||
554  MsanTrackOrigins > 2) {
555  D.Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S;
556  }
557  }
558  }
559  MsanUseAfterDtor =
560  Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
561  options::OPT_fno_sanitize_memory_use_after_dtor,
562  MsanUseAfterDtor);
563  NeedPIE |= !(TC.getTriple().isOSLinux() &&
564  TC.getTriple().getArch() == llvm::Triple::x86_64);
565  } else {
566  MsanUseAfterDtor = false;
567  }
568 
569  if (AllAddedKinds & Thread) {
570  TsanMemoryAccess = Args.hasFlag(options::OPT_fsanitize_thread_memory_access,
571  options::OPT_fno_sanitize_thread_memory_access,
572  TsanMemoryAccess);
573  TsanFuncEntryExit = Args.hasFlag(options::OPT_fsanitize_thread_func_entry_exit,
574  options::OPT_fno_sanitize_thread_func_entry_exit,
575  TsanFuncEntryExit);
576  TsanAtomics = Args.hasFlag(options::OPT_fsanitize_thread_atomics,
577  options::OPT_fno_sanitize_thread_atomics,
578  TsanAtomics);
579  }
580 
581  if (AllAddedKinds & CFI) {
582  // Without PIE, external function address may resolve to a PLT record, which
583  // can not be verified by the target module.
584  NeedPIE |= CfiCrossDso;
585  CfiICallGeneralizePointers =
586  Args.hasArg(options::OPT_fsanitize_cfi_icall_generalize_pointers);
587 
588  if (CfiCrossDso && CfiICallGeneralizePointers)
589  D.Diag(diag::err_drv_argument_not_allowed_with)
590  << "-fsanitize-cfi-cross-dso"
591  << "-fsanitize-cfi-icall-generalize-pointers";
592  }
593 
594  Stats = Args.hasFlag(options::OPT_fsanitize_stats,
595  options::OPT_fno_sanitize_stats, false);
596 
597  if (MinimalRuntime) {
598  SanitizerMask IncompatibleMask =
600  if (IncompatibleMask)
601  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
602  << "-fsanitize-minimal-runtime"
603  << lastArgumentForMask(D, Args, IncompatibleMask);
604 
605  SanitizerMask NonTrappingCfi = Kinds & CFI & ~TrappingKinds;
606  if (NonTrappingCfi)
607  D.Diag(clang::diag::err_drv_argument_only_allowed_with)
608  << "fsanitize-minimal-runtime"
609  << "fsanitize-trap=cfi";
610  }
611 
612  // Parse -f(no-)?sanitize-coverage flags if coverage is supported by the
613  // enabled sanitizers.
614  for (const auto *Arg : Args) {
615  if (Arg->getOption().matches(options::OPT_fsanitize_coverage)) {
616  int LegacySanitizeCoverage;
617  if (Arg->getNumValues() == 1 &&
618  !StringRef(Arg->getValue(0))
619  .getAsInteger(0, LegacySanitizeCoverage)) {
620  CoverageFeatures = 0;
621  Arg->claim();
622  if (LegacySanitizeCoverage != 0) {
623  D.Diag(diag::warn_drv_deprecated_arg)
624  << Arg->getAsString(Args) << "-fsanitize-coverage=trace-pc-guard";
625  }
626  continue;
627  }
628  CoverageFeatures |= parseCoverageFeatures(D, Arg);
629 
630  // Disable coverage and not claim the flags if there is at least one
631  // non-supporting sanitizer.
632  if (!(AllAddedKinds & ~AllRemove & ~setGroupBits(SupportsCoverage))) {
633  Arg->claim();
634  } else {
635  CoverageFeatures = 0;
636  }
637  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_coverage)) {
638  Arg->claim();
639  CoverageFeatures &= ~parseCoverageFeatures(D, Arg);
640  }
641  }
642  // Choose at most one coverage type: function, bb, or edge.
643  if ((CoverageFeatures & CoverageFunc) && (CoverageFeatures & CoverageBB))
644  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
645  << "-fsanitize-coverage=func"
646  << "-fsanitize-coverage=bb";
647  if ((CoverageFeatures & CoverageFunc) && (CoverageFeatures & CoverageEdge))
648  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
649  << "-fsanitize-coverage=func"
650  << "-fsanitize-coverage=edge";
651  if ((CoverageFeatures & CoverageBB) && (CoverageFeatures & CoverageEdge))
652  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
653  << "-fsanitize-coverage=bb"
654  << "-fsanitize-coverage=edge";
655  // Basic block tracing and 8-bit counters require some type of coverage
656  // enabled.
657  if (CoverageFeatures & CoverageTraceBB)
658  D.Diag(clang::diag::warn_drv_deprecated_arg)
659  << "-fsanitize-coverage=trace-bb"
660  << "-fsanitize-coverage=trace-pc-guard";
661  if (CoverageFeatures & Coverage8bitCounters)
662  D.Diag(clang::diag::warn_drv_deprecated_arg)
663  << "-fsanitize-coverage=8bit-counters"
664  << "-fsanitize-coverage=trace-pc-guard";
665 
666  int InsertionPointTypes = CoverageFunc | CoverageBB | CoverageEdge;
667  int InstrumentationTypes =
669  if ((CoverageFeatures & InsertionPointTypes) &&
670  !(CoverageFeatures & InstrumentationTypes)) {
671  D.Diag(clang::diag::warn_drv_deprecated_arg)
672  << "-fsanitize-coverage=[func|bb|edge]"
673  << "-fsanitize-coverage=[func|bb|edge],[trace-pc-guard|trace-pc]";
674  }
675 
676  // trace-pc w/o func/bb/edge implies edge.
677  if (!(CoverageFeatures & InsertionPointTypes)) {
678  if (CoverageFeatures &
680  CoverageFeatures |= CoverageEdge;
681 
682  if (CoverageFeatures & CoverageStackDepth)
683  CoverageFeatures |= CoverageFunc;
684  }
685 
686  SharedRuntime =
687  Args.hasFlag(options::OPT_shared_libsan, options::OPT_static_libsan,
688  TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia() ||
689  TC.getTriple().isOSDarwin());
690 
691  ImplicitCfiRuntime = TC.getTriple().isAndroid();
692 
693  if (AllAddedKinds & Address) {
694  NeedPIE |= TC.getTriple().isOSFuchsia();
695  if (Arg *A =
696  Args.getLastArg(options::OPT_fsanitize_address_field_padding)) {
697  StringRef S = A->getValue();
698  // Legal values are 0 and 1, 2, but in future we may add more levels.
699  if (S.getAsInteger(0, AsanFieldPadding) || AsanFieldPadding < 0 ||
700  AsanFieldPadding > 2) {
701  D.Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S;
702  }
703  }
704 
705  if (Arg *WindowsDebugRTArg =
706  Args.getLastArg(options::OPT__SLASH_MTd, options::OPT__SLASH_MT,
707  options::OPT__SLASH_MDd, options::OPT__SLASH_MD,
708  options::OPT__SLASH_LDd, options::OPT__SLASH_LD)) {
709  switch (WindowsDebugRTArg->getOption().getID()) {
710  case options::OPT__SLASH_MTd:
711  case options::OPT__SLASH_MDd:
712  case options::OPT__SLASH_LDd:
713  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
714  << WindowsDebugRTArg->getAsString(Args)
715  << lastArgumentForMask(D, Args, Address);
716  D.Diag(clang::diag::note_drv_address_sanitizer_debug_runtime);
717  }
718  }
719 
720  AsanUseAfterScope = Args.hasFlag(
721  options::OPT_fsanitize_address_use_after_scope,
722  options::OPT_fno_sanitize_address_use_after_scope, AsanUseAfterScope);
723 
724  // As a workaround for a bug in gold 2.26 and earlier, dead stripping of
725  // globals in ASan is disabled by default on ELF targets.
726  // See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
727  AsanGlobalsDeadStripping =
728  !TC.getTriple().isOSBinFormatELF() || TC.getTriple().isOSFuchsia() ||
729  Args.hasArg(options::OPT_fsanitize_address_globals_dead_stripping);
730  } else {
731  AsanUseAfterScope = false;
732  }
733 
734  if (AllAddedKinds & SafeStack) {
735  // SafeStack runtime is built into the system on Fuchsia.
736  SafeStackRuntime = !TC.getTriple().isOSFuchsia();
737  }
738 
739  // Parse -link-cxx-sanitizer flag.
740  LinkCXXRuntimes =
741  Args.hasArg(options::OPT_fsanitize_link_cxx_runtime) || D.CCCIsCXX();
742 
743  // Finally, initialize the set of available and recoverable sanitizers.
744  Sanitizers.Mask |= Kinds;
745  RecoverableSanitizers.Mask |= RecoverableKinds;
746  TrapSanitizers.Mask |= TrappingKinds;
747  assert(!(RecoverableKinds & TrappingKinds) &&
748  "Overlap between recoverable and trapping sanitizers");
749 }
750 
751 static std::string toString(const clang::SanitizerSet &Sanitizers) {
752  std::string Res;
753 #define SANITIZER(NAME, ID) \
754  if (Sanitizers.has(ID)) { \
755  if (!Res.empty()) \
756  Res += ","; \
757  Res += NAME; \
758  }
759 #include "clang/Basic/Sanitizers.def"
760  return Res;
761 }
762 
763 static void addIncludeLinkerOption(const ToolChain &TC,
764  const llvm::opt::ArgList &Args,
765  llvm::opt::ArgStringList &CmdArgs,
766  StringRef SymbolName) {
767  SmallString<64> LinkerOptionFlag;
768  LinkerOptionFlag = "--linker-option=/include:";
769  if (TC.getTriple().getArch() == llvm::Triple::x86) {
770  // Win32 mangles C function names with a '_' prefix.
771  LinkerOptionFlag += '_';
772  }
773  LinkerOptionFlag += SymbolName;
774  CmdArgs.push_back(Args.MakeArgString(LinkerOptionFlag));
775 }
776 
777 void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
778  llvm::opt::ArgStringList &CmdArgs,
779  types::ID InputType) const {
780  // NVPTX doesn't currently support sanitizers. Bailing out here means that
781  // e.g. -fsanitize=address applies only to host code, which is what we want
782  // for now.
783  if (TC.getTriple().isNVPTX())
784  return;
785 
786  // Translate available CoverageFeatures to corresponding clang-cc1 flags.
787  // Do it even if Sanitizers.empty() since some forms of coverage don't require
788  // sanitizers.
789  std::pair<int, const char *> CoverageFlags[] = {
790  std::make_pair(CoverageFunc, "-fsanitize-coverage-type=1"),
791  std::make_pair(CoverageBB, "-fsanitize-coverage-type=2"),
792  std::make_pair(CoverageEdge, "-fsanitize-coverage-type=3"),
793  std::make_pair(CoverageIndirCall, "-fsanitize-coverage-indirect-calls"),
794  std::make_pair(CoverageTraceBB, "-fsanitize-coverage-trace-bb"),
795  std::make_pair(CoverageTraceCmp, "-fsanitize-coverage-trace-cmp"),
796  std::make_pair(CoverageTraceDiv, "-fsanitize-coverage-trace-div"),
797  std::make_pair(CoverageTraceGep, "-fsanitize-coverage-trace-gep"),
798  std::make_pair(Coverage8bitCounters, "-fsanitize-coverage-8bit-counters"),
799  std::make_pair(CoverageTracePC, "-fsanitize-coverage-trace-pc"),
800  std::make_pair(CoverageTracePCGuard, "-fsanitize-coverage-trace-pc-guard"),
801  std::make_pair(CoverageInline8bitCounters, "-fsanitize-coverage-inline-8bit-counters"),
802  std::make_pair(CoveragePCTable, "-fsanitize-coverage-pc-table"),
803  std::make_pair(CoverageNoPrune, "-fsanitize-coverage-no-prune"),
804  std::make_pair(CoverageStackDepth, "-fsanitize-coverage-stack-depth")};
805  for (auto F : CoverageFlags) {
806  if (CoverageFeatures & F.first)
807  CmdArgs.push_back(F.second);
808  }
809 
810  if (TC.getTriple().isOSWindows() && needsUbsanRt()) {
811  // Instruct the code generator to embed linker directives in the object file
812  // that cause the required runtime libraries to be linked.
813  CmdArgs.push_back(Args.MakeArgString(
814  "--dependent-lib=" + TC.getCompilerRT(Args, "ubsan_standalone")));
815  if (types::isCXX(InputType))
816  CmdArgs.push_back(Args.MakeArgString(
817  "--dependent-lib=" + TC.getCompilerRT(Args, "ubsan_standalone_cxx")));
818  }
819  if (TC.getTriple().isOSWindows() && needsStatsRt()) {
820  CmdArgs.push_back(Args.MakeArgString("--dependent-lib=" +
821  TC.getCompilerRT(Args, "stats_client")));
822 
823  // The main executable must export the stats runtime.
824  // FIXME: Only exporting from the main executable (e.g. based on whether the
825  // translation unit defines main()) would save a little space, but having
826  // multiple copies of the runtime shouldn't hurt.
827  CmdArgs.push_back(Args.MakeArgString("--dependent-lib=" +
828  TC.getCompilerRT(Args, "stats")));
829  addIncludeLinkerOption(TC, Args, CmdArgs, "__sanitizer_stats_register");
830  }
831 
832  if (Sanitizers.empty())
833  return;
834  CmdArgs.push_back(Args.MakeArgString("-fsanitize=" + toString(Sanitizers)));
835 
836  if (!RecoverableSanitizers.empty())
837  CmdArgs.push_back(Args.MakeArgString("-fsanitize-recover=" +
838  toString(RecoverableSanitizers)));
839 
840  if (!TrapSanitizers.empty())
841  CmdArgs.push_back(
842  Args.MakeArgString("-fsanitize-trap=" + toString(TrapSanitizers)));
843 
844  for (const auto &BLPath : BlacklistFiles) {
845  SmallString<64> BlacklistOpt("-fsanitize-blacklist=");
846  BlacklistOpt += BLPath;
847  CmdArgs.push_back(Args.MakeArgString(BlacklistOpt));
848  }
849  for (const auto &Dep : ExtraDeps) {
850  SmallString<64> ExtraDepOpt("-fdepfile-entry=");
851  ExtraDepOpt += Dep;
852  CmdArgs.push_back(Args.MakeArgString(ExtraDepOpt));
853  }
854 
855  if (MsanTrackOrigins)
856  CmdArgs.push_back(Args.MakeArgString("-fsanitize-memory-track-origins=" +
857  Twine(MsanTrackOrigins)));
858 
859  if (MsanUseAfterDtor)
860  CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
861 
862  // FIXME: Pass these parameters as function attributes, not as -llvm flags.
863  if (!TsanMemoryAccess) {
864  CmdArgs.push_back("-mllvm");
865  CmdArgs.push_back("-tsan-instrument-memory-accesses=0");
866  CmdArgs.push_back("-mllvm");
867  CmdArgs.push_back("-tsan-instrument-memintrinsics=0");
868  }
869  if (!TsanFuncEntryExit) {
870  CmdArgs.push_back("-mllvm");
871  CmdArgs.push_back("-tsan-instrument-func-entry-exit=0");
872  }
873  if (!TsanAtomics) {
874  CmdArgs.push_back("-mllvm");
875  CmdArgs.push_back("-tsan-instrument-atomics=0");
876  }
877 
878  if (CfiCrossDso)
879  CmdArgs.push_back("-fsanitize-cfi-cross-dso");
880 
881  if (CfiICallGeneralizePointers)
882  CmdArgs.push_back("-fsanitize-cfi-icall-generalize-pointers");
883 
884  if (Stats)
885  CmdArgs.push_back("-fsanitize-stats");
886 
887  if (MinimalRuntime)
888  CmdArgs.push_back("-fsanitize-minimal-runtime");
889 
890  if (AsanFieldPadding)
891  CmdArgs.push_back(Args.MakeArgString("-fsanitize-address-field-padding=" +
892  Twine(AsanFieldPadding)));
893 
894  if (AsanUseAfterScope)
895  CmdArgs.push_back("-fsanitize-address-use-after-scope");
896 
897  if (AsanGlobalsDeadStripping)
898  CmdArgs.push_back("-fsanitize-address-globals-dead-stripping");
899 
900  // MSan: Workaround for PR16386.
901  // ASan: This is mainly to help LSan with cases such as
902  // https://github.com/google/sanitizers/issues/373
903  // We can't make this conditional on -fsanitize=leak, as that flag shouldn't
904  // affect compilation.
905  if (Sanitizers.has(Memory) || Sanitizers.has(Address))
906  CmdArgs.push_back("-fno-assume-sane-operator-new");
907 
908  // Require -fvisibility= flag on non-Windows when compiling if vptr CFI is
909  // enabled.
910  if (Sanitizers.hasOneOf(CFIClasses) && !TC.getTriple().isOSWindows() &&
911  !Args.hasArg(options::OPT_fvisibility_EQ)) {
912  TC.getDriver().Diag(clang::diag::err_drv_argument_only_allowed_with)
913  << lastArgumentForMask(TC.getDriver(), Args,
914  Sanitizers.Mask & CFIClasses)
915  << "-fvisibility=";
916  }
917 }
918 
919 SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A,
920  bool DiagnoseErrors) {
921  assert((A->getOption().matches(options::OPT_fsanitize_EQ) ||
922  A->getOption().matches(options::OPT_fno_sanitize_EQ) ||
923  A->getOption().matches(options::OPT_fsanitize_recover_EQ) ||
924  A->getOption().matches(options::OPT_fno_sanitize_recover_EQ) ||
925  A->getOption().matches(options::OPT_fsanitize_trap_EQ) ||
926  A->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) &&
927  "Invalid argument in parseArgValues!");
928  SanitizerMask Kinds = 0;
929  for (int i = 0, n = A->getNumValues(); i != n; ++i) {
930  const char *Value = A->getValue(i);
932  // Special case: don't accept -fsanitize=all.
933  if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
934  0 == strcmp("all", Value))
935  Kind = 0;
936  // Similarly, don't accept -fsanitize=efficiency-all.
937  else if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
938  0 == strcmp("efficiency-all", Value))
939  Kind = 0;
940  else
941  Kind = parseSanitizerValue(Value, /*AllowGroups=*/true);
942 
943  if (Kind)
944  Kinds |= Kind;
945  else if (DiagnoseErrors)
946  D.Diag(clang::diag::err_drv_unsupported_option_argument)
947  << A->getOption().getName() << Value;
948  }
949  return Kinds;
950 }
951 
952 int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A) {
953  assert(A->getOption().matches(options::OPT_fsanitize_coverage) ||
954  A->getOption().matches(options::OPT_fno_sanitize_coverage));
955  int Features = 0;
956  for (int i = 0, n = A->getNumValues(); i != n; ++i) {
957  const char *Value = A->getValue(i);
958  int F = llvm::StringSwitch<int>(Value)
959  .Case("func", CoverageFunc)
960  .Case("bb", CoverageBB)
961  .Case("edge", CoverageEdge)
962  .Case("indirect-calls", CoverageIndirCall)
963  .Case("trace-bb", CoverageTraceBB)
964  .Case("trace-cmp", CoverageTraceCmp)
965  .Case("trace-div", CoverageTraceDiv)
966  .Case("trace-gep", CoverageTraceGep)
967  .Case("8bit-counters", Coverage8bitCounters)
968  .Case("trace-pc", CoverageTracePC)
969  .Case("trace-pc-guard", CoverageTracePCGuard)
970  .Case("no-prune", CoverageNoPrune)
971  .Case("inline-8bit-counters", CoverageInline8bitCounters)
972  .Case("pc-table", CoveragePCTable)
973  .Case("stack-depth", CoverageStackDepth)
974  .Default(0);
975  if (F == 0)
976  D.Diag(clang::diag::err_drv_unsupported_option_argument)
977  << A->getOption().getName() << Value;
978  Features |= F;
979  }
980  return Features;
981 }
982 
983 std::string lastArgumentForMask(const Driver &D, const llvm::opt::ArgList &Args,
984  SanitizerMask Mask) {
985  for (llvm::opt::ArgList::const_reverse_iterator I = Args.rbegin(),
986  E = Args.rend();
987  I != E; ++I) {
988  const auto *Arg = *I;
989  if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) {
990  SanitizerMask AddKinds =
991  expandSanitizerGroups(parseArgValues(D, Arg, false));
992  if (AddKinds & Mask)
993  return describeSanitizeArg(Arg, Mask);
994  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_EQ)) {
995  SanitizerMask RemoveKinds =
996  expandSanitizerGroups(parseArgValues(D, Arg, false));
997  Mask &= ~RemoveKinds;
998  }
999  }
1000  llvm_unreachable("arg list didn't provide expected value");
1001 }
1002 
1003 std::string describeSanitizeArg(const llvm::opt::Arg *A, SanitizerMask Mask) {
1004  assert(A->getOption().matches(options::OPT_fsanitize_EQ)
1005  && "Invalid argument in describeSanitizerArg!");
1006 
1007  std::string Sanitizers;
1008  for (int i = 0, n = A->getNumValues(); i != n; ++i) {
1010  parseSanitizerValue(A->getValue(i), /*AllowGroups=*/true)) &
1011  Mask) {
1012  if (!Sanitizers.empty())
1013  Sanitizers += ",";
1014  Sanitizers += A->getValue(i);
1015  }
1016  }
1017 
1018  assert(!Sanitizers.empty() && "arg didn't provide expected value");
1019  return "-fsanitize=" + Sanitizers;
1020 }
bool isUsingLTO() const
Returns true if we are performing any kind of LTO.
Definition: Driver.h:519
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:110
Defines the clang::SanitizerKind enum.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
SanitizerMask Mask
Bitmask of enabled sanitizers.
Definition: Sanitizers.h:73
CoverageFeature
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
const llvm::opt::Arg * getRTTIArg() const
Definition: ToolChain.h:229
static SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A, bool DiagnoseErrors)
Parse a -fsanitize= or -fno-sanitize= argument&#39;s values, diagnosing any invalid components.
virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, bool Shared=false) const
Definition: ToolChain.cpp:355
static int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A)
Parse -f(no-)?sanitize-coverage= flag values, diagnosing any invalid components.
static void addIncludeLinkerOption(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, StringRef SymbolName)
Kind
const Driver & getDriver() const
Definition: ToolChain.h:181
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
Definition: Driver.h:174
virtual SanitizerMask getDefaultSanitizers() const
Return sanitizers which are enabled by default.
Definition: ToolChain.h:539
Dataflow Directional Tag Classes.
static void addDefaultBlacklists(const Driver &D, SanitizerMask Kinds, std::vector< std::string > &BlacklistFiles)
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups)
Parse a single value from a -fsanitize= or -fno-sanitize= value list.
Definition: Sanitizers.cpp:19
static SanitizerMask setGroupBits(SanitizerMask Kinds)
Sets group bits for every group that has at least one representative already enabled in Kinds...
uint64_t SanitizerMask
Definition: Sanitizers.h:26
bool isCXX(ID Id)
isCXX - Is this a "C++" input (C++ and Obj-C++ sources and headers).
Definition: Types.cpp:136
RTTIMode getRTTIMode() const
Definition: ToolChain.h:232
const llvm::Triple & getTriple() const
Definition: ToolChain.h:183
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:799
SanitizerMask expandSanitizerGroups(SanitizerMask Kinds)
For each sanitizer group bit set in Kinds, set the bits for sanitizers this group enables...
Definition: Sanitizers.cpp:29
static SanitizerMask parseSanitizeTrapArgs(const Driver &D, const llvm::opt::ArgList &Args)
static std::string describeSanitizeArg(const llvm::opt::Arg *A, SanitizerMask Mask)
Produce an argument string from argument A, which shows how it provides a value in Mask...
static std::string lastArgumentForMask(const Driver &D, const llvm::opt::ArgList &Args, SanitizerMask Mask)
Produce an argument string from ArgList Args, which shows how it provides some sanitizer kind from Ma...
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:88
std::string ResourceDir
The path to the compiler resource directory.
Definition: Driver.h:133