clang  15.0.0git
SanitizerArgs.cpp
Go to the documentation of this file.
1 //===--- SanitizerArgs.cpp - Arguments for sanitizer tools ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
10 #include "clang/Basic/Sanitizers.h"
11 #include "clang/Driver/Driver.h"
13 #include "clang/Driver/Options.h"
14 #include "clang/Driver/ToolChain.h"
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/Support/AArch64TargetParser.h"
18 #include "llvm/Support/Path.h"
19 #include "llvm/Support/SpecialCaseList.h"
20 #include "llvm/Support/TargetParser.h"
21 #include "llvm/Support/VirtualFileSystem.h"
22 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
23 #include <memory>
24 
25 using namespace clang;
26 using namespace clang::driver;
27 using namespace llvm::opt;
28 
30  SanitizerKind::Undefined | SanitizerKind::Integer |
31  SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
32  SanitizerKind::CFI | SanitizerKind::FloatDivideByZero |
33  SanitizerKind::ObjCCast;
35  SanitizerKind::Vptr | SanitizerKind::CFI;
36 static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
38  SanitizerKind::Function | SanitizerKind::Vptr;
39 static const SanitizerMask RequiresPIE =
40  SanitizerKind::DataFlow | SanitizerKind::HWAddress | SanitizerKind::Scudo;
42  SanitizerKind::Address | SanitizerKind::HWAddress | SanitizerKind::Thread |
43  SanitizerKind::Memory | SanitizerKind::DataFlow;
45  SanitizerKind::Address | SanitizerKind::HWAddress |
46  SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress |
47  SanitizerKind::MemtagStack | SanitizerKind::MemtagHeap |
48  SanitizerKind::Memory | SanitizerKind::KernelMemory | SanitizerKind::Leak |
49  SanitizerKind::Undefined | SanitizerKind::Integer | SanitizerKind::Bounds |
50  SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
51  SanitizerKind::DataFlow | SanitizerKind::Fuzzer |
52  SanitizerKind::FuzzerNoLink | SanitizerKind::FloatDivideByZero |
53  SanitizerKind::SafeStack | SanitizerKind::ShadowCallStack |
54  SanitizerKind::Thread | SanitizerKind::ObjCCast;
56  SanitizerKind::Undefined | SanitizerKind::Integer |
57  SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
58  SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast;
60  SanitizerKind::Unreachable | SanitizerKind::Return;
62  SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress;
63 static const SanitizerMask NeedsLTO = SanitizerKind::CFI;
65  (SanitizerKind::Undefined & ~SanitizerKind::Vptr) | SanitizerKind::Integer |
66  SanitizerKind::Nullability | SanitizerKind::LocalBounds |
67  SanitizerKind::CFI | SanitizerKind::FloatDivideByZero |
68  SanitizerKind::ObjCCast;
69 static const SanitizerMask TrappingDefault = SanitizerKind::CFI;
70 static const SanitizerMask CFIClasses =
71  SanitizerKind::CFIVCall | SanitizerKind::CFINVCall |
72  SanitizerKind::CFIMFCall | SanitizerKind::CFIDerivedCast |
73  SanitizerKind::CFIUnrelatedCast;
75  TrappingSupported | SanitizerKind::Scudo | SanitizerKind::ShadowCallStack |
76  SanitizerKind::MemtagStack | SanitizerKind::MemtagHeap;
77 
79  CoverageFunc = 1 << 0,
80  CoverageBB = 1 << 1,
81  CoverageEdge = 1 << 2,
83  CoverageTraceBB = 1 << 4, // Deprecated.
84  CoverageTraceCmp = 1 << 5,
85  CoverageTraceDiv = 1 << 6,
86  CoverageTraceGep = 1 << 7,
87  Coverage8bitCounters = 1 << 8, // Deprecated.
88  CoverageTracePC = 1 << 9,
90  CoverageNoPrune = 1 << 11,
92  CoveragePCTable = 1 << 13,
93  CoverageStackDepth = 1 << 14,
95  CoverageTraceLoads = 1 << 16,
97 };
98 
99 /// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any
100 /// invalid components. Returns a SanitizerMask.
101 static SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A,
102  bool DiagnoseErrors);
103 
104 /// Parse -f(no-)?sanitize-coverage= flag values, diagnosing any invalid
105 /// components. Returns OR of members of \c CoverageFeature enumeration.
106 static int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A,
107  bool DiagnoseErrors);
108 
109 /// Produce an argument string from ArgList \p Args, which shows how it
110 /// provides some sanitizer kind from \p Mask. For example, the argument list
111 /// "-fsanitize=thread,vptr -fsanitize=address" with mask \c NeedsUbsanRt
112 /// would produce "-fsanitize=vptr".
113 static std::string lastArgumentForMask(const Driver &D,
114  const llvm::opt::ArgList &Args,
115  SanitizerMask Mask);
116 
117 /// Produce an argument string from argument \p A, which shows how it provides
118 /// a value in \p Mask. For instance, the argument
119 /// "-fsanitize=address,alignment" with mask \c NeedsUbsanRt would produce
120 /// "-fsanitize=alignment".
121 static std::string describeSanitizeArg(const llvm::opt::Arg *A,
122  SanitizerMask Mask);
123 
124 /// Produce a string containing comma-separated names of sanitizers in \p
125 /// Sanitizers set.
126 static std::string toString(const clang::SanitizerSet &Sanitizers);
127 
129  std::vector<std::string> &SCLFiles,
130  unsigned MalformedSCLErrorDiagID,
131  bool DiagnoseErrors) {
132  if (SCLFiles.empty())
133  return;
134 
135  std::string BLError;
136  std::unique_ptr<llvm::SpecialCaseList> SCL(
137  llvm::SpecialCaseList::create(SCLFiles, D.getVFS(), BLError));
138  if (!SCL.get() && DiagnoseErrors)
139  D.Diag(MalformedSCLErrorDiagID) << BLError;
140 }
141 
142 static void addDefaultIgnorelists(const Driver &D, SanitizerMask Kinds,
143  std::vector<std::string> &IgnorelistFiles,
144  bool DiagnoseErrors) {
145  struct Ignorelist {
146  const char *File;
147  SanitizerMask Mask;
148  } Ignorelists[] = {{"asan_ignorelist.txt", SanitizerKind::Address},
149  {"hwasan_ignorelist.txt", SanitizerKind::HWAddress},
150  {"memtag_ignorelist.txt", SanitizerKind::MemTag},
151  {"msan_ignorelist.txt", SanitizerKind::Memory},
152  {"tsan_ignorelist.txt", SanitizerKind::Thread},
153  {"dfsan_abilist.txt", SanitizerKind::DataFlow},
154  {"cfi_ignorelist.txt", SanitizerKind::CFI},
155  {"ubsan_ignorelist.txt",
156  SanitizerKind::Undefined | SanitizerKind::Integer |
158  SanitizerKind::FloatDivideByZero}};
159 
160  for (auto BL : Ignorelists) {
161  if (!(Kinds & BL.Mask))
162  continue;
163 
165  llvm::sys::path::append(Path, "share", BL.File);
166  if (D.getVFS().exists(Path))
167  IgnorelistFiles.push_back(std::string(Path.str()));
168  else if (BL.Mask == SanitizerKind::CFI && DiagnoseErrors)
169  // If cfi_ignorelist.txt cannot be found in the resource dir, driver
170  // should fail.
171  D.Diag(clang::diag::err_drv_no_such_file) << Path;
172  }
174  D, IgnorelistFiles, clang::diag::err_drv_malformed_sanitizer_ignorelist,
175  DiagnoseErrors);
176 }
177 
178 /// Parse -f(no-)?sanitize-(coverage-)?(white|ignore)list argument's values,
179 /// diagnosing any invalid file paths and validating special case list format.
180 static void parseSpecialCaseListArg(const Driver &D,
181  const llvm::opt::ArgList &Args,
182  std::vector<std::string> &SCLFiles,
183  llvm::opt::OptSpecifier SCLOptionID,
184  llvm::opt::OptSpecifier NoSCLOptionID,
185  unsigned MalformedSCLErrorDiagID,
186  bool DiagnoseErrors) {
187  for (const auto *Arg : Args) {
188  // Match -fsanitize-(coverage-)?(white|ignore)list.
189  if (Arg->getOption().matches(SCLOptionID)) {
190  Arg->claim();
191  std::string SCLPath = Arg->getValue();
192  if (D.getVFS().exists(SCLPath)) {
193  SCLFiles.push_back(SCLPath);
194  } else if (DiagnoseErrors) {
195  D.Diag(clang::diag::err_drv_no_such_file) << SCLPath;
196  }
197  // Match -fno-sanitize-ignorelist.
198  } else if (Arg->getOption().matches(NoSCLOptionID)) {
199  Arg->claim();
200  SCLFiles.clear();
201  }
202  }
203  validateSpecialCaseListFormat(D, SCLFiles, MalformedSCLErrorDiagID,
204  DiagnoseErrors);
205 }
206 
207 /// Sets group bits for every group that has at least one representative already
208 /// enabled in \p Kinds.
210 #define SANITIZER(NAME, ID)
211 #define SANITIZER_GROUP(NAME, ID, ALIAS) \
212  if (Kinds & SanitizerKind::ID) \
213  Kinds |= SanitizerKind::ID##Group;
214 #include "clang/Basic/Sanitizers.def"
215  return Kinds;
216 }
217 
219  const llvm::opt::ArgList &Args,
220  bool DiagnoseErrors) {
221  SanitizerMask TrapRemove; // During the loop below, the accumulated set of
222  // sanitizers disabled by the current sanitizer
223  // argument or any argument after it.
224  SanitizerMask TrappingKinds;
225  SanitizerMask TrappingSupportedWithGroups = setGroupBits(TrappingSupported);
226 
227  for (const llvm::opt::Arg *Arg : llvm::reverse(Args)) {
228  if (Arg->getOption().matches(options::OPT_fsanitize_trap_EQ)) {
229  Arg->claim();
230  SanitizerMask Add = parseArgValues(D, Arg, true);
231  Add &= ~TrapRemove;
232  SanitizerMask InvalidValues = Add & ~TrappingSupportedWithGroups;
233  if (InvalidValues && DiagnoseErrors) {
234  SanitizerSet S;
235  S.Mask = InvalidValues;
236  D.Diag(diag::err_drv_unsupported_option_argument)
237  << Arg->getOption().getName() << toString(S);
238  }
239  TrappingKinds |= expandSanitizerGroups(Add) & ~TrapRemove;
240  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) {
241  Arg->claim();
242  TrapRemove |=
243  expandSanitizerGroups(parseArgValues(D, Arg, DiagnoseErrors));
244  }
245  }
246 
247  // Apply default trapping behavior.
248  TrappingKinds |= TrappingDefault & ~TrapRemove;
249 
250  return TrappingKinds;
251 }
252 
254  return needsFuzzer() && !needsAsanRt() && !needsTsanRt() && !needsMsanRt();
255 }
256 
258  // All of these include ubsan.
259  if (needsAsanRt() || needsMsanRt() || needsHwasanRt() || needsTsanRt() ||
260  needsDfsanRt() || needsLsanRt() || needsCfiDiagRt() ||
261  (needsScudoRt() && !requiresMinimalRuntime()))
262  return false;
263 
264  return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) ||
265  CoverageFeatures;
266 }
267 
269  return !(Sanitizers.Mask & SanitizerKind::CFI & ~TrapSanitizers.Mask) &&
270  CfiCrossDso && !ImplicitCfiRuntime;
271 }
272 
274  return (Sanitizers.Mask & SanitizerKind::CFI & ~TrapSanitizers.Mask) &&
275  CfiCrossDso && !ImplicitCfiRuntime;
276 }
277 
279  return NeedPIE || (Sanitizers.Mask & RequiresPIE);
280 }
281 
283  return static_cast<bool>(Sanitizers.Mask & NeedsUnwindTables);
284 }
285 
287  return static_cast<bool>(Sanitizers.Mask & NeedsLTO);
288 }
289 
291  const llvm::opt::ArgList &Args,
292  bool DiagnoseErrors) {
293  SanitizerMask AllRemove; // During the loop below, the accumulated set of
294  // sanitizers disabled by the current sanitizer
295  // argument or any argument after it.
296  SanitizerMask AllAddedKinds; // Mask of all sanitizers ever enabled by
297  // -fsanitize= flags (directly or via group
298  // expansion), some of which may be disabled
299  // later. Used to carefully prune
300  // unused-argument diagnostics.
301  SanitizerMask DiagnosedKinds; // All Kinds we have diagnosed up to now.
302  // Used to deduplicate diagnostics.
303  SanitizerMask Kinds;
304  const SanitizerMask Supported = setGroupBits(TC.getSupportedSanitizers());
305 
306  CfiCrossDso = Args.hasFlag(options::OPT_fsanitize_cfi_cross_dso,
307  options::OPT_fno_sanitize_cfi_cross_dso, false);
308 
309  ToolChain::RTTIMode RTTIMode = TC.getRTTIMode();
310 
311  const Driver &D = TC.getDriver();
312  SanitizerMask TrappingKinds = parseSanitizeTrapArgs(D, Args, DiagnoseErrors);
313  SanitizerMask InvalidTrappingKinds = TrappingKinds & NotAllowedWithTrap;
314 
315  MinimalRuntime =
316  Args.hasFlag(options::OPT_fsanitize_minimal_runtime,
317  options::OPT_fno_sanitize_minimal_runtime, MinimalRuntime);
318 
319  // The object size sanitizer should not be enabled at -O0.
320  Arg *OptLevel = Args.getLastArg(options::OPT_O_Group);
321  bool RemoveObjectSizeAtO0 =
322  !OptLevel || OptLevel->getOption().matches(options::OPT_O0);
323 
324  for (const llvm::opt::Arg *Arg : llvm::reverse(Args)) {
325  if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) {
326  Arg->claim();
327  SanitizerMask Add = parseArgValues(D, Arg, DiagnoseErrors);
328 
329  if (RemoveObjectSizeAtO0) {
330  AllRemove |= SanitizerKind::ObjectSize;
331 
332  // The user explicitly enabled the object size sanitizer. Warn
333  // that this does nothing at -O0.
334  if ((Add & SanitizerKind::ObjectSize) && DiagnoseErrors)
335  D.Diag(diag::warn_drv_object_size_disabled_O0)
336  << Arg->getAsString(Args);
337  }
338 
339  AllAddedKinds |= expandSanitizerGroups(Add);
340 
341  // Avoid diagnosing any sanitizer which is disabled later.
342  Add &= ~AllRemove;
343  // At this point we have not expanded groups, so any unsupported
344  // sanitizers in Add are those which have been explicitly enabled.
345  // Diagnose them.
346  if (SanitizerMask KindsToDiagnose =
347  Add & InvalidTrappingKinds & ~DiagnosedKinds) {
348  if (DiagnoseErrors) {
349  std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
350  D.Diag(diag::err_drv_argument_not_allowed_with)
351  << Desc << "-fsanitize-trap=undefined";
352  }
353  DiagnosedKinds |= KindsToDiagnose;
354  }
355  Add &= ~InvalidTrappingKinds;
356 
357  if (MinimalRuntime) {
358  if (SanitizerMask KindsToDiagnose =
359  Add & NotAllowedWithMinimalRuntime & ~DiagnosedKinds) {
360  if (DiagnoseErrors) {
361  std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
362  D.Diag(diag::err_drv_argument_not_allowed_with)
363  << Desc << "-fsanitize-minimal-runtime";
364  }
365  DiagnosedKinds |= KindsToDiagnose;
366  }
368  }
369 
370  // FIXME: Make CFI on member function calls compatible with cross-DSO CFI.
371  // There are currently two problems:
372  // - Virtual function call checks need to pass a pointer to the function
373  // address to llvm.type.test and a pointer to the address point to the
374  // diagnostic function. Currently we pass the same pointer to both
375  // places.
376  // - Non-virtual function call checks may need to check multiple type
377  // identifiers.
378  // Fixing both of those may require changes to the cross-DSO CFI
379  // interface.
380  if (CfiCrossDso && (Add & SanitizerKind::CFIMFCall & ~DiagnosedKinds)) {
381  if (DiagnoseErrors)
382  D.Diag(diag::err_drv_argument_not_allowed_with)
383  << "-fsanitize=cfi-mfcall"
384  << "-fsanitize-cfi-cross-dso";
385  Add &= ~SanitizerKind::CFIMFCall;
386  DiagnosedKinds |= SanitizerKind::CFIMFCall;
387  }
388 
389  if (SanitizerMask KindsToDiagnose = Add & ~Supported & ~DiagnosedKinds) {
390  if (DiagnoseErrors) {
391  std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
392  D.Diag(diag::err_drv_unsupported_opt_for_target)
393  << Desc << TC.getTriple().str();
394  }
395  DiagnosedKinds |= KindsToDiagnose;
396  }
397  Add &= Supported;
398 
399  // Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups
400  // so we don't error out if -fno-rtti and -fsanitize=undefined were
401  // passed.
402  if ((Add & SanitizerKind::Vptr) && (RTTIMode == ToolChain::RM_Disabled)) {
403  if (const llvm::opt::Arg *NoRTTIArg = TC.getRTTIArg()) {
404  assert(NoRTTIArg->getOption().matches(options::OPT_fno_rtti) &&
405  "RTTI disabled without -fno-rtti option?");
406  // The user explicitly passed -fno-rtti with -fsanitize=vptr, but
407  // the vptr sanitizer requires RTTI, so this is a user error.
408  if (DiagnoseErrors)
409  D.Diag(diag::err_drv_argument_not_allowed_with)
410  << "-fsanitize=vptr" << NoRTTIArg->getAsString(Args);
411  } else {
412  // The vptr sanitizer requires RTTI, but RTTI is disabled (by
413  // default). Warn that the vptr sanitizer is being disabled.
414  if (DiagnoseErrors)
415  D.Diag(diag::warn_drv_disabling_vptr_no_rtti_default);
416  }
417 
418  // Take out the Vptr sanitizer from the enabled sanitizers
419  AllRemove |= SanitizerKind::Vptr;
420  }
421 
423  // Group expansion may have enabled a sanitizer which is disabled later.
424  Add &= ~AllRemove;
425  // Silently discard any unsupported sanitizers implicitly enabled through
426  // group expansion.
427  Add &= ~InvalidTrappingKinds;
428  if (MinimalRuntime) {
430  }
431  if (CfiCrossDso)
432  Add &= ~SanitizerKind::CFIMFCall;
433  Add &= Supported;
434 
435  if (Add & SanitizerKind::Fuzzer)
436  Add |= SanitizerKind::FuzzerNoLink;
437 
438  // Enable coverage if the fuzzing flag is set.
439  if (Add & SanitizerKind::FuzzerNoLink) {
440  CoverageFeatures |= CoverageInline8bitCounters | CoverageIndirCall |
442  // Due to TLS differences, stack depth tracking is only enabled on Linux
443  if (TC.getTriple().isOSLinux())
444  CoverageFeatures |= CoverageStackDepth;
445  }
446 
447  Kinds |= Add;
448  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_EQ)) {
449  Arg->claim();
450  SanitizerMask Remove = parseArgValues(D, Arg, DiagnoseErrors);
451  AllRemove |= expandSanitizerGroups(Remove);
452  }
453  }
454 
455  std::pair<SanitizerMask, SanitizerMask> IncompatibleGroups[] = {
456  std::make_pair(SanitizerKind::Address,
457  SanitizerKind::Thread | SanitizerKind::Memory),
458  std::make_pair(SanitizerKind::Thread, SanitizerKind::Memory),
459  std::make_pair(SanitizerKind::Leak,
460  SanitizerKind::Thread | SanitizerKind::Memory),
461  std::make_pair(SanitizerKind::KernelAddress,
462  SanitizerKind::Address | SanitizerKind::Leak |
463  SanitizerKind::Thread | SanitizerKind::Memory),
464  std::make_pair(SanitizerKind::HWAddress,
465  SanitizerKind::Address | SanitizerKind::Thread |
466  SanitizerKind::Memory | SanitizerKind::KernelAddress),
467  std::make_pair(SanitizerKind::Scudo,
468  SanitizerKind::Address | SanitizerKind::HWAddress |
469  SanitizerKind::Leak | SanitizerKind::Thread |
470  SanitizerKind::Memory | SanitizerKind::KernelAddress),
471  std::make_pair(SanitizerKind::SafeStack,
472  (TC.getTriple().isOSFuchsia() ? SanitizerMask()
473  : SanitizerKind::Leak) |
474  SanitizerKind::Address | SanitizerKind::HWAddress |
475  SanitizerKind::Thread | SanitizerKind::Memory |
476  SanitizerKind::KernelAddress),
477  std::make_pair(SanitizerKind::KernelHWAddress,
478  SanitizerKind::Address | SanitizerKind::HWAddress |
479  SanitizerKind::Leak | SanitizerKind::Thread |
480  SanitizerKind::Memory | SanitizerKind::KernelAddress |
481  SanitizerKind::SafeStack),
482  std::make_pair(SanitizerKind::KernelMemory,
483  SanitizerKind::Address | SanitizerKind::HWAddress |
484  SanitizerKind::Leak | SanitizerKind::Thread |
485  SanitizerKind::Memory | SanitizerKind::KernelAddress |
486  SanitizerKind::Scudo | SanitizerKind::SafeStack),
487  std::make_pair(SanitizerKind::MemTag,
488  SanitizerKind::Address | SanitizerKind::KernelAddress |
489  SanitizerKind::HWAddress |
490  SanitizerKind::KernelHWAddress)};
491  // Enable toolchain specific default sanitizers if not explicitly disabled.
492  SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
493 
494  // Disable default sanitizers that are incompatible with explicitly requested
495  // ones.
496  for (auto G : IncompatibleGroups) {
497  SanitizerMask Group = G.first;
498  if ((Default & Group) && (Kinds & G.second))
499  Default &= ~Group;
500  }
501 
502  Kinds |= Default;
503 
504  // We disable the vptr sanitizer if it was enabled by group expansion but RTTI
505  // is disabled.
506  if ((Kinds & SanitizerKind::Vptr) && (RTTIMode == ToolChain::RM_Disabled)) {
507  Kinds &= ~SanitizerKind::Vptr;
508  }
509 
510  // Check that LTO is enabled if we need it.
511  if ((Kinds & NeedsLTO) && !D.isUsingLTO() && DiagnoseErrors) {
512  D.Diag(diag::err_drv_argument_only_allowed_with)
513  << lastArgumentForMask(D, Args, Kinds & NeedsLTO) << "-flto";
514  }
515 
516  if ((Kinds & SanitizerKind::ShadowCallStack) &&
517  ((TC.getTriple().isAArch64() &&
518  !llvm::AArch64::isX18ReservedByDefault(TC.getTriple())) ||
519  TC.getTriple().isRISCV()) &&
520  !Args.hasArg(options::OPT_ffixed_x18) && DiagnoseErrors) {
521  D.Diag(diag::err_drv_argument_only_allowed_with)
522  << lastArgumentForMask(D, Args, Kinds & SanitizerKind::ShadowCallStack)
523  << "-ffixed-x18";
524  }
525 
526  // Report error if there are non-trapping sanitizers that require
527  // c++abi-specific parts of UBSan runtime, and they are not provided by the
528  // toolchain. We don't have a good way to check the latter, so we just
529  // check if the toolchan supports vptr.
530  if (~Supported & SanitizerKind::Vptr) {
531  SanitizerMask KindsToDiagnose = Kinds & ~TrappingKinds & NeedsUbsanCxxRt;
532  // The runtime library supports the Microsoft C++ ABI, but only well enough
533  // for CFI. FIXME: Remove this once we support vptr on Windows.
534  if (TC.getTriple().isOSWindows())
535  KindsToDiagnose &= ~SanitizerKind::CFI;
536  if (KindsToDiagnose) {
537  SanitizerSet S;
538  S.Mask = KindsToDiagnose;
539  if (DiagnoseErrors)
540  D.Diag(diag::err_drv_unsupported_opt_for_target)
541  << ("-fno-sanitize-trap=" + toString(S)) << TC.getTriple().str();
542  Kinds &= ~KindsToDiagnose;
543  }
544  }
545 
546  // Warn about incompatible groups of sanitizers.
547  for (auto G : IncompatibleGroups) {
548  SanitizerMask Group = G.first;
549  if (Kinds & Group) {
550  if (SanitizerMask Incompatible = Kinds & G.second) {
551  if (DiagnoseErrors)
552  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
553  << lastArgumentForMask(D, Args, Group)
554  << lastArgumentForMask(D, Args, Incompatible);
555  Kinds &= ~Incompatible;
556  }
557  }
558  }
559  // FIXME: Currently -fsanitize=leak is silently ignored in the presence of
560  // -fsanitize=address. Perhaps it should print an error, or perhaps
561  // -f(-no)sanitize=leak should change whether leak detection is enabled by
562  // default in ASan?
563 
564  // Parse -f(no-)?sanitize-recover flags.
566  SanitizerMask DiagnosedUnrecoverableKinds;
567  SanitizerMask DiagnosedAlwaysRecoverableKinds;
568  for (const auto *Arg : Args) {
569  if (Arg->getOption().matches(options::OPT_fsanitize_recover_EQ)) {
570  SanitizerMask Add = parseArgValues(D, Arg, DiagnoseErrors);
571  // Report error if user explicitly tries to recover from unrecoverable
572  // sanitizer.
573  if (SanitizerMask KindsToDiagnose =
574  Add & Unrecoverable & ~DiagnosedUnrecoverableKinds) {
575  SanitizerSet SetToDiagnose;
576  SetToDiagnose.Mask |= KindsToDiagnose;
577  if (DiagnoseErrors)
578  D.Diag(diag::err_drv_unsupported_option_argument)
579  << Arg->getOption().getName() << toString(SetToDiagnose);
580  DiagnosedUnrecoverableKinds |= KindsToDiagnose;
581  }
582  RecoverableKinds |= expandSanitizerGroups(Add);
583  Arg->claim();
584  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_recover_EQ)) {
585  SanitizerMask Remove = parseArgValues(D, Arg, DiagnoseErrors);
586  // Report error if user explicitly tries to disable recovery from
587  // always recoverable sanitizer.
588  if (SanitizerMask KindsToDiagnose =
589  Remove & AlwaysRecoverable & ~DiagnosedAlwaysRecoverableKinds) {
590  SanitizerSet SetToDiagnose;
591  SetToDiagnose.Mask |= KindsToDiagnose;
592  if (DiagnoseErrors)
593  D.Diag(diag::err_drv_unsupported_option_argument)
594  << Arg->getOption().getName() << toString(SetToDiagnose);
595  DiagnosedAlwaysRecoverableKinds |= KindsToDiagnose;
596  }
597  RecoverableKinds &= ~expandSanitizerGroups(Remove);
598  Arg->claim();
599  }
600  }
601  RecoverableKinds &= Kinds;
602  RecoverableKinds &= ~Unrecoverable;
603 
604  TrappingKinds &= Kinds;
605  RecoverableKinds &= ~TrappingKinds;
606 
607  // Setup ignorelist files.
608  // Add default ignorelist from resource directory for activated sanitizers,
609  // and validate special case lists format.
610  if (!Args.hasArgNoClaim(options::OPT_fno_sanitize_ignorelist))
611  addDefaultIgnorelists(D, Kinds, SystemIgnorelistFiles, DiagnoseErrors);
612 
613  // Parse -f(no-)?sanitize-ignorelist options.
614  // This also validates special case lists format.
616  D, Args, UserIgnorelistFiles, options::OPT_fsanitize_ignorelist_EQ,
617  options::OPT_fno_sanitize_ignorelist,
618  clang::diag::err_drv_malformed_sanitizer_ignorelist, DiagnoseErrors);
619 
620  // Parse -f[no-]sanitize-memory-track-origins[=level] options.
621  if (AllAddedKinds & SanitizerKind::Memory) {
622  if (Arg *A =
623  Args.getLastArg(options::OPT_fsanitize_memory_track_origins_EQ,
624  options::OPT_fsanitize_memory_track_origins,
625  options::OPT_fno_sanitize_memory_track_origins)) {
626  if (A->getOption().matches(options::OPT_fsanitize_memory_track_origins)) {
627  MsanTrackOrigins = 2;
628  } else if (A->getOption().matches(
629  options::OPT_fno_sanitize_memory_track_origins)) {
630  MsanTrackOrigins = 0;
631  } else {
632  StringRef S = A->getValue();
633  if (S.getAsInteger(0, MsanTrackOrigins) || MsanTrackOrigins < 0 ||
634  MsanTrackOrigins > 2) {
635  if (DiagnoseErrors)
636  D.Diag(clang::diag::err_drv_invalid_value)
637  << A->getAsString(Args) << S;
638  }
639  }
640  }
641  MsanUseAfterDtor = Args.hasFlag(
642  options::OPT_fsanitize_memory_use_after_dtor,
643  options::OPT_fno_sanitize_memory_use_after_dtor, MsanUseAfterDtor);
644  MsanParamRetval = Args.hasFlag(
645  options::OPT_fsanitize_memory_param_retval,
646  options::OPT_fno_sanitize_memory_param_retval, MsanParamRetval);
647  NeedPIE |= !(TC.getTriple().isOSLinux() &&
648  TC.getTriple().getArch() == llvm::Triple::x86_64);
649  } else {
650  MsanUseAfterDtor = false;
651  MsanParamRetval = false;
652  }
653 
654  if (AllAddedKinds & SanitizerKind::MemTag) {
655  StringRef S =
656  Args.getLastArgValue(options::OPT_fsanitize_memtag_mode_EQ, "sync");
657  if (S == "async" || S == "sync") {
658  MemtagMode = S.str();
659  } else {
660  D.Diag(clang::diag::err_drv_invalid_value_with_suggestion)
661  << "-fsanitize-memtag-mode=" << S << "{async, sync}";
662  MemtagMode = "sync";
663  }
664  }
665 
666  if (AllAddedKinds & SanitizerKind::Thread) {
667  TsanMemoryAccess = Args.hasFlag(
668  options::OPT_fsanitize_thread_memory_access,
669  options::OPT_fno_sanitize_thread_memory_access, TsanMemoryAccess);
670  TsanFuncEntryExit = Args.hasFlag(
671  options::OPT_fsanitize_thread_func_entry_exit,
672  options::OPT_fno_sanitize_thread_func_entry_exit, TsanFuncEntryExit);
673  TsanAtomics =
674  Args.hasFlag(options::OPT_fsanitize_thread_atomics,
675  options::OPT_fno_sanitize_thread_atomics, TsanAtomics);
676  }
677 
678  if (AllAddedKinds & SanitizerKind::CFI) {
679  // Without PIE, external function address may resolve to a PLT record, which
680  // can not be verified by the target module.
681  NeedPIE |= CfiCrossDso;
682  CfiICallGeneralizePointers =
683  Args.hasArg(options::OPT_fsanitize_cfi_icall_generalize_pointers);
684 
685  if (CfiCrossDso && CfiICallGeneralizePointers && DiagnoseErrors)
686  D.Diag(diag::err_drv_argument_not_allowed_with)
687  << "-fsanitize-cfi-cross-dso"
688  << "-fsanitize-cfi-icall-generalize-pointers";
689 
690  CfiCanonicalJumpTables =
691  Args.hasFlag(options::OPT_fsanitize_cfi_canonical_jump_tables,
692  options::OPT_fno_sanitize_cfi_canonical_jump_tables, true);
693  }
694 
695  Stats = Args.hasFlag(options::OPT_fsanitize_stats,
696  options::OPT_fno_sanitize_stats, false);
697 
698  if (MinimalRuntime) {
699  SanitizerMask IncompatibleMask =
701  if (IncompatibleMask && DiagnoseErrors)
702  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
703  << "-fsanitize-minimal-runtime"
704  << lastArgumentForMask(D, Args, IncompatibleMask);
705 
706  SanitizerMask NonTrappingCfi = Kinds & SanitizerKind::CFI & ~TrappingKinds;
707  if (NonTrappingCfi && DiagnoseErrors)
708  D.Diag(clang::diag::err_drv_argument_only_allowed_with)
709  << "fsanitize-minimal-runtime"
710  << "fsanitize-trap=cfi";
711  }
712 
713  // Parse -f(no-)?sanitize-coverage flags if coverage is supported by the
714  // enabled sanitizers.
715  for (const auto *Arg : Args) {
716  if (Arg->getOption().matches(options::OPT_fsanitize_coverage)) {
717  int LegacySanitizeCoverage;
718  if (Arg->getNumValues() == 1 &&
719  !StringRef(Arg->getValue(0))
720  .getAsInteger(0, LegacySanitizeCoverage)) {
721  CoverageFeatures = 0;
722  Arg->claim();
723  if (LegacySanitizeCoverage != 0 && DiagnoseErrors) {
724  D.Diag(diag::warn_drv_deprecated_arg)
725  << Arg->getAsString(Args) << "-fsanitize-coverage=trace-pc-guard";
726  }
727  continue;
728  }
729  CoverageFeatures |= parseCoverageFeatures(D, Arg, DiagnoseErrors);
730 
731  // Disable coverage and not claim the flags if there is at least one
732  // non-supporting sanitizer.
733  if (!(AllAddedKinds & ~AllRemove & ~setGroupBits(SupportsCoverage))) {
734  Arg->claim();
735  } else {
736  CoverageFeatures = 0;
737  }
738  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_coverage)) {
739  Arg->claim();
740  CoverageFeatures &= ~parseCoverageFeatures(D, Arg, DiagnoseErrors);
741  }
742  }
743  // Choose at most one coverage type: function, bb, or edge.
744  if (DiagnoseErrors) {
745  if ((CoverageFeatures & CoverageFunc) && (CoverageFeatures & CoverageBB))
746  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
747  << "-fsanitize-coverage=func"
748  << "-fsanitize-coverage=bb";
749  if ((CoverageFeatures & CoverageFunc) && (CoverageFeatures & CoverageEdge))
750  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
751  << "-fsanitize-coverage=func"
752  << "-fsanitize-coverage=edge";
753  if ((CoverageFeatures & CoverageBB) && (CoverageFeatures & CoverageEdge))
754  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
755  << "-fsanitize-coverage=bb"
756  << "-fsanitize-coverage=edge";
757  // Basic block tracing and 8-bit counters require some type of coverage
758  // enabled.
759  if (CoverageFeatures & CoverageTraceBB)
760  D.Diag(clang::diag::warn_drv_deprecated_arg)
761  << "-fsanitize-coverage=trace-bb"
762  << "-fsanitize-coverage=trace-pc-guard";
763  if (CoverageFeatures & Coverage8bitCounters)
764  D.Diag(clang::diag::warn_drv_deprecated_arg)
765  << "-fsanitize-coverage=8bit-counters"
766  << "-fsanitize-coverage=trace-pc-guard";
767  }
768 
769  int InsertionPointTypes = CoverageFunc | CoverageBB | CoverageEdge;
770  int InstrumentationTypes = CoverageTracePC | CoverageTracePCGuard |
773  if ((CoverageFeatures & InsertionPointTypes) &&
774  !(CoverageFeatures & InstrumentationTypes) && DiagnoseErrors) {
775  D.Diag(clang::diag::warn_drv_deprecated_arg)
776  << "-fsanitize-coverage=[func|bb|edge]"
777  << "-fsanitize-coverage=[func|bb|edge],[trace-pc-guard|trace-pc]";
778  }
779 
780  // trace-pc w/o func/bb/edge implies edge.
781  if (!(CoverageFeatures & InsertionPointTypes)) {
782  if (CoverageFeatures &
785  CoverageFeatures |= CoverageEdge;
786 
787  if (CoverageFeatures & CoverageStackDepth)
788  CoverageFeatures |= CoverageFunc;
789  }
790 
791  // Parse -fsanitize-coverage-(ignore|white)list options if coverage enabled.
792  // This also validates special case lists format.
793  // Here, OptSpecifier() acts as a never-matching command-line argument.
794  // So, there is no way to clear coverage lists but you can append to them.
795  if (CoverageFeatures) {
797  D, Args, CoverageAllowlistFiles,
798  options::OPT_fsanitize_coverage_allowlist, OptSpecifier(),
799  clang::diag::err_drv_malformed_sanitizer_coverage_allowlist,
800  DiagnoseErrors);
802  D, Args, CoverageIgnorelistFiles,
803  options::OPT_fsanitize_coverage_ignorelist, OptSpecifier(),
804  clang::diag::err_drv_malformed_sanitizer_coverage_ignorelist,
805  DiagnoseErrors);
806  }
807 
808  SharedRuntime =
809  Args.hasFlag(options::OPT_shared_libsan, options::OPT_static_libsan,
810  TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia() ||
811  TC.getTriple().isOSDarwin());
812 
813  ImplicitCfiRuntime = TC.getTriple().isAndroid();
814 
815  if (AllAddedKinds & SanitizerKind::Address) {
816  NeedPIE |= TC.getTriple().isOSFuchsia();
817  if (Arg *A =
818  Args.getLastArg(options::OPT_fsanitize_address_field_padding)) {
819  StringRef S = A->getValue();
820  // Legal values are 0 and 1, 2, but in future we may add more levels.
821  if ((S.getAsInteger(0, AsanFieldPadding) || AsanFieldPadding < 0 ||
822  AsanFieldPadding > 2) &&
823  DiagnoseErrors) {
824  D.Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S;
825  }
826  }
827 
828  if (Arg *WindowsDebugRTArg =
829  Args.getLastArg(options::OPT__SLASH_MTd, options::OPT__SLASH_MT,
830  options::OPT__SLASH_MDd, options::OPT__SLASH_MD,
831  options::OPT__SLASH_LDd, options::OPT__SLASH_LD)) {
832  switch (WindowsDebugRTArg->getOption().getID()) {
833  case options::OPT__SLASH_MTd:
834  case options::OPT__SLASH_MDd:
835  case options::OPT__SLASH_LDd:
836  if (DiagnoseErrors) {
837  D.Diag(clang::diag::err_drv_argument_not_allowed_with)
838  << WindowsDebugRTArg->getAsString(Args)
839  << lastArgumentForMask(D, Args, SanitizerKind::Address);
840  D.Diag(clang::diag::note_drv_address_sanitizer_debug_runtime);
841  }
842  }
843  }
844 
845  AsanUseAfterScope = Args.hasFlag(
846  options::OPT_fsanitize_address_use_after_scope,
847  options::OPT_fno_sanitize_address_use_after_scope, AsanUseAfterScope);
848 
849  AsanPoisonCustomArrayCookie = Args.hasFlag(
850  options::OPT_fsanitize_address_poison_custom_array_cookie,
851  options::OPT_fno_sanitize_address_poison_custom_array_cookie,
852  AsanPoisonCustomArrayCookie);
853 
854  AsanOutlineInstrumentation =
855  Args.hasFlag(options::OPT_fsanitize_address_outline_instrumentation,
856  options::OPT_fno_sanitize_address_outline_instrumentation,
857  AsanOutlineInstrumentation);
858 
859  // As a workaround for a bug in gold 2.26 and earlier, dead stripping of
860  // globals in ASan is disabled by default on most ELF targets.
861  // See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
862  AsanGlobalsDeadStripping = Args.hasFlag(
863  options::OPT_fsanitize_address_globals_dead_stripping,
864  options::OPT_fno_sanitize_address_globals_dead_stripping,
865  !TC.getTriple().isOSBinFormatELF() || TC.getTriple().isOSFuchsia() ||
866  TC.getTriple().isPS());
867 
868  AsanUseOdrIndicator =
869  Args.hasFlag(options::OPT_fsanitize_address_use_odr_indicator,
870  options::OPT_fno_sanitize_address_use_odr_indicator,
871  AsanUseOdrIndicator);
872 
873  if (AllAddedKinds & SanitizerKind::PointerCompare & ~AllRemove) {
874  AsanInvalidPointerCmp = true;
875  }
876 
877  if (AllAddedKinds & SanitizerKind::PointerSubtract & ~AllRemove) {
878  AsanInvalidPointerSub = true;
879  }
880 
881  if (TC.getTriple().isOSDarwin() &&
882  (Args.hasArg(options::OPT_mkernel) ||
883  Args.hasArg(options::OPT_fapple_kext))) {
884  AsanDtorKind = llvm::AsanDtorKind::None;
885  }
886 
887  if (const auto *Arg =
888  Args.getLastArg(options::OPT_sanitize_address_destructor_EQ)) {
889  auto parsedAsanDtorKind = AsanDtorKindFromString(Arg->getValue());
890  if (parsedAsanDtorKind == llvm::AsanDtorKind::Invalid && DiagnoseErrors) {
891  TC.getDriver().Diag(clang::diag::err_drv_unsupported_option_argument)
892  << Arg->getOption().getName() << Arg->getValue();
893  }
894  AsanDtorKind = parsedAsanDtorKind;
895  }
896 
897  if (const auto *Arg = Args.getLastArg(
898  options::OPT_sanitize_address_use_after_return_EQ)) {
899  auto parsedAsanUseAfterReturn =
901  if (parsedAsanUseAfterReturn ==
903  DiagnoseErrors) {
904  TC.getDriver().Diag(clang::diag::err_drv_unsupported_option_argument)
905  << Arg->getOption().getName() << Arg->getValue();
906  }
907  AsanUseAfterReturn = parsedAsanUseAfterReturn;
908  }
909 
910  } else {
911  AsanUseAfterScope = false;
912  // -fsanitize=pointer-compare/pointer-subtract requires -fsanitize=address.
913  SanitizerMask DetectInvalidPointerPairs =
914  SanitizerKind::PointerCompare | SanitizerKind::PointerSubtract;
915  if ((AllAddedKinds & DetectInvalidPointerPairs & ~AllRemove) &&
916  DiagnoseErrors) {
917  TC.getDriver().Diag(clang::diag::err_drv_argument_only_allowed_with)
918  << lastArgumentForMask(D, Args,
919  SanitizerKind::PointerCompare |
920  SanitizerKind::PointerSubtract)
921  << "-fsanitize=address";
922  }
923  }
924 
925  if (AllAddedKinds & SanitizerKind::HWAddress) {
926  if (Arg *HwasanAbiArg =
927  Args.getLastArg(options::OPT_fsanitize_hwaddress_abi_EQ)) {
928  HwasanAbi = HwasanAbiArg->getValue();
929  if (HwasanAbi != "platform" && HwasanAbi != "interceptor" &&
930  DiagnoseErrors)
931  D.Diag(clang::diag::err_drv_invalid_value)
932  << HwasanAbiArg->getAsString(Args) << HwasanAbi;
933  } else {
934  HwasanAbi = "interceptor";
935  }
936  if (TC.getTriple().getArch() == llvm::Triple::x86_64)
937  HwasanUseAliases = Args.hasFlag(
938  options::OPT_fsanitize_hwaddress_experimental_aliasing,
939  options::OPT_fno_sanitize_hwaddress_experimental_aliasing,
940  HwasanUseAliases);
941  }
942 
943  if (AllAddedKinds & SanitizerKind::SafeStack) {
944  // SafeStack runtime is built into the system on Android and Fuchsia.
945  SafeStackRuntime =
946  !TC.getTriple().isAndroid() && !TC.getTriple().isOSFuchsia();
947  }
948 
949  LinkRuntimes =
950  Args.hasFlag(options::OPT_fsanitize_link_runtime,
951  options::OPT_fno_sanitize_link_runtime, LinkRuntimes);
952 
953  // Parse -link-cxx-sanitizer flag.
954  LinkCXXRuntimes = Args.hasArg(options::OPT_fsanitize_link_cxx_runtime,
955  options::OPT_fno_sanitize_link_cxx_runtime,
956  LinkCXXRuntimes) ||
957  D.CCCIsCXX();
958 
959  NeedsMemProfRt = Args.hasFlag(options::OPT_fmemory_profile,
960  options::OPT_fmemory_profile_EQ,
961  options::OPT_fno_memory_profile, false);
962 
963  // Finally, initialize the set of available and recoverable sanitizers.
964  Sanitizers.Mask |= Kinds;
965  RecoverableSanitizers.Mask |= RecoverableKinds;
966  TrapSanitizers.Mask |= TrappingKinds;
967  assert(!(RecoverableKinds & TrappingKinds) &&
968  "Overlap between recoverable and trapping sanitizers");
969 }
970 
971 static std::string toString(const clang::SanitizerSet &Sanitizers) {
972  std::string Res;
973 #define SANITIZER(NAME, ID) \
974  if (Sanitizers.has(SanitizerKind::ID)) { \
975  if (!Res.empty()) \
976  Res += ","; \
977  Res += NAME; \
978  }
979 #include "clang/Basic/Sanitizers.def"
980  return Res;
981 }
982 
983 static void addSpecialCaseListOpt(const llvm::opt::ArgList &Args,
984  llvm::opt::ArgStringList &CmdArgs,
985  const char *SCLOptFlag,
986  const std::vector<std::string> &SCLFiles) {
987  for (const auto &SCLPath : SCLFiles) {
988  SmallString<64> SCLOpt(SCLOptFlag);
989  SCLOpt += SCLPath;
990  CmdArgs.push_back(Args.MakeArgString(SCLOpt));
991  }
992 }
993 
994 static void addIncludeLinkerOption(const ToolChain &TC,
995  const llvm::opt::ArgList &Args,
996  llvm::opt::ArgStringList &CmdArgs,
997  StringRef SymbolName) {
998  SmallString<64> LinkerOptionFlag;
999  LinkerOptionFlag = "--linker-option=/include:";
1000  if (TC.getTriple().getArch() == llvm::Triple::x86) {
1001  // Win32 mangles C function names with a '_' prefix.
1002  LinkerOptionFlag += '_';
1003  }
1004  LinkerOptionFlag += SymbolName;
1005  CmdArgs.push_back(Args.MakeArgString(LinkerOptionFlag));
1006 }
1007 
1008 static bool hasTargetFeatureMTE(const llvm::opt::ArgStringList &CmdArgs) {
1009  for (auto Start = CmdArgs.begin(), End = CmdArgs.end(); Start != End;
1010  ++Start) {
1011  auto It = std::find(Start, End, StringRef("+mte"));
1012  if (It == End)
1013  break;
1014  if (It > Start && *std::prev(It) == StringRef("-target-feature"))
1015  return true;
1016  Start = It;
1017  }
1018  return false;
1019 }
1020 
1021 void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
1022  llvm::opt::ArgStringList &CmdArgs,
1023  types::ID InputType) const {
1024  // NVPTX doesn't currently support sanitizers. Bailing out here means
1025  // that e.g. -fsanitize=address applies only to host code, which is what we
1026  // want for now.
1027  //
1028  // AMDGPU sanitizer support is experimental and controlled by -fgpu-sanitize.
1029  if (TC.getTriple().isNVPTX() ||
1030  (TC.getTriple().isAMDGPU() &&
1031  !Args.hasFlag(options::OPT_fgpu_sanitize, options::OPT_fno_gpu_sanitize,
1032  true)))
1033  return;
1034 
1035  // Translate available CoverageFeatures to corresponding clang-cc1 flags.
1036  // Do it even if Sanitizers.empty() since some forms of coverage don't require
1037  // sanitizers.
1038  std::pair<int, const char *> CoverageFlags[] = {
1039  std::make_pair(CoverageFunc, "-fsanitize-coverage-type=1"),
1040  std::make_pair(CoverageBB, "-fsanitize-coverage-type=2"),
1041  std::make_pair(CoverageEdge, "-fsanitize-coverage-type=3"),
1042  std::make_pair(CoverageIndirCall, "-fsanitize-coverage-indirect-calls"),
1043  std::make_pair(CoverageTraceBB, "-fsanitize-coverage-trace-bb"),
1044  std::make_pair(CoverageTraceCmp, "-fsanitize-coverage-trace-cmp"),
1045  std::make_pair(CoverageTraceDiv, "-fsanitize-coverage-trace-div"),
1046  std::make_pair(CoverageTraceGep, "-fsanitize-coverage-trace-gep"),
1047  std::make_pair(Coverage8bitCounters, "-fsanitize-coverage-8bit-counters"),
1048  std::make_pair(CoverageTracePC, "-fsanitize-coverage-trace-pc"),
1049  std::make_pair(CoverageTracePCGuard,
1050  "-fsanitize-coverage-trace-pc-guard"),
1051  std::make_pair(CoverageInline8bitCounters,
1052  "-fsanitize-coverage-inline-8bit-counters"),
1053  std::make_pair(CoverageInlineBoolFlag,
1054  "-fsanitize-coverage-inline-bool-flag"),
1055  std::make_pair(CoveragePCTable, "-fsanitize-coverage-pc-table"),
1056  std::make_pair(CoverageNoPrune, "-fsanitize-coverage-no-prune"),
1057  std::make_pair(CoverageStackDepth, "-fsanitize-coverage-stack-depth"),
1058  std::make_pair(CoverageTraceLoads, "-fsanitize-coverage-trace-loads"),
1059  std::make_pair(CoverageTraceStores, "-fsanitize-coverage-trace-stores")};
1060  for (auto F : CoverageFlags) {
1061  if (CoverageFeatures & F.first)
1062  CmdArgs.push_back(F.second);
1063  }
1065  Args, CmdArgs, "-fsanitize-coverage-allowlist=", CoverageAllowlistFiles);
1066  addSpecialCaseListOpt(Args, CmdArgs, "-fsanitize-coverage-ignorelist=",
1067  CoverageIgnorelistFiles);
1068 
1069  if (TC.getTriple().isOSWindows() && needsUbsanRt()) {
1070  // Instruct the code generator to embed linker directives in the object file
1071  // that cause the required runtime libraries to be linked.
1072  CmdArgs.push_back(
1073  Args.MakeArgString("--dependent-lib=" +
1074  TC.getCompilerRTBasename(Args, "ubsan_standalone")));
1075  if (types::isCXX(InputType))
1076  CmdArgs.push_back(Args.MakeArgString(
1077  "--dependent-lib=" +
1078  TC.getCompilerRTBasename(Args, "ubsan_standalone_cxx")));
1079  }
1080  if (TC.getTriple().isOSWindows() && needsStatsRt()) {
1081  CmdArgs.push_back(Args.MakeArgString(
1082  "--dependent-lib=" + TC.getCompilerRTBasename(Args, "stats_client")));
1083 
1084  // The main executable must export the stats runtime.
1085  // FIXME: Only exporting from the main executable (e.g. based on whether the
1086  // translation unit defines main()) would save a little space, but having
1087  // multiple copies of the runtime shouldn't hurt.
1088  CmdArgs.push_back(Args.MakeArgString(
1089  "--dependent-lib=" + TC.getCompilerRTBasename(Args, "stats")));
1090  addIncludeLinkerOption(TC, Args, CmdArgs, "__sanitizer_stats_register");
1091  }
1092 
1093  if (Sanitizers.empty())
1094  return;
1095  CmdArgs.push_back(Args.MakeArgString("-fsanitize=" + toString(Sanitizers)));
1096 
1097  if (!RecoverableSanitizers.empty())
1098  CmdArgs.push_back(Args.MakeArgString("-fsanitize-recover=" +
1099  toString(RecoverableSanitizers)));
1100 
1101  if (!TrapSanitizers.empty())
1102  CmdArgs.push_back(
1103  Args.MakeArgString("-fsanitize-trap=" + toString(TrapSanitizers)));
1104 
1105  addSpecialCaseListOpt(Args, CmdArgs,
1106  "-fsanitize-ignorelist=", UserIgnorelistFiles);
1107  addSpecialCaseListOpt(Args, CmdArgs,
1108  "-fsanitize-system-ignorelist=", SystemIgnorelistFiles);
1109 
1110  if (MsanTrackOrigins)
1111  CmdArgs.push_back(Args.MakeArgString("-fsanitize-memory-track-origins=" +
1112  Twine(MsanTrackOrigins)));
1113 
1114  if (MsanUseAfterDtor)
1115  CmdArgs.push_back("-fsanitize-memory-use-after-dtor");
1116 
1117  if (MsanParamRetval)
1118  CmdArgs.push_back("-fsanitize-memory-param-retval");
1119 
1120  // FIXME: Pass these parameters as function attributes, not as -llvm flags.
1121  if (!TsanMemoryAccess) {
1122  CmdArgs.push_back("-mllvm");
1123  CmdArgs.push_back("-tsan-instrument-memory-accesses=0");
1124  CmdArgs.push_back("-mllvm");
1125  CmdArgs.push_back("-tsan-instrument-memintrinsics=0");
1126  }
1127  if (!TsanFuncEntryExit) {
1128  CmdArgs.push_back("-mllvm");
1129  CmdArgs.push_back("-tsan-instrument-func-entry-exit=0");
1130  }
1131  if (!TsanAtomics) {
1132  CmdArgs.push_back("-mllvm");
1133  CmdArgs.push_back("-tsan-instrument-atomics=0");
1134  }
1135 
1136  if (HwasanUseAliases) {
1137  CmdArgs.push_back("-mllvm");
1138  CmdArgs.push_back("-hwasan-experimental-use-page-aliases=1");
1139  }
1140 
1141  if (CfiCrossDso)
1142  CmdArgs.push_back("-fsanitize-cfi-cross-dso");
1143 
1144  if (CfiICallGeneralizePointers)
1145  CmdArgs.push_back("-fsanitize-cfi-icall-generalize-pointers");
1146 
1147  if (CfiCanonicalJumpTables)
1148  CmdArgs.push_back("-fsanitize-cfi-canonical-jump-tables");
1149 
1150  if (Stats)
1151  CmdArgs.push_back("-fsanitize-stats");
1152 
1153  if (MinimalRuntime)
1154  CmdArgs.push_back("-fsanitize-minimal-runtime");
1155 
1156  if (AsanFieldPadding)
1157  CmdArgs.push_back(Args.MakeArgString("-fsanitize-address-field-padding=" +
1158  Twine(AsanFieldPadding)));
1159 
1160  if (AsanUseAfterScope)
1161  CmdArgs.push_back("-fsanitize-address-use-after-scope");
1162 
1163  if (AsanPoisonCustomArrayCookie)
1164  CmdArgs.push_back("-fsanitize-address-poison-custom-array-cookie");
1165 
1166  if (AsanGlobalsDeadStripping)
1167  CmdArgs.push_back("-fsanitize-address-globals-dead-stripping");
1168 
1169  if (AsanUseOdrIndicator)
1170  CmdArgs.push_back("-fsanitize-address-use-odr-indicator");
1171 
1172  if (AsanInvalidPointerCmp) {
1173  CmdArgs.push_back("-mllvm");
1174  CmdArgs.push_back("-asan-detect-invalid-pointer-cmp");
1175  }
1176 
1177  if (AsanInvalidPointerSub) {
1178  CmdArgs.push_back("-mllvm");
1179  CmdArgs.push_back("-asan-detect-invalid-pointer-sub");
1180  }
1181 
1182  if (AsanOutlineInstrumentation) {
1183  CmdArgs.push_back("-mllvm");
1184  CmdArgs.push_back("-asan-instrumentation-with-call-threshold=0");
1185  }
1186 
1187  // Only pass the option to the frontend if the user requested,
1188  // otherwise the frontend will just use the codegen default.
1189  if (AsanDtorKind != llvm::AsanDtorKind::Invalid) {
1190  CmdArgs.push_back(Args.MakeArgString("-fsanitize-address-destructor=" +
1191  AsanDtorKindToString(AsanDtorKind)));
1192  }
1193 
1194  if (AsanUseAfterReturn != llvm::AsanDetectStackUseAfterReturnMode::Invalid) {
1195  CmdArgs.push_back(Args.MakeArgString(
1196  "-fsanitize-address-use-after-return=" +
1197  AsanDetectStackUseAfterReturnModeToString(AsanUseAfterReturn)));
1198  }
1199 
1200  if (!HwasanAbi.empty()) {
1201  CmdArgs.push_back("-default-function-attr");
1202  CmdArgs.push_back(Args.MakeArgString("hwasan-abi=" + HwasanAbi));
1203  }
1204 
1205  if (Sanitizers.has(SanitizerKind::HWAddress) && !HwasanUseAliases) {
1206  CmdArgs.push_back("-target-feature");
1207  CmdArgs.push_back("+tagged-globals");
1208  }
1209 
1210  // MSan: Workaround for PR16386.
1211  // ASan: This is mainly to help LSan with cases such as
1212  // https://github.com/google/sanitizers/issues/373
1213  // We can't make this conditional on -fsanitize=leak, as that flag shouldn't
1214  // affect compilation.
1215  if (Sanitizers.has(SanitizerKind::Memory) ||
1216  Sanitizers.has(SanitizerKind::Address))
1217  CmdArgs.push_back("-fno-assume-sane-operator-new");
1218 
1219  // libFuzzer wants to intercept calls to certain library functions, so the
1220  // following -fno-builtin-* flags force the compiler to emit interposable
1221  // libcalls to these functions. Other sanitizers effectively do the same thing
1222  // by marking all library call sites with NoBuiltin attribute in their LLVM
1223  // pass. (see llvm::maybeMarkSanitizerLibraryCallNoBuiltin)
1224  if (Sanitizers.has(SanitizerKind::FuzzerNoLink)) {
1225  CmdArgs.push_back("-fno-builtin-bcmp");
1226  CmdArgs.push_back("-fno-builtin-memcmp");
1227  CmdArgs.push_back("-fno-builtin-strncmp");
1228  CmdArgs.push_back("-fno-builtin-strcmp");
1229  CmdArgs.push_back("-fno-builtin-strncasecmp");
1230  CmdArgs.push_back("-fno-builtin-strcasecmp");
1231  CmdArgs.push_back("-fno-builtin-strstr");
1232  CmdArgs.push_back("-fno-builtin-strcasestr");
1233  CmdArgs.push_back("-fno-builtin-memmem");
1234  }
1235 
1236  // Require -fvisibility= flag on non-Windows when compiling if vptr CFI is
1237  // enabled.
1238  if (Sanitizers.hasOneOf(CFIClasses) && !TC.getTriple().isOSWindows() &&
1239  !Args.hasArg(options::OPT_fvisibility_EQ)) {
1240  TC.getDriver().Diag(clang::diag::err_drv_argument_only_allowed_with)
1241  << lastArgumentForMask(TC.getDriver(), Args,
1242  Sanitizers.Mask & CFIClasses)
1243  << "-fvisibility=";
1244  }
1245 
1246  if (Sanitizers.has(SanitizerKind::MemtagStack) &&
1247  !hasTargetFeatureMTE(CmdArgs))
1248  TC.getDriver().Diag(diag::err_stack_tagging_requires_hardware_feature);
1249 }
1250 
1251 SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A,
1252  bool DiagnoseErrors) {
1253  assert((A->getOption().matches(options::OPT_fsanitize_EQ) ||
1254  A->getOption().matches(options::OPT_fno_sanitize_EQ) ||
1255  A->getOption().matches(options::OPT_fsanitize_recover_EQ) ||
1256  A->getOption().matches(options::OPT_fno_sanitize_recover_EQ) ||
1257  A->getOption().matches(options::OPT_fsanitize_trap_EQ) ||
1258  A->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) &&
1259  "Invalid argument in parseArgValues!");
1260  SanitizerMask Kinds;
1261  for (int i = 0, n = A->getNumValues(); i != n; ++i) {
1262  const char *Value = A->getValue(i);
1264  // Special case: don't accept -fsanitize=all.
1265  if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
1266  0 == strcmp("all", Value))
1267  Kind = SanitizerMask();
1268  else
1269  Kind = parseSanitizerValue(Value, /*AllowGroups=*/true);
1270 
1271  if (Kind)
1272  Kinds |= Kind;
1273  else if (DiagnoseErrors)
1274  D.Diag(clang::diag::err_drv_unsupported_option_argument)
1275  << A->getOption().getName() << Value;
1276  }
1277  return Kinds;
1278 }
1279 
1280 int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A,
1281  bool DiagnoseErrors) {
1282  assert(A->getOption().matches(options::OPT_fsanitize_coverage) ||
1283  A->getOption().matches(options::OPT_fno_sanitize_coverage));
1284  int Features = 0;
1285  for (int i = 0, n = A->getNumValues(); i != n; ++i) {
1286  const char *Value = A->getValue(i);
1287  int F = llvm::StringSwitch<int>(Value)
1288  .Case("func", CoverageFunc)
1289  .Case("bb", CoverageBB)
1290  .Case("edge", CoverageEdge)
1291  .Case("indirect-calls", CoverageIndirCall)
1292  .Case("trace-bb", CoverageTraceBB)
1293  .Case("trace-cmp", CoverageTraceCmp)
1294  .Case("trace-div", CoverageTraceDiv)
1295  .Case("trace-gep", CoverageTraceGep)
1296  .Case("8bit-counters", Coverage8bitCounters)
1297  .Case("trace-pc", CoverageTracePC)
1298  .Case("trace-pc-guard", CoverageTracePCGuard)
1299  .Case("no-prune", CoverageNoPrune)
1300  .Case("inline-8bit-counters", CoverageInline8bitCounters)
1301  .Case("inline-bool-flag", CoverageInlineBoolFlag)
1302  .Case("pc-table", CoveragePCTable)
1303  .Case("stack-depth", CoverageStackDepth)
1304  .Case("trace-loads", CoverageTraceLoads)
1305  .Case("trace-stores", CoverageTraceStores)
1306  .Default(0);
1307  if (F == 0 && DiagnoseErrors)
1308  D.Diag(clang::diag::err_drv_unsupported_option_argument)
1309  << A->getOption().getName() << Value;
1310  Features |= F;
1311  }
1312  return Features;
1313 }
1314 
1315 std::string lastArgumentForMask(const Driver &D, const llvm::opt::ArgList &Args,
1316  SanitizerMask Mask) {
1317  for (llvm::opt::ArgList::const_reverse_iterator I = Args.rbegin(),
1318  E = Args.rend();
1319  I != E; ++I) {
1320  const auto *Arg = *I;
1321  if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) {
1322  SanitizerMask AddKinds =
1323  expandSanitizerGroups(parseArgValues(D, Arg, false));
1324  if (AddKinds & Mask)
1325  return describeSanitizeArg(Arg, Mask);
1326  } else if (Arg->getOption().matches(options::OPT_fno_sanitize_EQ)) {
1327  SanitizerMask RemoveKinds =
1328  expandSanitizerGroups(parseArgValues(D, Arg, false));
1329  Mask &= ~RemoveKinds;
1330  }
1331  }
1332  llvm_unreachable("arg list didn't provide expected value");
1333 }
1334 
1335 std::string describeSanitizeArg(const llvm::opt::Arg *A, SanitizerMask Mask) {
1336  assert(A->getOption().matches(options::OPT_fsanitize_EQ) &&
1337  "Invalid argument in describeSanitizerArg!");
1338 
1339  std::string Sanitizers;
1340  for (int i = 0, n = A->getNumValues(); i != n; ++i) {
1342  parseSanitizerValue(A->getValue(i), /*AllowGroups=*/true)) &
1343  Mask) {
1344  if (!Sanitizers.empty())
1345  Sanitizers += ",";
1346  Sanitizers += A->getValue(i);
1347  }
1348  }
1349 
1350  assert(!Sanitizers.empty() && "arg didn't provide expected value");
1351  return "-fsanitize=" + Sanitizers;
1352 }
clang::driver::SanitizerArgs::needsUnwindTables
bool needsUnwindTables() const
Definition: SanitizerArgs.cpp:282
clang::driver::SanitizerArgs::SanitizerArgs
SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, bool DiagnoseErrors=true)
Parses the sanitizer arguments from an argument list.
Definition: SanitizerArgs.cpp:290
CoverageStackDepth
@ CoverageStackDepth
Definition: SanitizerArgs.cpp:93
parseSanitizeTrapArgs
static SanitizerMask parseSanitizeTrapArgs(const Driver &D, const llvm::opt::ArgList &Args, bool DiagnoseErrors)
Definition: SanitizerArgs.cpp:218
clang::interp::Add
bool Add(InterpState &S, CodePtr OpPC)
Definition: Interp.h:134
RequiresPIE
static const SanitizerMask RequiresPIE
Definition: SanitizerArgs.cpp:39
hasTargetFeatureMTE
static bool hasTargetFeatureMTE(const llvm::opt::ArgStringList &CmdArgs)
Definition: SanitizerArgs.cpp:1008
clang::DeclaratorContext::File
@ File
CoverageTraceStores
@ CoverageTraceStores
Definition: SanitizerArgs.cpp:96
clang::ento::Nullability
Nullability
Definition: CheckerHelpers.h:55
Driver.h
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
setGroupBits
static SanitizerMask setGroupBits(SanitizerMask Kinds)
Sets group bits for every group that has at least one representative already enabled in Kinds.
Definition: SanitizerArgs.cpp:209
clang::driver::ToolChain::getRTTIArg
const llvm::opt::Arg * getRTTIArg() const
Definition: ToolChain.h:278
NeedsUbsanRt
static const SanitizerMask NeedsUbsanRt
Definition: SanitizerArgs.cpp:29
clang::driver::ToolChain::getDriver
const Driver & getDriver() const
Definition: ToolChain.h:225
CoverageInline8bitCounters
@ CoverageInline8bitCounters
Definition: SanitizerArgs.cpp:91
NotAllowedWithTrap
static const SanitizerMask NotAllowedWithTrap
Definition: SanitizerArgs.cpp:36
clang::diag::Group
Group
Definition: DiagnosticCategories.h:23
TrappingSupported
static const SanitizerMask TrappingSupported
Definition: SanitizerArgs.cpp:64
CompatibleWithMinimalRuntime
static const SanitizerMask CompatibleWithMinimalRuntime
Definition: SanitizerArgs.cpp:74
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::driver::types::isCXX
bool isCXX(ID Id)
isCXX - Is this a "C++" input (C++ and Obj-C++ sources and headers).
Definition: Types.cpp:230
clang::SanitizerSet::Mask
SanitizerMask Mask
Bitmask of enabled sanitizers.
Definition: Sanitizers.h:176
clang::StructuralEquivalenceKind::Default
@ Default
clang::AsanDtorKindFromString
llvm::AsanDtorKind AsanDtorKindFromString(StringRef kind)
Definition: Sanitizers.cpp:84
clang::driver::Driver::Diag
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:132
parseArgValues
static SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A, bool DiagnoseErrors)
Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any invalid components.
Definition: SanitizerArgs.cpp:1251
clang::driver::SanitizerArgs::requiresPIE
bool requiresPIE() const
Definition: SanitizerArgs.cpp:278
clang::SanitizerSet
Definition: Sanitizers.h:153
Options.h
clang::driver::SanitizerArgs::addArgs
void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const
Definition: SanitizerArgs.cpp:1021
clang::XRayInstrKind::None
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
toString
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Definition: SanitizerArgs.cpp:971
clang::driver::ToolChain::getDefaultSanitizers
virtual SanitizerMask getDefaultSanitizers() const
Return sanitizers which are enabled by default.
Definition: ToolChain.h:710
CoverageTraceGep
@ CoverageTraceGep
Definition: SanitizerArgs.cpp:86
llvm::opt
Definition: DiagnosticOptions.h:19
DriverDiagnostic.h
CoverageTracePC
@ CoverageTracePC
Definition: SanitizerArgs.cpp:88
describeSanitizeArg
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.
Definition: SanitizerArgs.cpp:1335
clang::AsanDetectStackUseAfterReturnModeFromString
llvm::AsanDetectStackUseAfterReturnMode AsanDetectStackUseAfterReturnModeFromString(StringRef modeStr)
Definition: Sanitizers.cpp:107
CoverageFeature
CoverageFeature
Definition: SanitizerArgs.cpp:78
CoverageFunc
@ CoverageFunc
Definition: SanitizerArgs.cpp:79
NotAllowedWithMinimalRuntime
static const SanitizerMask NotAllowedWithMinimalRuntime
Definition: SanitizerArgs.cpp:37
llvm::SmallString
Definition: LLVM.h:37
clang::driver::ToolChain::getTriple
const llvm::Triple & getTriple() const
Definition: ToolChain.h:227
clang::driver::ToolChain::getRTTIMode
RTTIMode getRTTIMode() const
Definition: ToolChain.h:281
CoverageBB
@ CoverageBB
Definition: SanitizerArgs.cpp:80
clang::driver::Driver::CCCIsCXX
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
Definition: Driver.h:201
clang::driver::SanitizerArgs::needsFuzzerInterceptors
bool needsFuzzerInterceptors() const
Definition: SanitizerArgs.cpp:253
TrappingDefault
static const SanitizerMask TrappingDefault
Definition: SanitizerArgs.cpp:69
SanitizerArgs.h
clang::driver::SanitizerArgs::needsLTO
bool needsLTO() const
Definition: SanitizerArgs.cpp:286
CoverageTracePCGuard
@ CoverageTracePCGuard
Definition: SanitizerArgs.cpp:89
CoverageIndirCall
@ CoverageIndirCall
Definition: SanitizerArgs.cpp:82
clang::driver::Driver::ResourceDir
std::string ResourceDir
The path to the compiler resource directory.
Definition: Driver.h:155
Unrecoverable
static const SanitizerMask Unrecoverable
Definition: SanitizerArgs.cpp:59
parseCoverageFeatures
static int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A, bool DiagnoseErrors)
Parse -f(no-)?sanitize-coverage= flag values, diagnosing any invalid components.
Definition: SanitizerArgs.cpp:1280
clang::expandSanitizerGroups
SanitizerMask expandSanitizerGroups(SanitizerMask Kinds)
For each sanitizer group bit set in Kinds, set the bits for sanitizers this group enables.
Definition: Sanitizers.cpp:47
clang::driver::ToolChain::getCompilerRTBasename
std::string getCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
Definition: ToolChain.cpp:442
ToolChain.h
clang::serialized_diags::create
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Definition: SerializedDiagnosticPrinter.cpp:301
clang::driver::ToolChain::getSupportedSanitizers
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:1031
clang::driver::Driver::isUsingLTO
bool isUsingLTO(bool IsOffload=false) const
Returns true if we are performing any kind of LTO.
Definition: Driver.h:619
addDefaultIgnorelists
static void addDefaultIgnorelists(const Driver &D, SanitizerMask Kinds, std::vector< std::string > &IgnorelistFiles, bool DiagnoseErrors)
Definition: SanitizerArgs.cpp:142
SupportsCoverage
static const SanitizerMask SupportsCoverage
Definition: SanitizerArgs.cpp:44
CoverageTraceDiv
@ CoverageTraceDiv
Definition: SanitizerArgs.cpp:85
lastArgumentForMask
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...
Definition: SanitizerArgs.cpp:1315
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
Coverage8bitCounters
@ Coverage8bitCounters
Definition: SanitizerArgs.cpp:87
Value
Value
Definition: UninitializedValues.cpp:102
clang::driver::SanitizerArgs::needsCfiRt
bool needsCfiRt() const
Definition: SanitizerArgs.cpp:268
CoverageTraceLoads
@ CoverageTraceLoads
Definition: SanitizerArgs.cpp:95
clang::SanitizerKind
Definition: Sanitizers.h:131
clang::driver::SanitizerArgs::needsCfiDiagRt
bool needsCfiDiagRt() const
Definition: SanitizerArgs.cpp:273
clang::driver::types::ID
ID
Definition: Types.h:23
RecoverableByDefault
static const SanitizerMask RecoverableByDefault
Definition: SanitizerArgs.cpp:55
CoverageEdge
@ CoverageEdge
Definition: SanitizerArgs.cpp:81
clang::AsanDtorKindToString
StringRef AsanDtorKindToString(llvm::AsanDtorKind kind)
Definition: Sanitizers.cpp:72
CoverageInlineBoolFlag
@ CoverageInlineBoolFlag
Definition: SanitizerArgs.cpp:94
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
CoveragePCTable
@ CoveragePCTable
Definition: SanitizerArgs.cpp:92
Sanitizers.h
CommonArgs.h
clang
Definition: CalledOnceCheck.h:17
CoverageTraceBB
@ CoverageTraceBB
Definition: SanitizerArgs.cpp:83
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:71
CoverageNoPrune
@ CoverageNoPrune
Definition: SanitizerArgs.cpp:90
CoverageTraceCmp
@ CoverageTraceCmp
Definition: SanitizerArgs.cpp:84
clang::AsanDetectStackUseAfterReturnModeToString
StringRef AsanDetectStackUseAfterReturnModeToString(llvm::AsanDetectStackUseAfterReturnMode mode)
Definition: Sanitizers.cpp:91
clang::driver::SanitizerArgs::needsUbsanRt
bool needsUbsanRt() const
Definition: SanitizerArgs.cpp:257
clang::driver::Driver::getVFS
llvm::vfs::FileSystem & getVFS() const
Definition: Driver.h:362
NeedsUbsanCxxRt
static const SanitizerMask NeedsUbsanCxxRt
Definition: SanitizerArgs.cpp:34
NeedsUnwindTables
static const SanitizerMask NeedsUnwindTables
Definition: SanitizerArgs.cpp:41
clang::driver::ToolChain::RTTIMode
RTTIMode
Definition: ToolChain.h:111
addIncludeLinkerOption
static void addIncludeLinkerOption(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, StringRef SymbolName)
Definition: SanitizerArgs.cpp:994
clang::driver
Definition: Action.h:31
addSpecialCaseListOpt
static void addSpecialCaseListOpt(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const char *SCLOptFlag, const std::vector< std::string > &SCLFiles)
Definition: SanitizerArgs.cpp:983
clang::parseSanitizerValue
SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups)
Parse a single value from a -fsanitize= or -fno-sanitize= value list.
Definition: Sanitizers.cpp:29
CFIClasses
static const SanitizerMask CFIClasses
Definition: SanitizerArgs.cpp:70
NeedsLTO
static const SanitizerMask NeedsLTO
Definition: SanitizerArgs.cpp:63
clang::RISCV::Invalid
@ Invalid
Definition: RISCVVIntrinsicUtils.h:148
AlwaysRecoverable
static const SanitizerMask AlwaysRecoverable
Definition: SanitizerArgs.cpp:61
clang::SanitizerMask
Definition: Sanitizers.h:30
validateSpecialCaseListFormat
static void validateSpecialCaseListFormat(const Driver &D, std::vector< std::string > &SCLFiles, unsigned MalformedSCLErrorDiagID, bool DiagnoseErrors)
Definition: SanitizerArgs.cpp:128
parseSpecialCaseListArg
static void parseSpecialCaseListArg(const Driver &D, const llvm::opt::ArgList &Args, std::vector< std::string > &SCLFiles, llvm::opt::OptSpecifier SCLOptionID, llvm::opt::OptSpecifier NoSCLOptionID, unsigned MalformedSCLErrorDiagID, bool DiagnoseErrors)
Parse -f(no-)?sanitize-(coverage-)?(white|ignore)list argument's values, diagnosing any invalid file ...
Definition: SanitizerArgs.cpp:180
clang::driver::ToolChain::RM_Disabled
@ RM_Disabled
Definition: ToolChain.h:113