clang  16.0.0git
Diagnostic.h
Go to the documentation of this file.
1 //===- Diagnostic.h - C Language Family Diagnostic Handling -----*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
8 //
9 /// \file
10 /// Defines the Diagnostic-related interfaces.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_BASIC_DIAGNOSTIC_H
15 #define LLVM_CLANG_BASIC_DIAGNOSTIC_H
16 
20 #include "clang/Basic/Specifiers.h"
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/IntrusiveRefCntPtr.h"
24 #include "llvm/ADT/Optional.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/ADT/iterator_range.h"
28 #include "llvm/Support/Compiler.h"
29 #include <cassert>
30 #include <cstdint>
31 #include <limits>
32 #include <list>
33 #include <map>
34 #include <memory>
35 #include <string>
36 #include <type_traits>
37 #include <utility>
38 #include <vector>
39 
40 namespace llvm {
41 class Error;
42 class raw_ostream;
43 } // namespace llvm
44 
45 namespace clang {
46 
47 class DeclContext;
48 class DiagnosticBuilder;
49 class DiagnosticConsumer;
50 class IdentifierInfo;
51 class LangOptions;
52 class Preprocessor;
53 class SourceManager;
54 class StoredDiagnostic;
55 
56 namespace tok {
57 
58 enum TokenKind : unsigned short;
59 
60 } // namespace tok
61 
62 /// Annotates a diagnostic with some code that should be
63 /// inserted, removed, or replaced to fix the problem.
64 ///
65 /// This kind of hint should be used when we are certain that the
66 /// introduction, removal, or modification of a particular (small!)
67 /// amount of code will correct a compilation error. The compiler
68 /// should also provide full recovery from such errors, such that
69 /// suppressing the diagnostic output can still result in successful
70 /// compilation.
71 class FixItHint {
72 public:
73  /// Code that should be replaced to correct the error. Empty for an
74  /// insertion hint.
76 
77  /// Code in the specific range that should be inserted in the insertion
78  /// location.
80 
81  /// The actual code to insert at the insertion location, as a
82  /// string.
84 
86 
87  /// Empty code modification hint, indicating that no code
88  /// modification is known.
89  FixItHint() = default;
90 
91  bool isNull() const {
92  return !RemoveRange.isValid();
93  }
94 
95  /// Create a code modification hint that inserts the given
96  /// code string at a specific location.
98  StringRef Code,
99  bool BeforePreviousInsertions = false) {
100  FixItHint Hint;
101  Hint.RemoveRange =
102  CharSourceRange::getCharRange(InsertionLoc, InsertionLoc);
103  Hint.CodeToInsert = std::string(Code);
105  return Hint;
106  }
107 
108  /// Create a code modification hint that inserts the given
109  /// code from \p FromRange at a specific location.
111  CharSourceRange FromRange,
112  bool BeforePreviousInsertions = false) {
113  FixItHint Hint;
114  Hint.RemoveRange =
115  CharSourceRange::getCharRange(InsertionLoc, InsertionLoc);
116  Hint.InsertFromRange = FromRange;
118  return Hint;
119  }
120 
121  /// Create a code modification hint that removes the given
122  /// source range.
124  FixItHint Hint;
125  Hint.RemoveRange = RemoveRange;
126  return Hint;
127  }
130  }
131 
132  /// Create a code modification hint that replaces the given
133  /// source range with the given code string.
135  StringRef Code) {
136  FixItHint Hint;
137  Hint.RemoveRange = RemoveRange;
138  Hint.CodeToInsert = std::string(Code);
139  return Hint;
140  }
141 
143  StringRef Code) {
145  }
146 };
147 
149  enum {
150  /// The maximum number of arguments we can hold. We
151  /// currently only support up to 10 arguments (%0-%9).
152  ///
153  /// A single diagnostic with more than that almost certainly has to
154  /// be simplified anyway.
156  };
157 
158  /// The number of entries in Arguments.
159  unsigned char NumDiagArgs = 0;
160 
161  /// Specifies for each argument whether it is in DiagArgumentsStr
162  /// or in DiagArguments.
164 
165  /// The values for the various substitution positions.
166  ///
167  /// This is used when the argument is not an std::string. The specific value
168  /// is mangled into an uint64_t and the interpretation depends on exactly
169  /// what sort of argument kind it is.
171 
172  /// The values for the various substitution positions that have
173  /// string arguments.
175 
176  /// The list of ranges added to this diagnostic.
178 
179  /// If valid, provides a hint with some code to insert, remove, or
180  /// modify at a particular position.
182 
183  DiagnosticStorage() = default;
184 };
185 
186 /// Concrete class used by the front-end to report problems and issues.
187 ///
188 /// This massages the diagnostics (e.g. handling things like "report warnings
189 /// as errors" and passes them off to the DiagnosticConsumer for reporting to
190 /// the user. DiagnosticsEngine is tied to one translation unit and one
191 /// SourceManager.
192 class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
193 public:
194  /// The level of the diagnostic, after it has been through mapping.
195  enum Level {
202  };
203 
205  /// std::string
207 
208  /// const char *
210 
211  /// int
213 
214  /// unsigned
216 
217  /// enum TokenKind : unsigned
219 
220  /// IdentifierInfo
222 
223  /// address space
225 
226  /// Qualifiers
228 
229  /// QualType
231 
232  /// DeclarationName
234 
235  /// NamedDecl *
237 
238  /// NestedNameSpecifier *
240 
241  /// DeclContext *
243 
244  /// pair<QualType, QualType>
246 
247  /// Attr *
249  };
250 
251  /// Represents on argument value, which is a union discriminated
252  /// by ArgumentKind, with a value.
253  using ArgumentValue = std::pair<ArgumentKind, intptr_t>;
254 
255 private:
256  // Used by __extension__
257  unsigned char AllExtensionsSilenced = 0;
258 
259  // Treat fatal errors like errors.
260  bool FatalsAsError = false;
261 
262  // Suppress all diagnostics.
263  bool SuppressAllDiagnostics = false;
264 
265  // Elide common types of templates.
266  bool ElideType = true;
267 
268  // Print a tree when comparing templates.
269  bool PrintTemplateTree = false;
270 
271  // Color printing is enabled.
272  bool ShowColors = false;
273 
274  // Which overload candidates to show.
275  OverloadsShown ShowOverloads = Ovl_All;
276 
277  // With Ovl_Best, the number of overload candidates to show when we encounter
278  // an error.
279  //
280  // The value here is the number of candidates to show in the first nontrivial
281  // error. Future errors may show a different number of candidates.
282  unsigned NumOverloadsToShow = 32;
283 
284  // Cap of # errors emitted, 0 -> no limit.
285  unsigned ErrorLimit = 0;
286 
287  // Cap on depth of template backtrace stack, 0 -> no limit.
288  unsigned TemplateBacktraceLimit = 0;
289 
290  // Cap on depth of constexpr evaluation backtrace stack, 0 -> no limit.
291  unsigned ConstexprBacktraceLimit = 0;
292 
295  DiagnosticConsumer *Client = nullptr;
296  std::unique_ptr<DiagnosticConsumer> Owner;
297  SourceManager *SourceMgr = nullptr;
298 
299  /// Mapping information for diagnostics.
300  ///
301  /// Mapping info is packed into four bits per diagnostic. The low three
302  /// bits are the mapping (an instance of diag::Severity), or zero if unset.
303  /// The high bit is set when the mapping was established as a user mapping.
304  /// If the high bit is clear, then the low bits are set to the default
305  /// value, and should be mapped with -pedantic, -Werror, etc.
306  ///
307  /// A new DiagState is created and kept around when diagnostic pragmas modify
308  /// the state so that we know what is the diagnostic state at any given
309  /// source location.
310  class DiagState {
311  llvm::DenseMap<unsigned, DiagnosticMapping> DiagMap;
312 
313  public:
314  // "Global" configuration state that can actually vary between modules.
315 
316  // Ignore all warnings: -w
317  unsigned IgnoreAllWarnings : 1;
318 
319  // Enable all warnings.
320  unsigned EnableAllWarnings : 1;
321 
322  // Treat warnings like errors.
323  unsigned WarningsAsErrors : 1;
324 
325  // Treat errors like fatal errors.
326  unsigned ErrorsAsFatal : 1;
327 
328  // Suppress warnings in system headers.
329  unsigned SuppressSystemWarnings : 1;
330 
331  // Map extensions to warnings or errors?
333 
334  DiagState()
335  : IgnoreAllWarnings(false), EnableAllWarnings(false),
336  WarningsAsErrors(false), ErrorsAsFatal(false),
337  SuppressSystemWarnings(false) {}
338 
339  using iterator = llvm::DenseMap<unsigned, DiagnosticMapping>::iterator;
340  using const_iterator =
341  llvm::DenseMap<unsigned, DiagnosticMapping>::const_iterator;
342 
343  void setMapping(diag::kind Diag, DiagnosticMapping Info) {
344  DiagMap[Diag] = Info;
345  }
346 
347  DiagnosticMapping lookupMapping(diag::kind Diag) const {
348  return DiagMap.lookup(Diag);
349  }
350 
351  DiagnosticMapping &getOrAddMapping(diag::kind Diag);
352 
353  const_iterator begin() const { return DiagMap.begin(); }
354  const_iterator end() const { return DiagMap.end(); }
355  };
356 
357  /// Keeps and automatically disposes all DiagStates that we create.
358  std::list<DiagState> DiagStates;
359 
360  /// A mapping from files to the diagnostic states for those files. Lazily
361  /// built on demand for files in which the diagnostic state has not changed.
362  class DiagStateMap {
363  public:
364  /// Add an initial diagnostic state.
365  void appendFirst(DiagState *State);
366 
367  /// Add a new latest state point.
368  void append(SourceManager &SrcMgr, SourceLocation Loc, DiagState *State);
369 
370  /// Look up the diagnostic state at a given source location.
371  DiagState *lookup(SourceManager &SrcMgr, SourceLocation Loc) const;
372 
373  /// Determine whether this map is empty.
374  bool empty() const { return Files.empty(); }
375 
376  /// Clear out this map.
377  void clear() {
378  Files.clear();
379  FirstDiagState = CurDiagState = nullptr;
380  CurDiagStateLoc = SourceLocation();
381  }
382 
383  /// Produce a debugging dump of the diagnostic state.
384  LLVM_DUMP_METHOD void dump(SourceManager &SrcMgr,
385  StringRef DiagName = StringRef()) const;
386 
387  /// Grab the most-recently-added state point.
388  DiagState *getCurDiagState() const { return CurDiagState; }
389 
390  /// Get the location at which a diagnostic state was last added.
391  SourceLocation getCurDiagStateLoc() const { return CurDiagStateLoc; }
392 
393  private:
394  friend class ASTReader;
395  friend class ASTWriter;
396 
397  /// Represents a point in source where the diagnostic state was
398  /// modified because of a pragma.
399  ///
400  /// 'Loc' can be null if the point represents the diagnostic state
401  /// modifications done through the command-line.
402  struct DiagStatePoint {
403  DiagState *State;
404  unsigned Offset;
405 
406  DiagStatePoint(DiagState *State, unsigned Offset)
407  : State(State), Offset(Offset) {}
408  };
409 
410  /// Description of the diagnostic states and state transitions for a
411  /// particular FileID.
412  struct File {
413  /// The diagnostic state for the parent file. This is strictly redundant,
414  /// as looking up the DecomposedIncludedLoc for the FileID in the Files
415  /// map would give us this, but we cache it here for performance.
416  File *Parent = nullptr;
417 
418  /// The offset of this file within its parent.
419  unsigned ParentOffset = 0;
420 
421  /// Whether this file has any local (not imported from an AST file)
422  /// diagnostic state transitions.
423  bool HasLocalTransitions = false;
424 
425  /// The points within the file where the state changes. There will always
426  /// be at least one of these (the state on entry to the file).
427  llvm::SmallVector<DiagStatePoint, 4> StateTransitions;
428 
429  DiagState *lookup(unsigned Offset) const;
430  };
431 
432  /// The diagnostic states for each file.
433  mutable std::map<FileID, File> Files;
434 
435  /// The initial diagnostic state.
436  DiagState *FirstDiagState;
437 
438  /// The current diagnostic state.
439  DiagState *CurDiagState;
440 
441  /// The location at which the current diagnostic state was established.
442  SourceLocation CurDiagStateLoc;
443 
444  /// Get the diagnostic state information for a file.
445  File *getFile(SourceManager &SrcMgr, FileID ID) const;
446  };
447 
448  DiagStateMap DiagStatesByLoc;
449 
450  /// Keeps the DiagState that was active during each diagnostic 'push'
451  /// so we can get back at it when we 'pop'.
452  std::vector<DiagState *> DiagStateOnPushStack;
453 
454  DiagState *GetCurDiagState() const {
455  return DiagStatesByLoc.getCurDiagState();
456  }
457 
458  void PushDiagStatePoint(DiagState *State, SourceLocation L);
459 
460  /// Finds the DiagStatePoint that contains the diagnostic state of
461  /// the given source location.
462  DiagState *GetDiagStateForLoc(SourceLocation Loc) const {
463  return SourceMgr ? DiagStatesByLoc.lookup(*SourceMgr, Loc)
464  : DiagStatesByLoc.getCurDiagState();
465  }
466 
467  /// Sticky flag set to \c true when an error is emitted.
468  bool ErrorOccurred;
469 
470  /// Sticky flag set to \c true when an "uncompilable error" occurs.
471  /// I.e. an error that was not upgraded from a warning by -Werror.
472  bool UncompilableErrorOccurred;
473 
474  /// Sticky flag set to \c true when a fatal error is emitted.
475  bool FatalErrorOccurred;
476 
477  /// Indicates that an unrecoverable error has occurred.
478  bool UnrecoverableErrorOccurred;
479 
480  /// Counts for DiagnosticErrorTrap to check whether an error occurred
481  /// during a parsing section, e.g. during parsing a function.
482  unsigned TrapNumErrorsOccurred;
483  unsigned TrapNumUnrecoverableErrorsOccurred;
484 
485  /// The level of the last diagnostic emitted.
486  ///
487  /// This is used to emit continuation diagnostics with the same level as the
488  /// diagnostic that they follow.
489  DiagnosticIDs::Level LastDiagLevel;
490 
491  /// Number of warnings reported
492  unsigned NumWarnings;
493 
494  /// Number of errors reported
495  unsigned NumErrors;
496 
497  /// A function pointer that converts an opaque diagnostic
498  /// argument to a strings.
499  ///
500  /// This takes the modifiers and argument that was present in the diagnostic.
501  ///
502  /// The PrevArgs array indicates the previous arguments formatted for this
503  /// diagnostic. Implementations of this function can use this information to
504  /// avoid redundancy across arguments.
505  ///
506  /// This is a hack to avoid a layering violation between libbasic and libsema.
507  using ArgToStringFnTy = void (*)(
509  StringRef Modifier, StringRef Argument,
510  ArrayRef<ArgumentValue> PrevArgs,
511  SmallVectorImpl<char> &Output,
512  void *Cookie,
513  ArrayRef<intptr_t> QualTypeVals);
514 
515  void *ArgToStringCookie = nullptr;
516  ArgToStringFnTy ArgToStringFn;
517 
518  /// ID of the "delayed" diagnostic, which is a (typically
519  /// fatal) diagnostic that had to be delayed because it was found
520  /// while emitting another diagnostic.
521  unsigned DelayedDiagID;
522 
523  /// First string argument for the delayed diagnostic.
524  std::string DelayedDiagArg1;
525 
526  /// Second string argument for the delayed diagnostic.
527  std::string DelayedDiagArg2;
528 
529  /// Third string argument for the delayed diagnostic.
530  std::string DelayedDiagArg3;
531 
532  /// Optional flag value.
533  ///
534  /// Some flags accept values, for instance: -Wframe-larger-than=<value> and
535  /// -Rpass=<value>. The content of this string is emitted after the flag name
536  /// and '='.
537  std::string FlagValue;
538 
539 public:
540  explicit DiagnosticsEngine(IntrusiveRefCntPtr<DiagnosticIDs> Diags,
541  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
542  DiagnosticConsumer *client = nullptr,
543  bool ShouldOwnClient = true);
544  DiagnosticsEngine(const DiagnosticsEngine &) = delete;
545  DiagnosticsEngine &operator=(const DiagnosticsEngine &) = delete;
547 
549  LLVM_DUMP_METHOD void dump() const;
550  LLVM_DUMP_METHOD void dump(StringRef DiagName) const;
551 
553  return Diags;
554  }
555 
556  /// Retrieve the diagnostic options.
557  DiagnosticOptions &getDiagnosticOptions() const { return *DiagOpts; }
558 
559  using diag_mapping_range = llvm::iterator_range<DiagState::const_iterator>;
560 
561  /// Get the current set of diagnostic mappings.
563  const DiagState &DS = *GetCurDiagState();
564  return diag_mapping_range(DS.begin(), DS.end());
565  }
566 
567  DiagnosticConsumer *getClient() { return Client; }
568  const DiagnosticConsumer *getClient() const { return Client; }
569 
570  /// Determine whether this \c DiagnosticsEngine object own its client.
571  bool ownsClient() const { return Owner != nullptr; }
572 
573  /// Return the current diagnostic client along with ownership of that
574  /// client.
575  std::unique_ptr<DiagnosticConsumer> takeClient() { return std::move(Owner); }
576 
577  bool hasSourceManager() const { return SourceMgr != nullptr; }
578 
580  assert(SourceMgr && "SourceManager not set!");
581  return *SourceMgr;
582  }
583 
585  assert(DiagStatesByLoc.empty() &&
586  "Leftover diag state from a different SourceManager.");
587  SourceMgr = SrcMgr;
588  }
589 
590  //===--------------------------------------------------------------------===//
591  // DiagnosticsEngine characterization methods, used by a client to customize
592  // how diagnostics are emitted.
593  //
594 
595  /// Copies the current DiagMappings and pushes the new copy
596  /// onto the top of the stack.
597  void pushMappings(SourceLocation Loc);
598 
599  /// Pops the current DiagMappings off the top of the stack,
600  /// causing the new top of the stack to be the active mappings.
601  ///
602  /// \returns \c true if the pop happens, \c false if there is only one
603  /// DiagMapping on the stack.
604  bool popMappings(SourceLocation Loc);
605 
606  /// Set the diagnostic client associated with this diagnostic object.
607  ///
608  /// \param ShouldOwnClient true if the diagnostic object should take
609  /// ownership of \c client.
610  void setClient(DiagnosticConsumer *client, bool ShouldOwnClient = true);
611 
612  /// Specify a limit for the number of errors we should
613  /// emit before giving up.
614  ///
615  /// Zero disables the limit.
616  void setErrorLimit(unsigned Limit) { ErrorLimit = Limit; }
617 
618  /// Specify the maximum number of template instantiation
619  /// notes to emit along with a given diagnostic.
620  void setTemplateBacktraceLimit(unsigned Limit) {
621  TemplateBacktraceLimit = Limit;
622  }
623 
624  /// Retrieve the maximum number of template instantiation
625  /// notes to emit along with a given diagnostic.
626  unsigned getTemplateBacktraceLimit() const {
627  return TemplateBacktraceLimit;
628  }
629 
630  /// Specify the maximum number of constexpr evaluation
631  /// notes to emit along with a given diagnostic.
632  void setConstexprBacktraceLimit(unsigned Limit) {
633  ConstexprBacktraceLimit = Limit;
634  }
635 
636  /// Retrieve the maximum number of constexpr evaluation
637  /// notes to emit along with a given diagnostic.
638  unsigned getConstexprBacktraceLimit() const {
639  return ConstexprBacktraceLimit;
640  }
641 
642  /// When set to true, any unmapped warnings are ignored.
643  ///
644  /// If this and WarningsAsErrors are both set, then this one wins.
645  void setIgnoreAllWarnings(bool Val) {
646  GetCurDiagState()->IgnoreAllWarnings = Val;
647  }
648  bool getIgnoreAllWarnings() const {
649  return GetCurDiagState()->IgnoreAllWarnings;
650  }
651 
652  /// When set to true, any unmapped ignored warnings are no longer
653  /// ignored.
654  ///
655  /// If this and IgnoreAllWarnings are both set, then that one wins.
656  void setEnableAllWarnings(bool Val) {
657  GetCurDiagState()->EnableAllWarnings = Val;
658  }
659  bool getEnableAllWarnings() const {
660  return GetCurDiagState()->EnableAllWarnings;
661  }
662 
663  /// When set to true, any warnings reported are issued as errors.
664  void setWarningsAsErrors(bool Val) {
665  GetCurDiagState()->WarningsAsErrors = Val;
666  }
667  bool getWarningsAsErrors() const {
668  return GetCurDiagState()->WarningsAsErrors;
669  }
670 
671  /// When set to true, any error reported is made a fatal error.
672  void setErrorsAsFatal(bool Val) { GetCurDiagState()->ErrorsAsFatal = Val; }
673  bool getErrorsAsFatal() const { return GetCurDiagState()->ErrorsAsFatal; }
674 
675  /// \brief When set to true, any fatal error reported is made an error.
676  ///
677  /// This setting takes precedence over the setErrorsAsFatal setting above.
678  void setFatalsAsError(bool Val) { FatalsAsError = Val; }
679  bool getFatalsAsError() const { return FatalsAsError; }
680 
681  /// When set to true mask warnings that come from system headers.
682  void setSuppressSystemWarnings(bool Val) {
683  GetCurDiagState()->SuppressSystemWarnings = Val;
684  }
686  return GetCurDiagState()->SuppressSystemWarnings;
687  }
688 
689  /// Suppress all diagnostics, to silence the front end when we
690  /// know that we don't want any more diagnostics to be passed along to the
691  /// client
692  void setSuppressAllDiagnostics(bool Val) { SuppressAllDiagnostics = Val; }
693  bool getSuppressAllDiagnostics() const { return SuppressAllDiagnostics; }
694 
695  /// Set type eliding, to skip outputting same types occurring in
696  /// template types.
697  void setElideType(bool Val) { ElideType = Val; }
698  bool getElideType() { return ElideType; }
699 
700  /// Set tree printing, to outputting the template difference in a
701  /// tree format.
702  void setPrintTemplateTree(bool Val) { PrintTemplateTree = Val; }
703  bool getPrintTemplateTree() { return PrintTemplateTree; }
704 
705  /// Set color printing, so the type diffing will inject color markers
706  /// into the output.
707  void setShowColors(bool Val) { ShowColors = Val; }
708  bool getShowColors() { return ShowColors; }
709 
710  /// Specify which overload candidates to show when overload resolution
711  /// fails.
712  ///
713  /// By default, we show all candidates.
715  ShowOverloads = Val;
716  }
717  OverloadsShown getShowOverloads() const { return ShowOverloads; }
718 
719  /// When a call or operator fails, print out up to this many candidate
720  /// overloads as suggestions.
721  ///
722  /// With Ovl_Best, we set a high limit for the first nontrivial overload set
723  /// we print, and a lower limit for later sets. This way the user has a
724  /// chance of diagnosing at least one callsite in their program without
725  /// having to recompile with -fshow-overloads=all.
727  switch (getShowOverloads()) {
728  case Ovl_All:
729  // INT_MAX rather than UINT_MAX so that we don't have to think about the
730  // effect of implicit conversions on this value. In practice we'll never
731  // hit 2^31 candidates anyway.
733  case Ovl_Best:
734  return NumOverloadsToShow;
735  }
736  llvm_unreachable("invalid OverloadsShown kind");
737  }
738 
739  /// Call this after showing N overload candidates. This influences the value
740  /// returned by later calls to getNumOverloadCandidatesToShow().
741  void overloadCandidatesShown(unsigned N) {
742  // Current heuristic: Start out with a large value for NumOverloadsToShow,
743  // and then once we print one nontrivially-large overload set, decrease it
744  // for future calls.
745  if (N > 4) {
746  NumOverloadsToShow = 4;
747  }
748  }
749 
750  /// Pretend that the last diagnostic issued was ignored, so any
751  /// subsequent notes will be suppressed, or restore a prior ignoring
752  /// state after ignoring some diagnostics and their notes, possibly in
753  /// the middle of another diagnostic.
754  ///
755  /// This can be used by clients who suppress diagnostics themselves.
757  if (LastDiagLevel == DiagnosticIDs::Fatal)
758  FatalErrorOccurred = true;
760  }
761 
762  /// Determine whether the previous diagnostic was ignored. This can
763  /// be used by clients that want to determine whether notes attached to a
764  /// diagnostic will be suppressed.
765  bool isLastDiagnosticIgnored() const {
766  return LastDiagLevel == DiagnosticIDs::Ignored;
767  }
768 
769  /// Controls whether otherwise-unmapped extension diagnostics are
770  /// mapped onto ignore/warning/error.
771  ///
772  /// This corresponds to the GCC -pedantic and -pedantic-errors option.
774  GetCurDiagState()->ExtBehavior = H;
775  }
777  return GetCurDiagState()->ExtBehavior;
778  }
779 
780  /// Counter bumped when an __extension__ block is/ encountered.
781  ///
782  /// When non-zero, all extension diagnostics are entirely silenced, no
783  /// matter how they are mapped.
784  void IncrementAllExtensionsSilenced() { ++AllExtensionsSilenced; }
785  void DecrementAllExtensionsSilenced() { --AllExtensionsSilenced; }
786  bool hasAllExtensionsSilenced() { return AllExtensionsSilenced != 0; }
787 
788  /// This allows the client to specify that certain warnings are
789  /// ignored.
790  ///
791  /// Notes can never be mapped, errors can only be mapped to fatal, and
792  /// WARNINGs and EXTENSIONs can be mapped arbitrarily.
793  ///
794  /// \param Loc The source location that this change of diagnostic state should
795  /// take affect. It can be null if we are setting the latest state.
797 
798  /// Change an entire diagnostic group (e.g. "unknown-pragmas") to
799  /// have the specified mapping.
800  ///
801  /// \returns true (and ignores the request) if "Group" was unknown, false
802  /// otherwise.
803  ///
804  /// \param Flavor The flavor of group to affect. -Rfoo does not affect the
805  /// state of the -Wfoo group and vice versa.
806  ///
807  /// \param Loc The source location that this change of diagnostic state should
808  /// take affect. It can be null if we are setting the state from command-line.
810  diag::Severity Map,
813  diag::Severity Map,
815 
816  /// Set the warning-as-error flag for the given diagnostic group.
817  ///
818  /// This function always only operates on the current diagnostic state.
819  ///
820  /// \returns True if the given group is unknown, false otherwise.
821  bool setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled);
822 
823  /// Set the error-as-fatal flag for the given diagnostic group.
824  ///
825  /// This function always only operates on the current diagnostic state.
826  ///
827  /// \returns True if the given group is unknown, false otherwise.
828  bool setDiagnosticGroupErrorAsFatal(StringRef Group, bool Enabled);
829 
830  /// Add the specified mapping to all diagnostics of the specified
831  /// flavor.
832  ///
833  /// Mainly to be used by -Wno-everything to disable all warnings but allow
834  /// subsequent -W options to enable specific warnings.
837 
838  bool hasErrorOccurred() const { return ErrorOccurred; }
839 
840  /// Errors that actually prevent compilation, not those that are
841  /// upgraded from a warning by -Werror.
843  return UncompilableErrorOccurred;
844  }
845  bool hasFatalErrorOccurred() const { return FatalErrorOccurred; }
846 
847  /// Determine whether any kind of unrecoverable error has occurred.
849  return FatalErrorOccurred || UnrecoverableErrorOccurred;
850  }
851 
852  unsigned getNumErrors() const { return NumErrors; }
853  unsigned getNumWarnings() const { return NumWarnings; }
854 
855  void setNumWarnings(unsigned NumWarnings) {
856  this->NumWarnings = NumWarnings;
857  }
858 
859  /// Return an ID for a diagnostic with the specified format string and
860  /// level.
861  ///
862  /// If this is the first request for this diagnostic, it is registered and
863  /// created, otherwise the existing ID is returned.
864  ///
865  /// \param FormatString A fixed diagnostic format string that will be hashed
866  /// and mapped to a unique DiagID.
867  template <unsigned N>
868  unsigned getCustomDiagID(Level L, const char (&FormatString)[N]) {
869  return Diags->getCustomDiagID((DiagnosticIDs::Level)L,
870  StringRef(FormatString, N - 1));
871  }
872 
873  /// Converts a diagnostic argument (as an intptr_t) into the string
874  /// that represents it.
876  StringRef Modifier, StringRef Argument,
877  ArrayRef<ArgumentValue> PrevArgs,
878  SmallVectorImpl<char> &Output,
879  ArrayRef<intptr_t> QualTypeVals) const {
880  ArgToStringFn(Kind, Val, Modifier, Argument, PrevArgs, Output,
881  ArgToStringCookie, QualTypeVals);
882  }
883 
884  void SetArgToStringFn(ArgToStringFnTy Fn, void *Cookie) {
885  ArgToStringFn = Fn;
886  ArgToStringCookie = Cookie;
887  }
888 
889  /// Note that the prior diagnostic was emitted by some other
890  /// \c DiagnosticsEngine, and we may be attaching a note to that diagnostic.
892  LastDiagLevel = Other.LastDiagLevel;
893  }
894 
895  /// Reset the state of the diagnostic object to its initial configuration.
896  /// \param[in] soft - if true, doesn't reset the diagnostic mappings and state
897  void Reset(bool soft = false);
898 
899  //===--------------------------------------------------------------------===//
900  // DiagnosticsEngine classification and reporting interfaces.
901  //
902 
903  /// Determine whether the diagnostic is known to be ignored.
904  ///
905  /// This can be used to opportunistically avoid expensive checks when it's
906  /// known for certain that the diagnostic has been suppressed at the
907  /// specified location \p Loc.
908  ///
909  /// \param Loc The source location we are interested in finding out the
910  /// diagnostic state. Can be null in order to query the latest state.
911  bool isIgnored(unsigned DiagID, SourceLocation Loc) const {
912  return Diags->getDiagnosticSeverity(DiagID, Loc, *this) ==
914  }
915 
916  /// Based on the way the client configured the DiagnosticsEngine
917  /// object, classify the specified diagnostic ID into a Level, consumable by
918  /// the DiagnosticConsumer.
919  ///
920  /// To preserve invariant assumptions, this function should not be used to
921  /// influence parse or semantic analysis actions. Instead consider using
922  /// \c isIgnored().
923  ///
924  /// \param Loc The source location we are interested in finding out the
925  /// diagnostic state. Can be null in order to query the latest state.
926  Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const {
927  return (Level)Diags->getDiagnosticLevel(DiagID, Loc, *this);
928  }
929 
930  /// Issue the message to the client.
931  ///
932  /// This actually returns an instance of DiagnosticBuilder which emits the
933  /// diagnostics (through @c ProcessDiag) when it is destroyed.
934  ///
935  /// \param DiagID A member of the @c diag::kind enum.
936  /// \param Loc Represents the source location associated with the diagnostic,
937  /// which can be an invalid location if no position information is available.
938  inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID);
939  inline DiagnosticBuilder Report(unsigned DiagID);
940 
941  void Report(const StoredDiagnostic &storedDiag);
942 
943  /// Determine whethere there is already a diagnostic in flight.
944  bool isDiagnosticInFlight() const {
945  return CurDiagID != std::numeric_limits<unsigned>::max();
946  }
947 
948  /// Set the "delayed" diagnostic that will be emitted once
949  /// the current diagnostic completes.
950  ///
951  /// If a diagnostic is already in-flight but the front end must
952  /// report a problem (e.g., with an inconsistent file system
953  /// state), this routine sets a "delayed" diagnostic that will be
954  /// emitted after the current diagnostic completes. This should
955  /// only be used for fatal errors detected at inconvenient
956  /// times. If emitting a delayed diagnostic causes a second delayed
957  /// diagnostic to be introduced, that second delayed diagnostic
958  /// will be ignored.
959  ///
960  /// \param DiagID The ID of the diagnostic being delayed.
961  ///
962  /// \param Arg1 A string argument that will be provided to the
963  /// diagnostic. A copy of this string will be stored in the
964  /// DiagnosticsEngine object itself.
965  ///
966  /// \param Arg2 A string argument that will be provided to the
967  /// diagnostic. A copy of this string will be stored in the
968  /// DiagnosticsEngine object itself.
969  ///
970  /// \param Arg3 A string argument that will be provided to the
971  /// diagnostic. A copy of this string will be stored in the
972  /// DiagnosticsEngine object itself.
973  void SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1 = "",
974  StringRef Arg2 = "", StringRef Arg3 = "");
975 
976  /// Clear out the current diagnostic.
977  void Clear() { CurDiagID = std::numeric_limits<unsigned>::max(); }
978 
979  /// Return the value associated with this diagnostic flag.
980  StringRef getFlagValue() const { return FlagValue; }
981 
982 private:
983  // This is private state used by DiagnosticBuilder. We put it here instead of
984  // in DiagnosticBuilder in order to keep DiagnosticBuilder a small lightweight
985  // object. This implementation choice means that we can only have one
986  // diagnostic "in flight" at a time, but this seems to be a reasonable
987  // tradeoff to keep these objects small. Assertions verify that only one
988  // diagnostic is in flight at a time.
989  friend class Diagnostic;
990  friend class DiagnosticBuilder;
991  friend class DiagnosticErrorTrap;
992  friend class DiagnosticIDs;
993  friend class PartialDiagnostic;
994 
995  /// Report the delayed diagnostic.
996  void ReportDelayed();
997 
998  /// The location of the current diagnostic that is in flight.
999  SourceLocation CurDiagLoc;
1000 
1001  /// The ID of the current diagnostic that is in flight.
1002  ///
1003  /// This is set to std::numeric_limits<unsigned>::max() when there is no
1004  /// diagnostic in flight.
1005  unsigned CurDiagID;
1006 
1007  enum {
1008  /// The maximum number of arguments we can hold.
1009  ///
1010  /// We currently only support up to 10 arguments (%0-%9). A single
1011  /// diagnostic with more than that almost certainly has to be simplified
1012  /// anyway.
1013  MaxArguments = DiagnosticStorage::MaxArguments,
1014  };
1015 
1016  DiagnosticStorage DiagStorage;
1017 
1018  DiagnosticMapping makeUserMapping(diag::Severity Map, SourceLocation L) {
1019  bool isPragma = L.isValid();
1020  DiagnosticMapping Mapping =
1021  DiagnosticMapping::Make(Map, /*IsUser=*/true, isPragma);
1022 
1023  // If this is a pragma mapping, then set the diagnostic mapping flags so
1024  // that we override command line options.
1025  if (isPragma) {
1026  Mapping.setNoWarningAsError(true);
1027  Mapping.setNoErrorAsFatal(true);
1028  }
1029 
1030  return Mapping;
1031  }
1032 
1033  /// Used to report a diagnostic that is finally fully formed.
1034  ///
1035  /// \returns true if the diagnostic was emitted, false if it was suppressed.
1036  bool ProcessDiag() {
1037  return Diags->ProcessDiag(*this);
1038  }
1039 
1040  /// @name Diagnostic Emission
1041  /// @{
1042 protected:
1043  friend class ASTReader;
1044  friend class ASTWriter;
1045 
1046  // Sema requires access to the following functions because the current design
1047  // of SFINAE requires it to use its own SemaDiagnosticBuilder, which needs to
1048  // access us directly to ensure we minimize the emitted code for the common
1049  // Sema::Diag() patterns.
1050  friend class Sema;
1051 
1052  /// Emit the current diagnostic and clear the diagnostic state.
1053  ///
1054  /// \param Force Emit the diagnostic regardless of suppression settings.
1055  bool EmitCurrentDiagnostic(bool Force = false);
1056 
1057  unsigned getCurrentDiagID() const { return CurDiagID; }
1058 
1059  SourceLocation getCurrentDiagLoc() const { return CurDiagLoc; }
1060 
1061  /// @}
1062 };
1063 
1064 /// RAII class that determines when any errors have occurred
1065 /// between the time the instance was created and the time it was
1066 /// queried.
1067 ///
1068 /// Note that you almost certainly do not want to use this. It's usually
1069 /// meaningless to ask whether a particular scope triggered an error message,
1070 /// because error messages outside that scope can mark things invalid (or cause
1071 /// us to reach an error limit), which can suppress errors within that scope.
1073  DiagnosticsEngine &Diag;
1074  unsigned NumErrors;
1075  unsigned NumUnrecoverableErrors;
1076 
1077 public:
1079  : Diag(Diag) { reset(); }
1080 
1081  /// Determine whether any errors have occurred since this
1082  /// object instance was created.
1083  bool hasErrorOccurred() const {
1084  return Diag.TrapNumErrorsOccurred > NumErrors;
1085  }
1086 
1087  /// Determine whether any unrecoverable errors have occurred since this
1088  /// object instance was created.
1090  return Diag.TrapNumUnrecoverableErrorsOccurred > NumUnrecoverableErrors;
1091  }
1092 
1093  /// Set to initial state of "no errors occurred".
1094  void reset() {
1095  NumErrors = Diag.TrapNumErrorsOccurred;
1096  NumUnrecoverableErrors = Diag.TrapNumUnrecoverableErrorsOccurred;
1097  }
1098 };
1099 
1100 /// The streaming interface shared between DiagnosticBuilder and
1101 /// PartialDiagnostic. This class is not intended to be constructed directly
1102 /// but only as base class of DiagnosticBuilder and PartialDiagnostic builder.
1103 ///
1104 /// Any new type of argument accepted by DiagnosticBuilder and PartialDiagnostic
1105 /// should be implemented as a '<<' operator of StreamingDiagnostic, e.g.
1106 ///
1107 /// const StreamingDiagnostic&
1108 /// operator<<(const StreamingDiagnostic&, NewArgType);
1109 ///
1111 public:
1112  /// An allocator for DiagnosticStorage objects, which uses a small cache to
1113  /// objects, used to reduce malloc()/free() traffic for partial diagnostics.
1115  static const unsigned NumCached = 16;
1116  DiagnosticStorage Cached[NumCached];
1117  DiagnosticStorage *FreeList[NumCached];
1118  unsigned NumFreeListEntries;
1119 
1120  public:
1123 
1124  /// Allocate new storage.
1126  if (NumFreeListEntries == 0)
1127  return new DiagnosticStorage;
1128 
1129  DiagnosticStorage *Result = FreeList[--NumFreeListEntries];
1130  Result->NumDiagArgs = 0;
1131  Result->DiagRanges.clear();
1132  Result->FixItHints.clear();
1133  return Result;
1134  }
1135 
1136  /// Free the given storage object.
1138  if (S >= Cached && S <= Cached + NumCached) {
1139  FreeList[NumFreeListEntries++] = S;
1140  return;
1141  }
1142 
1143  delete S;
1144  }
1145  };
1146 
1147 protected:
1148  mutable DiagnosticStorage *DiagStorage = nullptr;
1149 
1150  /// Allocator used to allocate storage for this diagnostic.
1152 
1153 public:
1154  /// Retrieve storage for this particular diagnostic.
1156  if (DiagStorage)
1157  return DiagStorage;
1158 
1159  assert(Allocator);
1161  return DiagStorage;
1162  }
1163 
1164  void freeStorage() {
1165  if (!DiagStorage)
1166  return;
1167 
1168  // The hot path for PartialDiagnostic is when we just used it to wrap an ID
1169  // (typically so we have the flexibility of passing a more complex
1170  // diagnostic into the callee, but that does not commonly occur).
1171  //
1172  // Split this out into a slow function for silly compilers (*cough*) which
1173  // can't do decent partial inlining.
1174  freeStorageSlow();
1175  }
1176 
1178  if (!Allocator)
1179  return;
1181  DiagStorage = nullptr;
1182  }
1183 
1185  if (!DiagStorage)
1186  DiagStorage = getStorage();
1187 
1189  "Too many arguments to diagnostic!");
1192  }
1193 
1194  void AddString(StringRef V) const {
1195  if (!DiagStorage)
1196  DiagStorage = getStorage();
1197 
1199  "Too many arguments to diagnostic!");
1203  }
1204 
1205  void AddSourceRange(const CharSourceRange &R) const {
1206  if (!DiagStorage)
1207  DiagStorage = getStorage();
1208 
1209  DiagStorage->DiagRanges.push_back(R);
1210  }
1211 
1212  void AddFixItHint(const FixItHint &Hint) const {
1213  if (Hint.isNull())
1214  return;
1215 
1216  if (!DiagStorage)
1217  DiagStorage = getStorage();
1218 
1219  DiagStorage->FixItHints.push_back(Hint);
1220  }
1221 
1222  /// Conversion of StreamingDiagnostic to bool always returns \c true.
1223  ///
1224  /// This allows is to be used in boolean error contexts (where \c true is
1225  /// used to indicate that an error has occurred), like:
1226  /// \code
1227  /// return Diag(...);
1228  /// \endcode
1229  operator bool() const { return true; }
1230 
1231 protected:
1232  StreamingDiagnostic() = default;
1233 
1234  /// Construct with an external storage not owned by itself. The allocator
1235  /// is a null pointer in this case.
1237  : DiagStorage(Storage) {}
1238 
1239  /// Construct with a storage allocator which will manage the storage. The
1240  /// allocator is not a null pointer in this case.
1242  : Allocator(&Alloc) {}
1243 
1244  StreamingDiagnostic(const StreamingDiagnostic &Diag) = default;
1246 
1248 };
1249 
1250 //===----------------------------------------------------------------------===//
1251 // DiagnosticBuilder
1252 //===----------------------------------------------------------------------===//
1253 
1254 /// A little helper class used to produce diagnostics.
1255 ///
1256 /// This is constructed by the DiagnosticsEngine::Report method, and
1257 /// allows insertion of extra information (arguments and source ranges) into
1258 /// the currently "in flight" diagnostic. When the temporary for the builder
1259 /// is destroyed, the diagnostic is issued.
1260 ///
1261 /// Note that many of these will be created as temporary objects (many call
1262 /// sites), so we want them to be small and we never want their address taken.
1263 /// This ensures that compilers with somewhat reasonable optimizers will promote
1264 /// the common fields to registers, eliminating increments of the NumArgs field,
1265 /// for example.
1267  friend class DiagnosticsEngine;
1268  friend class PartialDiagnostic;
1269 
1270  mutable DiagnosticsEngine *DiagObj = nullptr;
1271 
1272  /// Status variable indicating if this diagnostic is still active.
1273  ///
1274  // NOTE: This field is redundant with DiagObj (IsActive iff (DiagObj == 0)),
1275  // but LLVM is not currently smart enough to eliminate the null check that
1276  // Emit() would end up with if we used that as our status variable.
1277  mutable bool IsActive = false;
1278 
1279  /// Flag indicating that this diagnostic is being emitted via a
1280  /// call to ForceEmit.
1281  mutable bool IsForceEmit = false;
1282 
1283  DiagnosticBuilder() = default;
1284 
1285  explicit DiagnosticBuilder(DiagnosticsEngine *diagObj)
1286  : StreamingDiagnostic(&diagObj->DiagStorage), DiagObj(diagObj),
1287  IsActive(true) {
1288  assert(diagObj && "DiagnosticBuilder requires a valid DiagnosticsEngine!");
1289  assert(DiagStorage &&
1290  "DiagnosticBuilder requires a valid DiagnosticStorage!");
1291  DiagStorage->NumDiagArgs = 0;
1292  DiagStorage->DiagRanges.clear();
1293  DiagStorage->FixItHints.clear();
1294  }
1295 
1296 protected:
1297  /// Clear out the current diagnostic.
1298  void Clear() const {
1299  DiagObj = nullptr;
1300  IsActive = false;
1301  IsForceEmit = false;
1302  }
1303 
1304  /// Determine whether this diagnostic is still active.
1305  bool isActive() const { return IsActive; }
1306 
1307  /// Force the diagnostic builder to emit the diagnostic now.
1308  ///
1309  /// Once this function has been called, the DiagnosticBuilder object
1310  /// should not be used again before it is destroyed.
1311  ///
1312  /// \returns true if a diagnostic was emitted, false if the
1313  /// diagnostic was suppressed.
1314  bool Emit() {
1315  // If this diagnostic is inactive, then its soul was stolen by the copy ctor
1316  // (or by a subclass, as in SemaDiagnosticBuilder).
1317  if (!isActive()) return false;
1318 
1319  // Process the diagnostic.
1320  bool Result = DiagObj->EmitCurrentDiagnostic(IsForceEmit);
1321 
1322  // This diagnostic is dead.
1323  Clear();
1324 
1325  return Result;
1326  }
1327 
1328 public:
1329  /// Copy constructor. When copied, this "takes" the diagnostic info from the
1330  /// input and neuters it.
1332  DiagObj = D.DiagObj;
1334  IsActive = D.IsActive;
1335  IsForceEmit = D.IsForceEmit;
1336  D.Clear();
1337  }
1338 
1339  template <typename T> const DiagnosticBuilder &operator<<(const T &V) const {
1340  assert(isActive() && "Clients must not add to cleared diagnostic!");
1341  const StreamingDiagnostic &DB = *this;
1342  DB << V;
1343  return *this;
1344  }
1345 
1346  // It is necessary to limit this to rvalue reference to avoid calling this
1347  // function with a bitfield lvalue argument since non-const reference to
1348  // bitfield is not allowed.
1349  template <typename T,
1350  typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>>
1351  const DiagnosticBuilder &operator<<(T &&V) const {
1352  assert(isActive() && "Clients must not add to cleared diagnostic!");
1353  const StreamingDiagnostic &DB = *this;
1354  DB << std::move(V);
1355  return *this;
1356  }
1357 
1358  DiagnosticBuilder &operator=(const DiagnosticBuilder &) = delete;
1359 
1360  /// Emits the diagnostic.
1362 
1363  /// Forces the diagnostic to be emitted.
1365  IsForceEmit = true;
1366  return *this;
1367  }
1368 
1369  void addFlagValue(StringRef V) const { DiagObj->FlagValue = std::string(V); }
1370 };
1371 
1373  StringRef Val;
1374 
1375  explicit AddFlagValue(StringRef V) : Val(V) {}
1376 };
1377 
1378 /// Register a value for the flag in the current diagnostic. This
1379 /// value will be shown as the suffix "=value" after the flag name. It is
1380 /// useful in cases where the diagnostic flag accepts values (e.g.,
1381 /// -Rpass or -Wframe-larger-than).
1383  const AddFlagValue V) {
1384  DB.addFlagValue(V.Val);
1385  return DB;
1386 }
1387 
1389  StringRef S) {
1390  DB.AddString(S);
1391  return DB;
1392 }
1393 
1395  const char *Str) {
1396  DB.AddTaggedVal(reinterpret_cast<intptr_t>(Str),
1398  return DB;
1399 }
1400 
1402  int I) {
1404  return DB;
1405 }
1406 
1408  long I) {
1410  return DB;
1411 }
1412 
1414  long long I) {
1416  return DB;
1417 }
1418 
1419 // We use enable_if here to prevent that this overload is selected for
1420 // pointers or other arguments that are implicitly convertible to bool.
1421 template <typename T>
1422 inline std::enable_if_t<std::is_same<T, bool>::value,
1423  const StreamingDiagnostic &>
1426  return DB;
1427 }
1428 
1430  unsigned I) {
1432  return DB;
1433 }
1434 
1436  unsigned long I) {
1438  return DB;
1439 }
1440 
1442  unsigned long long I) {
1444  return DB;
1445 }
1446 
1448  tok::TokenKind I) {
1449  DB.AddTaggedVal(static_cast<unsigned>(I), DiagnosticsEngine::ak_tokenkind);
1450  return DB;
1451 }
1452 
1454  const IdentifierInfo *II) {
1455  DB.AddTaggedVal(reinterpret_cast<intptr_t>(II),
1457  return DB;
1458 }
1459 
1460 // Adds a DeclContext to the diagnostic. The enable_if template magic is here
1461 // so that we only match those arguments that are (statically) DeclContexts;
1462 // other arguments that derive from DeclContext (e.g., RecordDecls) will not
1463 // match.
1464 template <typename T>
1465 inline std::enable_if_t<
1466  std::is_same<std::remove_const_t<T>, DeclContext>::value,
1467  const StreamingDiagnostic &>
1468 operator<<(const StreamingDiagnostic &DB, T *DC) {
1469  DB.AddTaggedVal(reinterpret_cast<intptr_t>(DC),
1471  return DB;
1472 }
1473 
1475  SourceRange R) {
1477  return DB;
1478 }
1479 
1481  ArrayRef<SourceRange> Ranges) {
1482  for (SourceRange R : Ranges)
1484  return DB;
1485 }
1486 
1488  const CharSourceRange &R) {
1489  DB.AddSourceRange(R);
1490  return DB;
1491 }
1492 
1494  const FixItHint &Hint) {
1495  DB.AddFixItHint(Hint);
1496  return DB;
1497 }
1498 
1500  ArrayRef<FixItHint> Hints) {
1501  for (const FixItHint &Hint : Hints)
1502  DB.AddFixItHint(Hint);
1503  return DB;
1504 }
1505 
1506 inline const StreamingDiagnostic &
1508  const llvm::Optional<SourceRange> &Opt) {
1509  if (Opt)
1510  DB << *Opt;
1511  return DB;
1512 }
1513 
1514 inline const StreamingDiagnostic &
1516  const llvm::Optional<CharSourceRange> &Opt) {
1517  if (Opt)
1518  DB << *Opt;
1519  return DB;
1520 }
1521 
1522 inline const StreamingDiagnostic &
1524  const llvm::Optional<FixItHint> &Opt) {
1525  if (Opt)
1526  DB << *Opt;
1527  return DB;
1528 }
1529 
1530 /// A nullability kind paired with a bit indicating whether it used a
1531 /// context-sensitive keyword.
1532 using DiagNullabilityKind = std::pair<NullabilityKind, bool>;
1533 
1535  DiagNullabilityKind nullability);
1536 
1538  unsigned DiagID) {
1539  assert(CurDiagID == std::numeric_limits<unsigned>::max() &&
1540  "Multiple diagnostics in flight at once!");
1541  CurDiagLoc = Loc;
1542  CurDiagID = DiagID;
1543  FlagValue.clear();
1544  return DiagnosticBuilder(this);
1545 }
1546 
1548  llvm::Error &&E);
1549 
1551  return Report(SourceLocation(), DiagID);
1552 }
1553 
1554 //===----------------------------------------------------------------------===//
1555 // Diagnostic
1556 //===----------------------------------------------------------------------===//
1557 
1558 /// A little helper class (which is basically a smart pointer that forwards
1559 /// info from DiagnosticsEngine) that allows clients to enquire about the
1560 /// currently in-flight diagnostic.
1561 class Diagnostic {
1562  const DiagnosticsEngine *DiagObj;
1563  StringRef StoredDiagMessage;
1564 
1565 public:
1566  explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}
1567  Diagnostic(const DiagnosticsEngine *DO, StringRef storedDiagMessage)
1568  : DiagObj(DO), StoredDiagMessage(storedDiagMessage) {}
1569 
1570  const DiagnosticsEngine *getDiags() const { return DiagObj; }
1571  unsigned getID() const { return DiagObj->CurDiagID; }
1572  const SourceLocation &getLocation() const { return DiagObj->CurDiagLoc; }
1573  bool hasSourceManager() const { return DiagObj->hasSourceManager(); }
1574  SourceManager &getSourceManager() const { return DiagObj->getSourceManager();}
1575 
1576  unsigned getNumArgs() const { return DiagObj->DiagStorage.NumDiagArgs; }
1577 
1578  /// Return the kind of the specified index.
1579  ///
1580  /// Based on the kind of argument, the accessors below can be used to get
1581  /// the value.
1582  ///
1583  /// \pre Idx < getNumArgs()
1585  assert(Idx < getNumArgs() && "Argument index out of range!");
1587  DiagObj->DiagStorage.DiagArgumentsKind[Idx];
1588  }
1589 
1590  /// Return the provided argument string specified by \p Idx.
1591  /// \pre getArgKind(Idx) == DiagnosticsEngine::ak_std_string
1592  const std::string &getArgStdStr(unsigned Idx) const {
1594  "invalid argument accessor!");
1595  return DiagObj->DiagStorage.DiagArgumentsStr[Idx];
1596  }
1597 
1598  /// Return the specified C string argument.
1599  /// \pre getArgKind(Idx) == DiagnosticsEngine::ak_c_string
1600  const char *getArgCStr(unsigned Idx) const {
1601  assert(getArgKind(Idx) == DiagnosticsEngine::ak_c_string &&
1602  "invalid argument accessor!");
1603  return reinterpret_cast<const char *>(
1604  DiagObj->DiagStorage.DiagArgumentsVal[Idx]);
1605  }
1606 
1607  /// Return the specified signed integer argument.
1608  /// \pre getArgKind(Idx) == DiagnosticsEngine::ak_sint
1609  int64_t getArgSInt(unsigned Idx) const {
1610  assert(getArgKind(Idx) == DiagnosticsEngine::ak_sint &&
1611  "invalid argument accessor!");
1612  return (int64_t)DiagObj->DiagStorage.DiagArgumentsVal[Idx];
1613  }
1614 
1615  /// Return the specified unsigned integer argument.
1616  /// \pre getArgKind(Idx) == DiagnosticsEngine::ak_uint
1617  uint64_t getArgUInt(unsigned Idx) const {
1618  assert(getArgKind(Idx) == DiagnosticsEngine::ak_uint &&
1619  "invalid argument accessor!");
1620  return DiagObj->DiagStorage.DiagArgumentsVal[Idx];
1621  }
1622 
1623  /// Return the specified IdentifierInfo argument.
1624  /// \pre getArgKind(Idx) == DiagnosticsEngine::ak_identifierinfo
1625  const IdentifierInfo *getArgIdentifier(unsigned Idx) const {
1627  "invalid argument accessor!");
1628  return reinterpret_cast<IdentifierInfo *>(
1629  DiagObj->DiagStorage.DiagArgumentsVal[Idx]);
1630  }
1631 
1632  /// Return the specified non-string argument in an opaque form.
1633  /// \pre getArgKind(Idx) != DiagnosticsEngine::ak_std_string
1634  uint64_t getRawArg(unsigned Idx) const {
1636  "invalid argument accessor!");
1637  return DiagObj->DiagStorage.DiagArgumentsVal[Idx];
1638  }
1639 
1640  /// Return the number of source ranges associated with this diagnostic.
1641  unsigned getNumRanges() const {
1642  return DiagObj->DiagStorage.DiagRanges.size();
1643  }
1644 
1645  /// \pre Idx < getNumRanges()
1646  const CharSourceRange &getRange(unsigned Idx) const {
1647  assert(Idx < getNumRanges() && "Invalid diagnostic range index!");
1648  return DiagObj->DiagStorage.DiagRanges[Idx];
1649  }
1650 
1651  /// Return an array reference for this diagnostic's ranges.
1653  return DiagObj->DiagStorage.DiagRanges;
1654  }
1655 
1656  unsigned getNumFixItHints() const {
1657  return DiagObj->DiagStorage.FixItHints.size();
1658  }
1659 
1660  const FixItHint &getFixItHint(unsigned Idx) const {
1661  assert(Idx < getNumFixItHints() && "Invalid index!");
1662  return DiagObj->DiagStorage.FixItHints[Idx];
1663  }
1664 
1666  return DiagObj->DiagStorage.FixItHints;
1667  }
1668 
1669  /// Format this diagnostic into a string, substituting the
1670  /// formal arguments into the %0 slots.
1671  ///
1672  /// The result is appended onto the \p OutStr array.
1673  void FormatDiagnostic(SmallVectorImpl<char> &OutStr) const;
1674 
1675  /// Format the given format-string into the output buffer using the
1676  /// arguments stored in this diagnostic.
1677  void FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1678  SmallVectorImpl<char> &OutStr) const;
1679 };
1680 
1681 /**
1682  * Represents a diagnostic in a form that can be retained until its
1683  * corresponding source manager is destroyed.
1684  */
1686  unsigned ID;
1688  FullSourceLoc Loc;
1689  std::string Message;
1690  std::vector<CharSourceRange> Ranges;
1691  std::vector<FixItHint> FixIts;
1692 
1693 public:
1694  StoredDiagnostic() = default;
1696  StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
1697  StringRef Message);
1698  StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
1699  StringRef Message, FullSourceLoc Loc,
1701  ArrayRef<FixItHint> Fixits);
1702 
1703  /// Evaluates true when this object stores a diagnostic.
1704  explicit operator bool() const { return !Message.empty(); }
1705 
1706  unsigned getID() const { return ID; }
1707  DiagnosticsEngine::Level getLevel() const { return Level; }
1708  const FullSourceLoc &getLocation() const { return Loc; }
1709  StringRef getMessage() const { return Message; }
1710 
1711  void setLocation(FullSourceLoc Loc) { this->Loc = Loc; }
1712 
1713  using range_iterator = std::vector<CharSourceRange>::const_iterator;
1714 
1715  range_iterator range_begin() const { return Ranges.begin(); }
1716  range_iterator range_end() const { return Ranges.end(); }
1717  unsigned range_size() const { return Ranges.size(); }
1718 
1720  return llvm::makeArrayRef(Ranges);
1721  }
1722 
1723  using fixit_iterator = std::vector<FixItHint>::const_iterator;
1724 
1725  fixit_iterator fixit_begin() const { return FixIts.begin(); }
1726  fixit_iterator fixit_end() const { return FixIts.end(); }
1727  unsigned fixit_size() const { return FixIts.size(); }
1728 
1730  return llvm::makeArrayRef(FixIts);
1731  }
1732 };
1733 
1734 // Simple debug printing of StoredDiagnostic.
1735 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const StoredDiagnostic &);
1736 
1737 /// Abstract interface, implemented by clients of the front-end, which
1738 /// formats and prints fully processed diagnostics.
1740 protected:
1741  unsigned NumWarnings = 0; ///< Number of warnings reported
1742  unsigned NumErrors = 0; ///< Number of errors reported
1743 
1744 public:
1745  DiagnosticConsumer() = default;
1746  virtual ~DiagnosticConsumer();
1747 
1748  unsigned getNumErrors() const { return NumErrors; }
1749  unsigned getNumWarnings() const { return NumWarnings; }
1750  virtual void clear() { NumWarnings = NumErrors = 0; }
1751 
1752  /// Callback to inform the diagnostic client that processing
1753  /// of a source file is beginning.
1754  ///
1755  /// Note that diagnostics may be emitted outside the processing of a source
1756  /// file, for example during the parsing of command line options. However,
1757  /// diagnostics with source range information are required to only be emitted
1758  /// in between BeginSourceFile() and EndSourceFile().
1759  ///
1760  /// \param LangOpts The language options for the source file being processed.
1761  /// \param PP The preprocessor object being used for the source; this is
1762  /// optional, e.g., it may not be present when processing AST source files.
1763  virtual void BeginSourceFile(const LangOptions &LangOpts,
1764  const Preprocessor *PP = nullptr) {}
1765 
1766  /// Callback to inform the diagnostic client that processing
1767  /// of a source file has ended.
1768  ///
1769  /// The diagnostic client should assume that any objects made available via
1770  /// BeginSourceFile() are inaccessible.
1771  virtual void EndSourceFile() {}
1772 
1773  /// Callback to inform the diagnostic client that processing of all
1774  /// source files has ended.
1775  virtual void finish() {}
1776 
1777  /// Indicates whether the diagnostics handled by this
1778  /// DiagnosticConsumer should be included in the number of diagnostics
1779  /// reported by DiagnosticsEngine.
1780  ///
1781  /// The default implementation returns true.
1782  virtual bool IncludeInDiagnosticCounts() const;
1783 
1784  /// Handle this diagnostic, reporting it to the user or
1785  /// capturing it to a log as needed.
1786  ///
1787  /// The default implementation just keeps track of the total number of
1788  /// warnings and errors.
1789  virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
1790  const Diagnostic &Info);
1791 };
1792 
1793 /// A diagnostic client that ignores all diagnostics.
1795  virtual void anchor();
1796 
1797  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
1798  const Diagnostic &Info) override {
1799  // Just ignore it.
1800  }
1801 };
1802 
1803 /// Diagnostic consumer that forwards diagnostics along to an
1804 /// existing, already-initialized diagnostic consumer.
1805 ///
1807  DiagnosticConsumer &Target;
1808 
1809 public:
1811  ~ForwardingDiagnosticConsumer() override;
1812 
1814  const Diagnostic &Info) override;
1815  void clear() override;
1816 
1817  bool IncludeInDiagnosticCounts() const override;
1818 };
1819 
1820 // Struct used for sending info about how a type should be printed.
1824  unsigned PrintTree : 1;
1825  unsigned PrintFromType : 1;
1826  unsigned ElideType : 1;
1827  unsigned ShowColors : 1;
1828 
1829  // The printer sets this variable to true if the template diff was used.
1830  unsigned TemplateDiffUsed : 1;
1831 };
1832 
1833 /// Special character that the diagnostic printer will use to toggle the bold
1834 /// attribute. The character itself will be not be printed.
1835 const char ToggleHighlight = 127;
1836 
1837 /// ProcessWarningOptions - Initialize the diagnostic client and process the
1838 /// warning options specified on the command line.
1840  const DiagnosticOptions &Opts,
1841  bool ReportDiags = true);
1842 
1843 } // namespace clang
1844 
1845 #endif // LLVM_CLANG_BASIC_DIAGNOSTIC_H
clang::Diagnostic::getNumFixItHints
unsigned getNumFixItHints() const
Definition: Diagnostic.h:1656
clang::DiagnosticsEngine::Level
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:195
clang::diag::Severity
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
Definition: DiagnosticIDs.h:82
max
__DEVICE__ int max(int __a, int __b)
Definition: __clang_cuda_math.h:196
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::DiagnosticsEngine::ak_qual
@ ak_qual
Qualifiers.
Definition: Diagnostic.h:227
clang::DiagnosticsEngine::SetArgToStringFn
void SetArgToStringFn(ArgToStringFnTy Fn, void *Cookie)
Definition: Diagnostic.h:884
clang::AddFlagValue::Val
StringRef Val
Definition: Diagnostic.h:1373
Specifiers.h
clang::StreamingDiagnostic::StreamingDiagnostic
StreamingDiagnostic()=default
clang::DiagnosticBuilder
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1266
clang::DiagnosticsEngine::IncrementAllExtensionsSilenced
void IncrementAllExtensionsSilenced()
Counter bumped when an extension block is/ encountered.
Definition: Diagnostic.h:784
clang::StreamingDiagnostic::DiagStorageAllocator::Allocate
DiagnosticStorage * Allocate()
Allocate new storage.
Definition: Diagnostic.h:1125
clang::FullSourceLoc
A SourceLocation and its associated SourceManager.
Definition: SourceLocation.h:368
clang::DeclaratorContext::File
@ File
Error
llvm::Error Error
Definition: ByteCodeEmitter.cpp:20
clang::DiagnosticsEngine::setSeverity
void setSeverity(diag::kind Diag, diag::Severity Map, SourceLocation Loc)
This allows the client to specify that certain warnings are ignored.
Definition: Diagnostic.cpp:358
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::DiagnosticsEngine::setClient
void setClient(DiagnosticConsumer *client, bool ShouldOwnClient=true)
Set the diagnostic client associated with this diagnostic object.
Definition: Diagnostic.cpp:112
clang::ForwardingDiagnosticConsumer
Diagnostic consumer that forwards diagnostics along to an existing, already-initialized diagnostic co...
Definition: Diagnostic.h:1806
clang::Diagnostic::getArgStdStr
const std::string & getArgStdStr(unsigned Idx) const
Return the provided argument string specified by Idx.
Definition: Diagnostic.h:1592
clang::ProcessWarningOptions
void ProcessWarningOptions(DiagnosticsEngine &Diags, const DiagnosticOptions &Opts, bool ReportDiags=true)
ProcessWarningOptions - Initialize the diagnostic client and process the warning options specified on...
Definition: Warnings.cpp:44
clang::FixItHint::CreateInsertion
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:97
clang::TemplateDiffTypes::TemplateDiffUsed
unsigned TemplateDiffUsed
Definition: Diagnostic.h:1830
clang::DiagnosticsEngine::popMappings
bool popMappings(SourceLocation Loc)
Pops the current DiagMappings off the top of the stack, causing the new top of the stack to be the ac...
Definition: Diagnostic.cpp:122
clang::DiagnosticErrorTrap::reset
void reset()
Set to initial state of "no errors occurred".
Definition: Diagnostic.h:1094
Diag
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Definition: LiteralSupport.cpp:79
clang::DiagnosticsEngine::setConstexprBacktraceLimit
void setConstexprBacktraceLimit(unsigned Limit)
Specify the maximum number of constexpr evaluation notes to emit along with a given diagnostic.
Definition: Diagnostic.h:632
llvm::SmallVector
Definition: LLVM.h:38
clang::DiagnosticsEngine::setDiagnosticGroupErrorAsFatal
bool setDiagnosticGroupErrorAsFatal(StringRef Group, bool Enabled)
Set the error-as-fatal flag for the given diagnostic group.
Definition: Diagnostic.cpp:459
clang::DiagnosticsEngine::setIgnoreAllWarnings
void setIgnoreAllWarnings(bool Val)
When set to true, any unmapped warnings are ignored.
Definition: Diagnostic.h:645
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::DiagnosticsEngine::getElideType
bool getElideType()
Definition: Diagnostic.h:698
clang::StoredDiagnostic::StoredDiagnostic
StoredDiagnostic()=default
clang::DiagnosticsEngine::isIgnored
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Definition: Diagnostic.h:911
clang::DiagnosticsEngine::getDiagnosticOptions
DiagnosticOptions & getDiagnosticOptions() const
Retrieve the diagnostic options.
Definition: Diagnostic.h:557
clang::MultiVersionKind::Target
@ Target
clang::DiagnosticsEngine::ak_identifierinfo
@ ak_identifierinfo
IdentifierInfo.
Definition: Diagnostic.h:221
clang::DiagnosticStorage::DiagArgumentsKind
unsigned char DiagArgumentsKind[MaxArguments]
Specifies for each argument whether it is in DiagArgumentsStr or in DiagArguments.
Definition: Diagnostic.h:163
clang::FixItHint::FixItHint
FixItHint()=default
Empty code modification hint, indicating that no code modification is known.
clang::DiagnosticConsumer
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1739
clang::DiagnosticErrorTrap::hasErrorOccurred
bool hasErrorOccurred() const
Determine whether any errors have occurred since this object instance was created.
Definition: Diagnostic.h:1083
clang::DiagnosticConsumer::NumErrors
unsigned NumErrors
Number of errors reported.
Definition: Diagnostic.h:1742
clang::DiagnosticsEngine::hasUnrecoverableErrorOccurred
bool hasUnrecoverableErrorOccurred() const
Determine whether any kind of unrecoverable error has occurred.
Definition: Diagnostic.h:848
clang::StoredDiagnostic::range_size
unsigned range_size() const
Definition: Diagnostic.h:1717
clang::DiagnosticConsumer::getNumErrors
unsigned getNumErrors() const
Definition: Diagnostic.h:1748
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
clang::DiagnosticsEngine::hasSourceManager
bool hasSourceManager() const
Definition: Diagnostic.h:577
clang::DiagnosticsEngine::getNumOverloadCandidatesToShow
unsigned getNumOverloadCandidatesToShow() const
When a call or operator fails, print out up to this many candidate overloads as suggestions.
Definition: Diagnostic.h:726
clang::Diagnostic::getRawArg
uint64_t getRawArg(unsigned Idx) const
Return the specified non-string argument in an opaque form.
Definition: Diagnostic.h:1634
clang::StoredDiagnostic::getRanges
ArrayRef< CharSourceRange > getRanges() const
Definition: Diagnostic.h:1719
clang::DiagnosticsEngine::setEnableAllWarnings
void setEnableAllWarnings(bool Val)
When set to true, any unmapped ignored warnings are no longer ignored.
Definition: Diagnostic.h:656
clang::DiagnosticsEngine::setElideType
void setElideType(bool Val)
Set type eliding, to skip outputting same types occurring in template types.
Definition: Diagnostic.h:697
clang::DiagnosticsEngine::getFlagValue
StringRef getFlagValue() const
Return the value associated with this diagnostic flag.
Definition: Diagnostic.h:980
llvm::Optional
Definition: LLVM.h:40
clang::DiagnosticIDs::Level
Level
The level of the diagnostic, after it has been through mapping.
Definition: DiagnosticIDs.h:169
clang::DiagnosticsEngine::setLastDiagnosticIgnored
void setLastDiagnosticIgnored(bool Ignored)
Pretend that the last diagnostic issued was ignored, so any subsequent notes will be suppressed,...
Definition: Diagnostic.h:756
clang::TemplateDiffTypes::ToType
intptr_t ToType
Definition: Diagnostic.h:1823
clang::DiagnosticErrorTrap::hasUnrecoverableErrorOccurred
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred since this object instance was created.
Definition: Diagnostic.h:1089
clang::DiagnosticsEngine::Reset
void Reset(bool soft=false)
Reset the state of the diagnostic object to its initial configuration.
Definition: Diagnostic.cpp:134
clang::DiagnosticsEngine::setSeverityForGroup
bool setSeverityForGroup(diag::Flavor Flavor, StringRef Group, diag::Severity Map, SourceLocation Loc=SourceLocation())
Change an entire diagnostic group (e.g.
Definition: Diagnostic.cpp:405
clang::StoredDiagnostic::getMessage
StringRef getMessage() const
Definition: Diagnostic.h:1709
clang::DiagnosticsEngine::setSuppressAllDiagnostics
void setSuppressAllDiagnostics(bool Val)
Suppress all diagnostics, to silence the front end when we know that we don't want any more diagnosti...
Definition: Diagnostic.h:692
clang::DiagnosticsEngine::hasUncompilableErrorOccurred
bool hasUncompilableErrorOccurred() const
Errors that actually prevent compilation, not those that are upgraded from a warning by -Werror.
Definition: Diagnostic.h:842
DiagnosticIDs.h
clang::diag::Group
Group
Definition: DiagnosticCategories.h:23
clang::Ovl_Best
@ Ovl_Best
Show just the "best" overload candidates.
Definition: DiagnosticOptions.h:34
clang::Diagnostic::getDiags
const DiagnosticsEngine * getDiags() const
Definition: Diagnostic.h:1570
clang::DiagnosticConsumer::EndSourceFile
virtual void EndSourceFile()
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: Diagnostic.h:1771
clang::DiagnosticErrorTrap
RAII class that determines when any errors have occurred between the time the instance was created an...
Definition: Diagnostic.h:1072
clang::StoredDiagnostic::getID
unsigned getID() const
Definition: Diagnostic.h:1706
clang::DiagnosticsEngine::DiagnosticBuilder
friend class DiagnosticBuilder
Definition: Diagnostic.h:990
clang::DiagnosticsEngine::ASTWriter
friend class ASTWriter
Definition: Diagnostic.h:1044
clang::StreamingDiagnostic::AddTaggedVal
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
Definition: Diagnostic.h:1184
clang::DiagnosticsEngine::getDiagnosticMappings
diag_mapping_range getDiagnosticMappings() const
Get the current set of diagnostic mappings.
Definition: Diagnostic.h:562
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:637
clang::DiagnosticStorage
Definition: Diagnostic.h:148
llvm::RefCountedBase
Definition: LLVM.h:49
clang::DiagnosticStorage::DiagRanges
SmallVector< CharSourceRange, 8 > DiagRanges
The list of ranges added to this diagnostic.
Definition: Diagnostic.h:177
Offset
unsigned Offset
Definition: Format.cpp:2717
clang::StoredDiagnostic::getFixIts
ArrayRef< FixItHint > getFixIts() const
Definition: Diagnostic.h:1729
clang::FixItHint::CreateRemoval
static FixItHint CreateRemoval(SourceRange RemoveRange)
Definition: Diagnostic.h:128
clang::FixItHint
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Definition: Diagnostic.h:71
clang::Diagnostic
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1561
clang::TemplateDiffTypes
Definition: Diagnostic.h:1821
clang::StreamingDiagnostic::Allocator
DiagStorageAllocator * Allocator
Allocator used to allocate storage for this diagnostic.
Definition: Diagnostic.h:1151
clang::CharSourceRange::getCharRange
static CharSourceRange getCharRange(SourceRange R)
Definition: SourceLocation.h:265
clang::DiagnosticStorage::MaxArguments
@ MaxArguments
The maximum number of arguments we can hold.
Definition: Diagnostic.h:155
clang::DiagnosticsEngine::setPrintTemplateTree
void setPrintTemplateTree(bool Val)
Set tree printing, to outputting the template difference in a tree format.
Definition: Diagnostic.h:702
clang::DiagnosticStorage::DiagArgumentsStr
std::string DiagArgumentsStr[MaxArguments]
The values for the various substitution positions that have string arguments.
Definition: Diagnostic.h:174
clang::DiagnosticConsumer::NumWarnings
unsigned NumWarnings
Number of warnings reported.
Definition: Diagnostic.h:1741
clang::DiagnosticsEngine::setDiagnosticGroupWarningAsError
bool setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled)
Set the warning-as-error flag for the given diagnostic group.
Definition: Diagnostic.cpp:428
clang::diag::Severity::Ignored
@ Ignored
Do not present this diagnostic, ignore it.
clang::DiagnosticConsumer::HandleDiagnostic
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info)
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
Definition: Diagnostic.cpp:564
V
#define V(N, I)
Definition: ASTContext.h:3208
clang::DiagnosticsEngine::ArgumentKind
ArgumentKind
Definition: Diagnostic.h:204
clang::StoredDiagnostic::range_begin
range_iterator range_begin() const
Definition: Diagnostic.h:1715
clang::Ovl_All
@ Ovl_All
Show all overloads.
Definition: DiagnosticOptions.h:31
clang::StreamingDiagnostic::StreamingDiagnostic
StreamingDiagnostic(DiagStorageAllocator &Alloc)
Construct with a storage allocator which will manage the storage.
Definition: Diagnostic.h:1241
clang::DiagnosticsEngine::setErrorLimit
void setErrorLimit(unsigned Limit)
Specify a limit for the number of errors we should emit before giving up.
Definition: Diagnostic.h:616
clang::DiagnosticsEngine::getShowOverloads
OverloadsShown getShowOverloads() const
Definition: Diagnostic.h:717
clang::ForwardingDiagnosticConsumer::IncludeInDiagnosticCounts
bool IncludeInDiagnosticCounts() const override
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
Definition: Diagnostic.cpp:1212
clang::DiagnosticsEngine::isLastDiagnosticIgnored
bool isLastDiagnosticIgnored() const
Determine whether the previous diagnostic was ignored.
Definition: Diagnostic.h:765
clang::DiagnosticsEngine::takeClient
std::unique_ptr< DiagnosticConsumer > takeClient()
Return the current diagnostic client along with ownership of that client.
Definition: Diagnostic.h:575
clang::AddFlagValue
Definition: Diagnostic.h:1372
clang::DiagnosticsEngine::hasFatalErrorOccurred
bool hasFatalErrorOccurred() const
Definition: Diagnostic.h:845
clang::DiagnosticBuilder::Clear
void Clear() const
Clear out the current diagnostic.
Definition: Diagnostic.h:1298
hlsl::uint64_t
unsigned long uint64_t
Definition: hlsl_basic_types.h:25
clang::StreamingDiagnostic::DiagStorage
DiagnosticStorage * DiagStorage
Definition: Diagnostic.h:1148
clang::DiagnosticsEngine::Remark
@ Remark
Definition: Diagnostic.h:198
clang::TemplateDiffTypes::FromType
intptr_t FromType
Definition: Diagnostic.h:1822
clang::DiagnosticsEngine::setExtensionHandlingBehavior
void setExtensionHandlingBehavior(diag::Severity H)
Controls whether otherwise-unmapped extension diagnostics are mapped onto ignore/warning/error.
Definition: Diagnostic.h:773
clang::DiagnosticsEngine::hasErrorOccurred
bool hasErrorOccurred() const
Definition: Diagnostic.h:838
clang::StreamingDiagnostic
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1110
clang::DiagnosticsEngine::setSuppressSystemWarnings
void setSuppressSystemWarnings(bool Val)
When set to true mask warnings that come from system headers.
Definition: Diagnostic.h:682
clang::DiagnosticsEngine::Clear
void Clear()
Clear out the current diagnostic.
Definition: Diagnostic.h:977
clang::FixItHint::CreateReplacement
static FixItHint CreateReplacement(SourceRange RemoveRange, StringRef Code)
Definition: Diagnostic.h:142
clang::DiagnosticsEngine::EmitCurrentDiagnostic
bool EmitCurrentDiagnostic(bool Force=false)
Emit the current diagnostic and clear the diagnostic state.
Definition: Diagnostic.cpp:530
clang::Diagnostic::getNumArgs
unsigned getNumArgs() const
Definition: Diagnostic.h:1576
clang::DiagnosticMapping
Definition: DiagnosticIDs.h:101
clang::DiagnosticsEngine::Error
@ Error
Definition: Diagnostic.h:200
clang::Diagnostic::getArgCStr
const char * getArgCStr(unsigned Idx) const
Return the specified C string argument.
Definition: Diagnostic.h:1600
intptr_t
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type,...
Definition: opencl-c-base.h:133
clang::DiagnosticsEngine::ak_attr
@ ak_attr
Attr *.
Definition: Diagnostic.h:248
clang::DiagnosticsEngine::getCurrentDiagLoc
SourceLocation getCurrentDiagLoc() const
Definition: Diagnostic.h:1059
clang::DiagnosticBuilder::addFlagValue
void addFlagValue(StringRef V) const
Definition: Diagnostic.h:1369
clang::DiagnosticsEngine::getDiagnosticIDs
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
Definition: Diagnostic.h:552
clang::DiagNullabilityKind
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
Definition: Diagnostic.h:1532
clang::DiagnosticIDs::Note
@ Note
Definition: DiagnosticIDs.h:170
clang::FixItHint::BeforePreviousInsertions
bool BeforePreviousInsertions
Definition: Diagnostic.h:85
clang::DiagnosticsEngine::getClient
DiagnosticConsumer * getClient()
Definition: Diagnostic.h:567
clang::DiagnosticsEngine::setShowColors
void setShowColors(bool Val)
Set color printing, so the type diffing will inject color markers into the output.
Definition: Diagnostic.h:707
bool
#define bool
Definition: stdbool.h:20
clang::DiagnosticsEngine::overloadCandidatesShown
void overloadCandidatesShown(unsigned N)
Call this after showing N overload candidates.
Definition: Diagnostic.h:741
clang::DiagnosticsEngine::ak_qualtype_pair
@ ak_qualtype_pair
pair<QualType, QualType>
Definition: Diagnostic.h:245
clang::FixItHint::InsertFromRange
CharSourceRange InsertFromRange
Code in the specific range that should be inserted in the insertion location.
Definition: Diagnostic.h:79
clang::DiagnosticsEngine::getNumWarnings
unsigned getNumWarnings() const
Definition: Diagnostic.h:853
clang::DiagnosticsEngine::getConstexprBacktraceLimit
unsigned getConstexprBacktraceLimit() const
Retrieve the maximum number of constexpr evaluation notes to emit along with a given diagnostic.
Definition: Diagnostic.h:638
clang::DiagnosticsEngine::ak_sint
@ ak_sint
int
Definition: Diagnostic.h:212
clang::StreamingDiagnostic::DiagStorageAllocator::Deallocate
void Deallocate(DiagnosticStorage *S)
Free the given storage object.
Definition: Diagnostic.h:1137
clang::DiagnosticsEngine::ownsClient
bool ownsClient() const
Determine whether this DiagnosticsEngine object own its client.
Definition: Diagnostic.h:571
clang::StoredDiagnostic::range_end
range_iterator range_end() const
Definition: Diagnostic.h:1716
clang::ASTWriter
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:85
clang::Diagnostic::getArgUInt
uint64_t getArgUInt(unsigned Idx) const
Return the specified unsigned integer argument.
Definition: Diagnostic.h:1617
clang::operator<<
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
Definition: ASTContext.cpp:13391
clang::DiagnosticConsumer::~DiagnosticConsumer
virtual ~DiagnosticConsumer()
clang::Diagnostic::Diagnostic
Diagnostic(const DiagnosticsEngine *DO)
Definition: Diagnostic.h:1566
clang::DiagnosticsEngine::ak_tokenkind
@ ak_tokenkind
enum TokenKind : unsigned
Definition: Diagnostic.h:218
clang::DiagnosticConsumer::IncludeInDiagnosticCounts
virtual bool IncludeInDiagnosticCounts() const
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
Definition: Diagnostic.cpp:1195
clang::DiagnosticsEngine::DiagnosticsTestHelper
friend void DiagnosticsTestHelper(DiagnosticsEngine &)
clang::DiagnosticsEngine::getFatalsAsError
bool getFatalsAsError() const
Definition: Diagnostic.h:679
clang::AddFlagValue::AddFlagValue
AddFlagValue(StringRef V)
Definition: Diagnostic.h:1375
clang::StreamingDiagnostic::DiagStorageAllocator::DiagStorageAllocator
DiagStorageAllocator()
clang::DiagnosticBuilder::operator=
DiagnosticBuilder & operator=(const DiagnosticBuilder &)=delete
clang::Diagnostic::getArgSInt
int64_t getArgSInt(unsigned Idx) const
Return the specified signed integer argument.
Definition: Diagnostic.h:1609
clang::StoredDiagnostic
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
Definition: Diagnostic.h:1685
clang::DiagnosticsEngine::operator=
DiagnosticsEngine & operator=(const DiagnosticsEngine &)=delete
clang::StoredDiagnostic::fixit_iterator
std::vector< FixItHint >::const_iterator fixit_iterator
Definition: Diagnostic.h:1723
clang::DiagnosticsEngine::ak_declarationname
@ ak_declarationname
DeclarationName.
Definition: Diagnostic.h:233
clang::FixItHint::isNull
bool isNull() const
Definition: Diagnostic.h:91
clang::DiagnosticBuilder::operator<<
const DiagnosticBuilder & operator<<(T &&V) const
Definition: Diagnostic.h:1351
clang::Diagnostic::Diagnostic
Diagnostic(const DiagnosticsEngine *DO, StringRef storedDiagMessage)
Definition: Diagnostic.h:1567
clang::StoredDiagnostic::setLocation
void setLocation(FullSourceLoc Loc)
Definition: Diagnostic.h:1711
SourceLocation.h
clang::tok::TokenKind
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
clang::DiagnosticsEngine::setWarningsAsErrors
void setWarningsAsErrors(bool Val)
When set to true, any warnings reported are issued as errors.
Definition: Diagnostic.h:664
clang::DiagnosticsEngine::~DiagnosticsEngine
~DiagnosticsEngine()
Definition: Diagnostic.cpp:98
clang::StoredDiagnostic::getLocation
const FullSourceLoc & getLocation() const
Definition: Diagnostic.h:1708
clang::FixItHint::CodeToInsert
std::string CodeToInsert
The actual code to insert at the insertion location, as a string.
Definition: Diagnostic.h:83
clang::DiagnosticsEngine::setFatalsAsError
void setFatalsAsError(bool Val)
When set to true, any fatal error reported is made an error.
Definition: Diagnostic.h:678
clang::DiagnosticConsumer::BeginSourceFile
virtual void BeginSourceFile(const LangOptions &LangOpts, const Preprocessor *PP=nullptr)
Callback to inform the diagnostic client that processing of a source file is beginning.
Definition: Diagnostic.h:1763
clang::StoredDiagnostic::range_iterator
std::vector< CharSourceRange >::const_iterator range_iterator
Definition: Diagnostic.h:1713
clang::DiagnosticsEngine::notePriorDiagnosticFrom
void notePriorDiagnosticFrom(const DiagnosticsEngine &Other)
Note that the prior diagnostic was emitted by some other DiagnosticsEngine, and we may be attaching a...
Definition: Diagnostic.h:891
clang::DiagnosticsEngine::Ignored
@ Ignored
Definition: Diagnostic.h:196
clang::Diagnostic::getLocation
const SourceLocation & getLocation() const
Definition: Diagnostic.h:1572
clang::CharSourceRange::getTokenRange
static CharSourceRange getTokenRange(SourceRange R)
Definition: SourceLocation.h:261
clang::ForwardingDiagnosticConsumer::~ForwardingDiagnosticConsumer
~ForwardingDiagnosticConsumer() override
clang::Diagnostic::getFixItHint
const FixItHint & getFixItHint(unsigned Idx) const
Definition: Diagnostic.h:1660
llvm::ArrayRef
Definition: LLVM.h:34
clang::StreamingDiagnostic::AddString
void AddString(StringRef V) const
Definition: Diagnostic.h:1194
clang::DiagnosticsEngine::diag_mapping_range
llvm::iterator_range< DiagState::const_iterator > diag_mapping_range
Definition: Diagnostic.h:559
clang::StreamingDiagnostic::DiagStorageAllocator::~DiagStorageAllocator
~DiagStorageAllocator()
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:253
clang::Diagnostic::getFixItHints
ArrayRef< FixItHint > getFixItHints() const
Definition: Diagnostic.h:1665
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:358
clang::DiagnosticsEngine::getEnableAllWarnings
bool getEnableAllWarnings() const
Definition: Diagnostic.h:659
clang::DiagnosticsEngine::ak_nameddecl
@ ak_nameddecl
NamedDecl *.
Definition: Diagnostic.h:236
clang::StoredDiagnostic::fixit_end
fixit_iterator fixit_end() const
Definition: Diagnostic.h:1726
clang::ToggleHighlight
const char ToggleHighlight
Special character that the diagnostic printer will use to toggle the bold attribute.
Definition: Diagnostic.h:1835
clang::StreamingDiagnostic::getStorage
DiagnosticStorage * getStorage() const
Retrieve storage for this particular diagnostic.
Definition: Diagnostic.h:1155
clang::DiagnosticIDs
Used for handling and querying diagnostic IDs.
Definition: DiagnosticIDs.h:166
State
LineState State
Definition: UnwrappedLineFormatter.cpp:1147
clang::ForwardingDiagnosticConsumer::HandleDiagnostic
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
Definition: Diagnostic.cpp:1201
clang::StreamingDiagnostic::freeStorage
void freeStorage()
Definition: Diagnostic.h:1164
clang::Diagnostic::getSourceManager
SourceManager & getSourceManager() const
Definition: Diagnostic.h:1574
clang::StreamingDiagnostic::StreamingDiagnostic
StreamingDiagnostic(DiagnosticStorage *Storage)
Construct with an external storage not owned by itself.
Definition: Diagnostic.h:1236
clang::StoredDiagnostic::getLevel
DiagnosticsEngine::Level getLevel() const
Definition: Diagnostic.h:1707
clang::diag::Flavor
Flavor
Flavors of diagnostics we can emit.
Definition: DiagnosticIDs.h:93
clang::DiagnosticsEngine::getExtensionHandlingBehavior
diag::Severity getExtensionHandlingBehavior() const
Definition: Diagnostic.h:776
clang::DiagnosticMapping::setNoErrorAsFatal
void setNoErrorAsFatal(bool Value)
Definition: DiagnosticIDs.h:137
clang::DiagnosticConsumer::finish
virtual void finish()
Callback to inform the diagnostic client that processing of all source files has ended.
Definition: Diagnostic.h:1775
clang::DiagnosticsEngine::DiagnosticsEngine
DiagnosticsEngine(IntrusiveRefCntPtr< DiagnosticIDs > Diags, IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, DiagnosticConsumer *client=nullptr, bool ShouldOwnClient=true)
Definition: Diagnostic.cpp:87
clang::DiagnosticIDs::Error
@ Error
Definition: DiagnosticIDs.h:170
clang::DiagnosticIDs::Remark
@ Remark
Definition: DiagnosticIDs.h:170
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:85
clang::Diagnostic::getArgKind
DiagnosticsEngine::ArgumentKind getArgKind(unsigned Idx) const
Return the kind of the specified index.
Definition: Diagnostic.h:1584
clang::StreamingDiagnostic::freeStorageSlow
void freeStorageSlow()
Definition: Diagnostic.h:1177
clang::PartialDiagnostic
Definition: PartialDiagnostic.h:31
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:81
clang::DiagnosticsEngine::ak_addrspace
@ ak_addrspace
address space
Definition: Diagnostic.h:224
clang::DiagnosticIDs::Warning
@ Warning
Definition: DiagnosticIDs.h:170
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::DiagnosticsEngine::setErrorsAsFatal
void setErrorsAsFatal(bool Val)
When set to true, any error reported is made a fatal error.
Definition: Diagnostic.h:672
clang::DiagnosticsEngine::hasAllExtensionsSilenced
bool hasAllExtensionsSilenced()
Definition: Diagnostic.h:786
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:359
clang::DiagnosticsEngine::getShowColors
bool getShowColors()
Definition: Diagnostic.h:708
clang::DiagnosticsEngine::ArgumentValue
std::pair< ArgumentKind, intptr_t > ArgumentValue
Represents on argument value, which is a union discriminated by ArgumentKind, with a value.
Definition: Diagnostic.h:253
clang::DiagnosticStorage::DiagnosticStorage
DiagnosticStorage()=default
clang::DiagnosticBuilder::isActive
bool isActive() const
Determine whether this diagnostic is still active.
Definition: Diagnostic.h:1305
clang::StreamingDiagnostic::~StreamingDiagnostic
~StreamingDiagnostic()
Definition: Diagnostic.h:1247
clang::DiagnosticBuilder::~DiagnosticBuilder
~DiagnosticBuilder()
Emits the diagnostic.
Definition: Diagnostic.h:1361
clang::DiagnosticsEngine::getIgnoreAllWarnings
bool getIgnoreAllWarnings() const
Definition: Diagnostic.h:648
clang::DiagnosticsEngine::getCustomDiagID
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:868
clang::DiagnosticsEngine::dump
LLVM_DUMP_METHOD void dump() const
Definition: Diagnostic.cpp:104
clang::CharSourceRange::isValid
bool isValid() const
Definition: SourceLocation.h:291
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::DiagnosticsEngine::ConvertArgToString
void ConvertArgToString(ArgumentKind Kind, intptr_t Val, StringRef Modifier, StringRef Argument, ArrayRef< ArgumentValue > PrevArgs, SmallVectorImpl< char > &Output, ArrayRef< intptr_t > QualTypeVals) const
Converts a diagnostic argument (as an intptr_t) into the string that represents it.
Definition: Diagnostic.h:875
clang::DiagnosticsEngine::getErrorsAsFatal
bool getErrorsAsFatal() const
Definition: Diagnostic.h:673
clang
Definition: CalledOnceCheck.h:17
clang::DiagnosticsEngine::ak_uint
@ ak_uint
unsigned
Definition: Diagnostic.h:215
hlsl::int64_t
long int64_t
Definition: hlsl_basic_types.h:26
clang::StoredDiagnostic::fixit_size
unsigned fixit_size() const
Definition: Diagnostic.h:1727
clang::Diagnostic::getRanges
ArrayRef< CharSourceRange > getRanges() const
Return an array reference for this diagnostic's ranges.
Definition: Diagnostic.h:1652
clang::DiagnosticConsumer::DiagnosticConsumer
DiagnosticConsumer()=default
clang::DiagnosticsEngine::ak_c_string
@ ak_c_string
const char *
Definition: Diagnostic.h:209
clang::DiagnosticIDs::Ignored
@ Ignored
Definition: DiagnosticIDs.h:170
clang::DiagnosticsEngine::SetDelayedDiagnostic
void SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1="", StringRef Arg2="", StringRef Arg3="")
Set the "delayed" diagnostic that will be emitted once the current diagnostic completes.
Definition: Diagnostic.cpp:162
clang::DiagnosticStorage::NumDiagArgs
unsigned char NumDiagArgs
The number of entries in Arguments.
Definition: Diagnostic.h:159
clang::DiagnosticsEngine::getPrintTemplateTree
bool getPrintTemplateTree()
Definition: Diagnostic.h:703
clang::Diagnostic::getRange
const CharSourceRange & getRange(unsigned Idx) const
Definition: Diagnostic.h:1646
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::DiagnosticConsumer::clear
virtual void clear()
Definition: Diagnostic.h:1750
clang::FixItHint::CreateRemoval
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:123
clang::StreamingDiagnostic::AddFixItHint
void AddFixItHint(const FixItHint &Hint) const
Definition: Diagnostic.h:1212
clang::DiagnosticsEngine::getSuppressAllDiagnostics
bool getSuppressAllDiagnostics() const
Definition: Diagnostic.h:693
clang::IgnoringDiagConsumer
A diagnostic client that ignores all diagnostics.
Definition: Diagnostic.h:1794
clang::DiagnosticsEngine::setShowOverloads
void setShowOverloads(OverloadsShown Val)
Specify which overload candidates to show when overload resolution fails.
Definition: Diagnostic.h:714
unsigned
clang::DiagnosticMapping::Make
static DiagnosticMapping Make(diag::Severity Severity, bool IsUser, bool IsPragma)
Definition: DiagnosticIDs.h:110
clang::DiagnosticBuilder::Emit
bool Emit()
Force the diagnostic builder to emit the diagnostic now.
Definition: Diagnostic.h:1314
clang::ForwardingDiagnosticConsumer::ForwardingDiagnosticConsumer
ForwardingDiagnosticConsumer(DiagnosticConsumer &Target)
Definition: Diagnostic.h:1810
clang::DiagnosticsEngine::setTemplateBacktraceLimit
void setTemplateBacktraceLimit(unsigned Limit)
Specify the maximum number of template instantiation notes to emit along with a given diagnostic.
Definition: Diagnostic.h:620
clang::DiagnosticsEngine::getCurrentDiagID
unsigned getCurrentDiagID() const
Definition: Diagnostic.h:1057
clang::ForwardingDiagnosticConsumer::clear
void clear() override
Definition: Diagnostic.cpp:1207
clang::DiagnosticStorage::DiagArgumentsVal
uint64_t DiagArgumentsVal[MaxArguments]
The values for the various substitution positions.
Definition: Diagnostic.h:170
clang::DiagnosticsEngine::setSourceManager
void setSourceManager(SourceManager *SrcMgr)
Definition: Diagnostic.h:584
DiagnosticOptions.h
clang::DiagnosticsEngine::setSeverityForAll
void setSeverityForAll(diag::Flavor Flavor, diag::Severity Map, SourceLocation Loc=SourceLocation())
Add the specified mapping to all diagnostics of the specified flavor.
Definition: Diagnostic.cpp:489
clang::Diagnostic::hasSourceManager
bool hasSourceManager() const
Definition: Diagnostic.h:1573
clang::DiagnosticsEngine::pushMappings
void pushMappings(SourceLocation Loc)
Copies the current DiagMappings and pushes the new copy onto the top of the stack.
Definition: Diagnostic.cpp:118
clang::DiagnosticsEngine::isDiagnosticInFlight
bool isDiagnosticInFlight() const
Determine whethere there is already a diagnostic in flight.
Definition: Diagnostic.h:944
clang::TemplateDiffTypes::PrintFromType
unsigned PrintFromType
Definition: Diagnostic.h:1825
clang::DiagnosticsEngine::ASTReader
friend class ASTReader
Definition: Diagnostic.h:1043
Parent
NodeId Parent
Definition: ASTDiff.cpp:190
clang::DiagnosticsEngine::Fatal
@ Fatal
Definition: Diagnostic.h:201
clang::TemplateDiffTypes::ShowColors
unsigned ShowColors
Definition: Diagnostic.h:1827
clang::DiagnosticsEngine::Note
@ Note
Definition: Diagnostic.h:197
clang::FixItHint::RemoveRange
CharSourceRange RemoveRange
Code that should be replaced to correct the error.
Definition: Diagnostic.h:75
clang::DiagnosticsEngine::getTemplateBacktraceLimit
unsigned getTemplateBacktraceLimit() const
Retrieve the maximum number of template instantiation notes to emit along with a given diagnostic.
Definition: Diagnostic.h:626
clang::DiagnosticsEngine::getDiagnosticLevel
Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const
Based on the way the client configured the DiagnosticsEngine object, classify the specified diagnosti...
Definition: Diagnostic.h:926
clang::DiagnosticBuilder::operator<<
const DiagnosticBuilder & operator<<(const T &V) const
Definition: Diagnostic.h:1339
clang::Diagnostic::getArgIdentifier
const IdentifierInfo * getArgIdentifier(unsigned Idx) const
Return the specified IdentifierInfo argument.
Definition: Diagnostic.h:1625
clang::Diagnostic::getID
unsigned getID() const
Definition: Diagnostic.h:1571
llvm::SmallVectorImpl< char >
clang::DiagnosticsEngine::getWarningsAsErrors
bool getWarningsAsErrors() const
Definition: Diagnostic.h:667
clang::DiagnosticsEngine::getNumErrors
unsigned getNumErrors() const
Definition: Diagnostic.h:852
clang::TemplateDiffTypes::ElideType
unsigned ElideType
Definition: Diagnostic.h:1826
true
#define true
Definition: stdbool.h:21
clang::DiagnosticsEngine::getSourceManager
SourceManager & getSourceManager() const
Definition: Diagnostic.h:579
clang::TemplateDiffTypes::PrintTree
unsigned PrintTree
Definition: Diagnostic.h:1824
clang::DiagnosticMapping::setNoWarningAsError
void setNoWarningAsError(bool Value)
Definition: DiagnosticIDs.h:134
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:129
clang::DiagnosticsEngine::ak_qualtype
@ ak_qualtype
QualType.
Definition: Diagnostic.h:230
clang::DiagnosticsEngine::getClient
const DiagnosticConsumer * getClient() const
Definition: Diagnostic.h:568
clang::DiagnosticErrorTrap::DiagnosticErrorTrap
DiagnosticErrorTrap(DiagnosticsEngine &Diag)
Definition: Diagnostic.h:1078
clang::DiagnosticBuilder::setForceEmit
const DiagnosticBuilder & setForceEmit() const
Forces the diagnostic to be emitted.
Definition: Diagnostic.h:1364
clang::Diagnostic::FormatDiagnostic
void FormatDiagnostic(SmallVectorImpl< char > &OutStr) const
Format this diagnostic into a string, substituting the formal arguments into the %0 slots.
Definition: Diagnostic.cpp:795
clang::DiagnosticsEngine::Warning
@ Warning
Definition: Diagnostic.h:199
clang::DiagnosticsEngine::ak_std_string
@ ak_std_string
std::string
Definition: Diagnostic.h:206
clang::OverloadsShown
OverloadsShown
Specifies which overload candidates to display when overload resolution fails.
Definition: DiagnosticOptions.h:29
clang::DiagnosticsEngine::setNumWarnings
void setNumWarnings(unsigned NumWarnings)
Definition: Diagnostic.h:855
clang::DiagnosticsEngine::ak_declcontext
@ ak_declcontext
DeclContext *.
Definition: Diagnostic.h:242
clang::DiagnosticStorage::FixItHints
SmallVector< FixItHint, 6 > FixItHints
If valid, provides a hint with some code to insert, remove, or modify at a particular position.
Definition: Diagnostic.h:181
clang::StreamingDiagnostic::DiagStorageAllocator
An allocator for DiagnosticStorage objects, which uses a small cache to objects, used to reduce mallo...
Definition: Diagnostic.h:1114
clang::StreamingDiagnostic::AddSourceRange
void AddSourceRange(const CharSourceRange &R) const
Definition: Diagnostic.h:1205
clang::Diagnostic::getNumRanges
unsigned getNumRanges() const
Return the number of source ranges associated with this diagnostic.
Definition: Diagnostic.h:1641
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:47
clang::FixItHint::CreateReplacement
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Definition: Diagnostic.h:134
clang::StoredDiagnostic::fixit_begin
fixit_iterator fixit_begin() const
Definition: Diagnostic.h:1725
clang::DiagnosticsEngine::getSuppressSystemWarnings
bool getSuppressSystemWarnings() const
Definition: Diagnostic.h:685
clang::DiagnosticOptions
Options for controlling the compiler diagnostics engine.
Definition: DiagnosticOptions.h:70
clang::DiagnosticBuilder::DiagnosticBuilder
DiagnosticBuilder(const DiagnosticBuilder &D)
Copy constructor.
Definition: Diagnostic.h:1331
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1537
clang::DiagnosticsEngine::DecrementAllExtensionsSilenced
void DecrementAllExtensionsSilenced()
Definition: Diagnostic.h:785
clang::DiagnosticConsumer::getNumWarnings
unsigned getNumWarnings() const
Definition: Diagnostic.h:1749
clang::FixItHint::CreateInsertionFromRange
static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc, CharSourceRange FromRange, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code from FromRange at a specific location.
Definition: Diagnostic.h:110
clang::DiagnosticsEngine::ak_nestednamespec
@ ak_nestednamespec
NestedNameSpecifier *.
Definition: Diagnostic.h:239
clang::DiagnosticIDs::Fatal
@ Fatal
Definition: DiagnosticIDs.h:170