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