clang  14.0.0git
Diagnostic.cpp
Go to the documentation of this file.
1 //===- Diagnostic.cpp - C Language Family Diagnostic Handling -------------===//
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 // This file implements the Diagnostic-related interfaces.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/Basic/Diagnostic.h"
14 #include "clang/Basic/CharInfo.h"
22 #include "clang/Basic/Specifiers.h"
23 #include "clang/Basic/TokenKinds.h"
24 #include "llvm/ADT/SmallString.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/ADT/StringExtras.h"
27 #include "llvm/ADT/StringRef.h"
28 #include "llvm/Support/CrashRecoveryContext.h"
29 #include "llvm/Support/Locale.h"
30 #include "llvm/Support/raw_ostream.h"
31 #include <algorithm>
32 #include <cassert>
33 #include <cstddef>
34 #include <cstdint>
35 #include <cstring>
36 #include <limits>
37 #include <string>
38 #include <utility>
39 #include <vector>
40 
41 using namespace clang;
42 
44  DiagNullabilityKind nullability) {
45  StringRef string;
46  switch (nullability.first) {
48  string = nullability.second ? "'nonnull'" : "'_Nonnull'";
49  break;
50 
52  string = nullability.second ? "'nullable'" : "'_Nullable'";
53  break;
54 
56  string = nullability.second ? "'null_unspecified'" : "'_Null_unspecified'";
57  break;
58 
60  assert(!nullability.second &&
61  "_Nullable_result isn't supported as context-sensitive keyword");
62  string = "_Nullable_result";
63  break;
64  }
65 
66  DB.AddString(string);
67  return DB;
68 }
69 
71  llvm::Error &&E) {
72  DB.AddString(toString(std::move(E)));
73  return DB;
74 }
75 
77  StringRef Modifier, StringRef Argument,
79  SmallVectorImpl<char> &Output,
80  void *Cookie,
81  ArrayRef<intptr_t> QualTypeVals) {
82  StringRef Str = "<can't format argument>";
83  Output.append(Str.begin(), Str.end());
84 }
85 
89  bool ShouldOwnClient)
90  : Diags(std::move(diags)), DiagOpts(std::move(DiagOpts)) {
91  setClient(client, ShouldOwnClient);
92  ArgToStringFn = DummyArgToStringFn;
93 
94  Reset();
95 }
96 
98  // If we own the diagnostic client, destroy it first so that it can access the
99  // engine from its destructor.
100  setClient(nullptr);
101 }
102 
104  DiagStatesByLoc.dump(*SourceMgr);
105 }
106 
107 void DiagnosticsEngine::dump(StringRef DiagName) const {
108  DiagStatesByLoc.dump(*SourceMgr, DiagName);
109 }
110 
112  bool ShouldOwnClient) {
113  Owner.reset(ShouldOwnClient ? client : nullptr);
114  Client = client;
115 }
116 
118  DiagStateOnPushStack.push_back(GetCurDiagState());
119 }
120 
122  if (DiagStateOnPushStack.empty())
123  return false;
124 
125  if (DiagStateOnPushStack.back() != GetCurDiagState()) {
126  // State changed at some point between push/pop.
127  PushDiagStatePoint(DiagStateOnPushStack.back(), Loc);
128  }
129  DiagStateOnPushStack.pop_back();
130  return true;
131 }
132 
134  ErrorOccurred = false;
135  UncompilableErrorOccurred = false;
136  FatalErrorOccurred = false;
137  UnrecoverableErrorOccurred = false;
138 
139  NumWarnings = 0;
140  NumErrors = 0;
141  TrapNumErrorsOccurred = 0;
142  TrapNumUnrecoverableErrorsOccurred = 0;
143 
145  LastDiagLevel = DiagnosticIDs::Ignored;
146  DelayedDiagID = 0;
147 
148  // Clear state related to #pragma diagnostic.
149  DiagStates.clear();
150  DiagStatesByLoc.clear();
151  DiagStateOnPushStack.clear();
152 
153  // Create a DiagState and DiagStatePoint representing diagnostic changes
154  // through command-line.
155  DiagStates.emplace_back();
156  DiagStatesByLoc.appendFirst(&DiagStates.back());
157 }
158 
159 void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1,
160  StringRef Arg2, StringRef Arg3) {
161  if (DelayedDiagID)
162  return;
163 
164  DelayedDiagID = DiagID;
165  DelayedDiagArg1 = Arg1.str();
166  DelayedDiagArg2 = Arg2.str();
167  DelayedDiagArg3 = Arg3.str();
168 }
169 
170 void DiagnosticsEngine::ReportDelayed() {
171  unsigned ID = DelayedDiagID;
172  DelayedDiagID = 0;
173  Report(ID) << DelayedDiagArg1 << DelayedDiagArg2 << DelayedDiagArg3;
174 }
175 
176 void DiagnosticsEngine::DiagStateMap::appendFirst(DiagState *State) {
177  assert(Files.empty() && "not first");
178  FirstDiagState = CurDiagState = State;
179  CurDiagStateLoc = SourceLocation();
180 }
181 
182 void DiagnosticsEngine::DiagStateMap::append(SourceManager &SrcMgr,
183  SourceLocation Loc,
184  DiagState *State) {
185  CurDiagState = State;
186  CurDiagStateLoc = Loc;
187 
188  std::pair<FileID, unsigned> Decomp = SrcMgr.getDecomposedLoc(Loc);
189  unsigned Offset = Decomp.second;
190  for (File *F = getFile(SrcMgr, Decomp.first); F;
191  Offset = F->ParentOffset, F = F->Parent) {
192  F->HasLocalTransitions = true;
193  auto &Last = F->StateTransitions.back();
194  assert(Last.Offset <= Offset && "state transitions added out of order");
195 
196  if (Last.Offset == Offset) {
197  if (Last.State == State)
198  break;
199  Last.State = State;
200  continue;
201  }
202 
203  F->StateTransitions.push_back({State, Offset});
204  }
205 }
206 
207 DiagnosticsEngine::DiagState *
208 DiagnosticsEngine::DiagStateMap::lookup(SourceManager &SrcMgr,
209  SourceLocation Loc) const {
210  // Common case: we have not seen any diagnostic pragmas.
211  if (Files.empty())
212  return FirstDiagState;
213 
214  std::pair<FileID, unsigned> Decomp = SrcMgr.getDecomposedLoc(Loc);
215  const File *F = getFile(SrcMgr, Decomp.first);
216  return F->lookup(Decomp.second);
217 }
218 
219 DiagnosticsEngine::DiagState *
220 DiagnosticsEngine::DiagStateMap::File::lookup(unsigned Offset) const {
221  auto OnePastIt =
222  llvm::partition_point(StateTransitions, [=](const DiagStatePoint &P) {
223  return P.Offset <= Offset;
224  });
225  assert(OnePastIt != StateTransitions.begin() && "missing initial state");
226  return OnePastIt[-1].State;
227 }
228 
229 DiagnosticsEngine::DiagStateMap::File *
230 DiagnosticsEngine::DiagStateMap::getFile(SourceManager &SrcMgr,
231  FileID ID) const {
232  // Get or insert the File for this ID.
233  auto Range = Files.equal_range(ID);
234  if (Range.first != Range.second)
235  return &Range.first->second;
236  auto &F = Files.insert(Range.first, std::make_pair(ID, File()))->second;
237 
238  // We created a new File; look up the diagnostic state at the start of it and
239  // initialize it.
240  if (ID.isValid()) {
241  std::pair<FileID, unsigned> Decomp = SrcMgr.getDecomposedIncludedLoc(ID);
242  F.Parent = getFile(SrcMgr, Decomp.first);
243  F.ParentOffset = Decomp.second;
244  F.StateTransitions.push_back({F.Parent->lookup(Decomp.second), 0});
245  } else {
246  // This is the (imaginary) root file into which we pretend all top-level
247  // files are included; it descends from the initial state.
248  //
249  // FIXME: This doesn't guarantee that we use the same ordering as
250  // isBeforeInTranslationUnit in the cases where someone invented another
251  // top-level file and added diagnostic pragmas to it. See the code at the
252  // end of isBeforeInTranslationUnit for the quirks it deals with.
253  F.StateTransitions.push_back({FirstDiagState, 0});
254  }
255  return &F;
256 }
257 
259  StringRef DiagName) const {
260  llvm::errs() << "diagnostic state at ";
261  CurDiagStateLoc.print(llvm::errs(), SrcMgr);
262  llvm::errs() << ": " << CurDiagState << "\n";
263 
264  for (auto &F : Files) {
265  FileID ID = F.first;
266  File &File = F.second;
267 
268  bool PrintedOuterHeading = false;
269  auto PrintOuterHeading = [&] {
270  if (PrintedOuterHeading) return;
271  PrintedOuterHeading = true;
272 
273  llvm::errs() << "File " << &File << " <FileID " << ID.getHashValue()
274  << ">: " << SrcMgr.getBufferOrFake(ID).getBufferIdentifier();
275 
276  if (F.second.Parent) {
277  std::pair<FileID, unsigned> Decomp =
279  assert(File.ParentOffset == Decomp.second);
280  llvm::errs() << " parent " << File.Parent << " <FileID "
281  << Decomp.first.getHashValue() << "> ";
282  SrcMgr.getLocForStartOfFile(Decomp.first)
283  .getLocWithOffset(Decomp.second)
284  .print(llvm::errs(), SrcMgr);
285  }
286  if (File.HasLocalTransitions)
287  llvm::errs() << " has_local_transitions";
288  llvm::errs() << "\n";
289  };
290 
291  if (DiagName.empty())
292  PrintOuterHeading();
293 
294  for (DiagStatePoint &Transition : File.StateTransitions) {
295  bool PrintedInnerHeading = false;
296  auto PrintInnerHeading = [&] {
297  if (PrintedInnerHeading) return;
298  PrintedInnerHeading = true;
299 
300  PrintOuterHeading();
301  llvm::errs() << " ";
302  SrcMgr.getLocForStartOfFile(ID)
303  .getLocWithOffset(Transition.Offset)
304  .print(llvm::errs(), SrcMgr);
305  llvm::errs() << ": state " << Transition.State << ":\n";
306  };
307 
308  if (DiagName.empty())
309  PrintInnerHeading();
310 
311  for (auto &Mapping : *Transition.State) {
312  StringRef Option =
314  if (!DiagName.empty() && DiagName != Option)
315  continue;
316 
317  PrintInnerHeading();
318  llvm::errs() << " ";
319  if (Option.empty())
320  llvm::errs() << "<unknown " << Mapping.first << ">";
321  else
322  llvm::errs() << Option;
323  llvm::errs() << ": ";
324 
325  switch (Mapping.second.getSeverity()) {
326  case diag::Severity::Ignored: llvm::errs() << "ignored"; break;
327  case diag::Severity::Remark: llvm::errs() << "remark"; break;
328  case diag::Severity::Warning: llvm::errs() << "warning"; break;
329  case diag::Severity::Error: llvm::errs() << "error"; break;
330  case diag::Severity::Fatal: llvm::errs() << "fatal"; break;
331  }
332 
333  if (!Mapping.second.isUser())
334  llvm::errs() << " default";
335  if (Mapping.second.isPragma())
336  llvm::errs() << " pragma";
337  if (Mapping.second.hasNoWarningAsError())
338  llvm::errs() << " no-error";
339  if (Mapping.second.hasNoErrorAsFatal())
340  llvm::errs() << " no-fatal";
341  if (Mapping.second.wasUpgradedFromWarning())
342  llvm::errs() << " overruled";
343  llvm::errs() << "\n";
344  }
345  }
346  }
347 }
348 
349 void DiagnosticsEngine::PushDiagStatePoint(DiagState *State,
350  SourceLocation Loc) {
351  assert(Loc.isValid() && "Adding invalid loc point");
352  DiagStatesByLoc.append(*SourceMgr, Loc, State);
353 }
354 
356  SourceLocation L) {
357  assert(Diag < diag::DIAG_UPPER_LIMIT &&
358  "Can only map builtin diagnostics");
359  assert((Diags->isBuiltinWarningOrExtension(Diag) ||
360  (Map == diag::Severity::Fatal || Map == diag::Severity::Error)) &&
361  "Cannot map errors into warnings!");
362  assert((L.isInvalid() || SourceMgr) && "No SourceMgr for valid location");
363 
364  // Don't allow a mapping to a warning override an error/fatal mapping.
365  bool WasUpgradedFromWarning = false;
366  if (Map == diag::Severity::Warning) {
367  DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag);
368  if (Info.getSeverity() == diag::Severity::Error ||
370  Map = Info.getSeverity();
371  WasUpgradedFromWarning = true;
372  }
373  }
374  DiagnosticMapping Mapping = makeUserMapping(Map, L);
375  Mapping.setUpgradedFromWarning(WasUpgradedFromWarning);
376 
377  // Common case; setting all the diagnostics of a group in one place.
378  if ((L.isInvalid() || L == DiagStatesByLoc.getCurDiagStateLoc()) &&
379  DiagStatesByLoc.getCurDiagState()) {
380  // FIXME: This is theoretically wrong: if the current state is shared with
381  // some other location (via push/pop) we will change the state for that
382  // other location as well. This cannot currently happen, as we can't update
383  // the diagnostic state at the same location at which we pop.
384  DiagStatesByLoc.getCurDiagState()->setMapping(Diag, Mapping);
385  return;
386  }
387 
388  // A diagnostic pragma occurred, create a new DiagState initialized with
389  // the current one and a new DiagStatePoint to record at which location
390  // the new state became active.
391  DiagStates.push_back(*GetCurDiagState());
392  DiagStates.back().setMapping(Diag, Mapping);
393  PushDiagStatePoint(&DiagStates.back(), L);
394 }
395 
397  StringRef Group, diag::Severity Map,
398  SourceLocation Loc) {
399  // Get the diagnostics in this group.
400  SmallVector<diag::kind, 256> GroupDiags;
401  if (Diags->getDiagnosticsInGroup(Flavor, Group, GroupDiags))
402  return true;
403 
404  // Set the mapping.
405  for (diag::kind Diag : GroupDiags)
406  setSeverity(Diag, Map, Loc);
407 
408  return false;
409 }
410 
413  diag::Severity Map,
414  SourceLocation Loc) {
415  return setSeverityForGroup(Flavor, Diags->getWarningOptionForGroup(Group),
416  Map, Loc);
417 }
418 
420  bool Enabled) {
421  // If we are enabling this feature, just set the diagnostic mappings to map to
422  // errors.
423  if (Enabled)
426 
427  // Otherwise, we want to set the diagnostic mapping's "no Werror" bit, and
428  // potentially downgrade anything already mapped to be a warning.
429 
430  // Get the diagnostics in this group.
431  SmallVector<diag::kind, 8> GroupDiags;
432  if (Diags->getDiagnosticsInGroup(diag::Flavor::WarningOrError, Group,
433  GroupDiags))
434  return true;
435 
436  // Perform the mapping change.
437  for (diag::kind Diag : GroupDiags) {
438  DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag);
439 
440  if (Info.getSeverity() == diag::Severity::Error ||
443 
444  Info.setNoWarningAsError(true);
445  }
446 
447  return false;
448 }
449 
451  bool Enabled) {
452  // If we are enabling this feature, just set the diagnostic mappings to map to
453  // fatal errors.
454  if (Enabled)
457 
458  // Otherwise, we want to set the diagnostic mapping's "no Wfatal-errors" bit,
459  // and potentially downgrade anything already mapped to be a fatal error.
460 
461  // Get the diagnostics in this group.
462  SmallVector<diag::kind, 8> GroupDiags;
463  if (Diags->getDiagnosticsInGroup(diag::Flavor::WarningOrError, Group,
464  GroupDiags))
465  return true;
466 
467  // Perform the mapping change.
468  for (diag::kind Diag : GroupDiags) {
469  DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag);
470 
471  if (Info.getSeverity() == diag::Severity::Fatal)
473 
474  Info.setNoErrorAsFatal(true);
475  }
476 
477  return false;
478 }
479 
481  diag::Severity Map,
482  SourceLocation Loc) {
483  // Get all the diagnostics.
484  std::vector<diag::kind> AllDiags;
486 
487  // Set the mapping.
488  for (diag::kind Diag : AllDiags)
489  if (Diags->isBuiltinWarningOrExtension(Diag))
490  setSeverity(Diag, Map, Loc);
491 }
492 
494  assert(CurDiagID == std::numeric_limits<unsigned>::max() &&
495  "Multiple diagnostics in flight at once!");
496 
497  CurDiagLoc = storedDiag.getLocation();
498  CurDiagID = storedDiag.getID();
499  DiagStorage.NumDiagArgs = 0;
500 
501  DiagStorage.DiagRanges.clear();
502  DiagStorage.DiagRanges.append(storedDiag.range_begin(),
503  storedDiag.range_end());
504 
505  DiagStorage.FixItHints.clear();
506  DiagStorage.FixItHints.append(storedDiag.fixit_begin(),
507  storedDiag.fixit_end());
508 
509  assert(Client && "DiagnosticConsumer not set!");
510  Level DiagLevel = storedDiag.getLevel();
511  Diagnostic Info(this, storedDiag.getMessage());
512  Client->HandleDiagnostic(DiagLevel, Info);
513  if (Client->IncludeInDiagnosticCounts()) {
514  if (DiagLevel == DiagnosticsEngine::Warning)
515  ++NumWarnings;
516  }
517 
519 }
520 
522  assert(getClient() && "DiagnosticClient not set!");
523 
524  bool Emitted;
525  if (Force) {
526  Diagnostic Info(this);
527 
528  // Figure out the diagnostic level of this message.
529  DiagnosticIDs::Level DiagLevel
530  = Diags->getDiagnosticLevel(Info.getID(), Info.getLocation(), *this);
531 
532  Emitted = (DiagLevel != DiagnosticIDs::Ignored);
533  if (Emitted) {
534  // Emit the diagnostic regardless of suppression level.
535  Diags->EmitDiag(*this, DiagLevel);
536  }
537  } else {
538  // Process the diagnostic, sending the accumulated information to the
539  // DiagnosticConsumer.
540  Emitted = ProcessDiag();
541  }
542 
543  // Clear out the current diagnostic object.
544  Clear();
545 
546  // If there was a delayed diagnostic, emit it now.
547  if (!Force && DelayedDiagID)
548  ReportDelayed();
549 
550  return Emitted;
551 }
552 
554 
556  const Diagnostic &Info) {
558  return;
559 
560  if (DiagLevel == DiagnosticsEngine::Warning)
561  ++NumWarnings;
562  else if (DiagLevel >= DiagnosticsEngine::Error)
563  ++NumErrors;
564 }
565 
566 /// ModifierIs - Return true if the specified modifier matches specified string.
567 template <std::size_t StrLen>
568 static bool ModifierIs(const char *Modifier, unsigned ModifierLen,
569  const char (&Str)[StrLen]) {
570  return StrLen-1 == ModifierLen && memcmp(Modifier, Str, StrLen-1) == 0;
571 }
572 
573 /// ScanForward - Scans forward, looking for the given character, skipping
574 /// nested clauses and escaped characters.
575 static const char *ScanFormat(const char *I, const char *E, char Target) {
576  unsigned Depth = 0;
577 
578  for ( ; I != E; ++I) {
579  if (Depth == 0 && *I == Target) return I;
580  if (Depth != 0 && *I == '}') Depth--;
581 
582  if (*I == '%') {
583  I++;
584  if (I == E) break;
585 
586  // Escaped characters get implicitly skipped here.
587 
588  // Format specifier.
589  if (!isDigit(*I) && !isPunctuation(*I)) {
590  for (I++; I != E && !isDigit(*I) && *I != '{'; I++) ;
591  if (I == E) break;
592  if (*I == '{')
593  Depth++;
594  }
595  }
596  }
597  return E;
598 }
599 
600 /// HandleSelectModifier - Handle the integer 'select' modifier. This is used
601 /// like this: %select{foo|bar|baz}2. This means that the integer argument
602 /// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'.
603 /// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'.
604 /// This is very useful for certain classes of variant diagnostics.
605 static void HandleSelectModifier(const Diagnostic &DInfo, unsigned ValNo,
606  const char *Argument, unsigned ArgumentLen,
607  SmallVectorImpl<char> &OutStr) {
608  const char *ArgumentEnd = Argument+ArgumentLen;
609 
610  // Skip over 'ValNo' |'s.
611  while (ValNo) {
612  const char *NextVal = ScanFormat(Argument, ArgumentEnd, '|');
613  assert(NextVal != ArgumentEnd && "Value for integer select modifier was"
614  " larger than the number of options in the diagnostic string!");
615  Argument = NextVal+1; // Skip this string.
616  --ValNo;
617  }
618 
619  // Get the end of the value. This is either the } or the |.
620  const char *EndPtr = ScanFormat(Argument, ArgumentEnd, '|');
621 
622  // Recursively format the result of the select clause into the output string.
623  DInfo.FormatDiagnostic(Argument, EndPtr, OutStr);
624 }
625 
626 /// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the
627 /// letter 's' to the string if the value is not 1. This is used in cases like
628 /// this: "you idiot, you have %4 parameter%s4!".
629 static void HandleIntegerSModifier(unsigned ValNo,
630  SmallVectorImpl<char> &OutStr) {
631  if (ValNo != 1)
632  OutStr.push_back('s');
633 }
634 
635 /// HandleOrdinalModifier - Handle the integer 'ord' modifier. This
636 /// prints the ordinal form of the given integer, with 1 corresponding
637 /// to the first ordinal. Currently this is hard-coded to use the
638 /// English form.
639 static void HandleOrdinalModifier(unsigned ValNo,
640  SmallVectorImpl<char> &OutStr) {
641  assert(ValNo != 0 && "ValNo must be strictly positive!");
642 
643  llvm::raw_svector_ostream Out(OutStr);
644 
645  // We could use text forms for the first N ordinals, but the numeric
646  // forms are actually nicer in diagnostics because they stand out.
647  Out << ValNo << llvm::getOrdinalSuffix(ValNo);
648 }
649 
650 /// PluralNumber - Parse an unsigned integer and advance Start.
651 static unsigned PluralNumber(const char *&Start, const char *End) {
652  // Programming 101: Parse a decimal number :-)
653  unsigned Val = 0;
654  while (Start != End && *Start >= '0' && *Start <= '9') {
655  Val *= 10;
656  Val += *Start - '0';
657  ++Start;
658  }
659  return Val;
660 }
661 
662 /// TestPluralRange - Test if Val is in the parsed range. Modifies Start.
663 static bool TestPluralRange(unsigned Val, const char *&Start, const char *End) {
664  if (*Start != '[') {
665  unsigned Ref = PluralNumber(Start, End);
666  return Ref == Val;
667  }
668 
669  ++Start;
670  unsigned Low = PluralNumber(Start, End);
671  assert(*Start == ',' && "Bad plural expression syntax: expected ,");
672  ++Start;
673  unsigned High = PluralNumber(Start, End);
674  assert(*Start == ']' && "Bad plural expression syntax: expected )");
675  ++Start;
676  return Low <= Val && Val <= High;
677 }
678 
679 /// EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.
680 static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) {
681  // Empty condition?
682  if (*Start == ':')
683  return true;
684 
685  while (true) {
686  char C = *Start;
687  if (C == '%') {
688  // Modulo expression
689  ++Start;
690  unsigned Arg = PluralNumber(Start, End);
691  assert(*Start == '=' && "Bad plural expression syntax: expected =");
692  ++Start;
693  unsigned ValMod = ValNo % Arg;
694  if (TestPluralRange(ValMod, Start, End))
695  return true;
696  } else {
697  assert((C == '[' || (C >= '0' && C <= '9')) &&
698  "Bad plural expression syntax: unexpected character");
699  // Range expression
700  if (TestPluralRange(ValNo, Start, End))
701  return true;
702  }
703 
704  // Scan for next or-expr part.
705  Start = std::find(Start, End, ',');
706  if (Start == End)
707  break;
708  ++Start;
709  }
710  return false;
711 }
712 
713 /// HandlePluralModifier - Handle the integer 'plural' modifier. This is used
714 /// for complex plural forms, or in languages where all plurals are complex.
715 /// The syntax is: %plural{cond1:form1|cond2:form2|:form3}, where condn are
716 /// conditions that are tested in order, the form corresponding to the first
717 /// that applies being emitted. The empty condition is always true, making the
718 /// last form a default case.
719 /// Conditions are simple boolean expressions, where n is the number argument.
720 /// Here are the rules.
721 /// condition := expression | empty
722 /// empty := -> always true
723 /// expression := numeric [',' expression] -> logical or
724 /// numeric := range -> true if n in range
725 /// | '%' number '=' range -> true if n % number in range
726 /// range := number
727 /// | '[' number ',' number ']' -> ranges are inclusive both ends
728 ///
729 /// Here are some examples from the GNU gettext manual written in this form:
730 /// English:
731 /// {1:form0|:form1}
732 /// Latvian:
733 /// {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0}
734 /// Gaeilge:
735 /// {1:form0|2:form1|:form2}
736 /// Romanian:
737 /// {1:form0|0,%100=[1,19]:form1|:form2}
738 /// Lithuanian:
739 /// {%10=0,%100=[10,19]:form2|%10=1:form0|:form1}
740 /// Russian (requires repeated form):
741 /// {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2}
742 /// Slovak
743 /// {1:form0|[2,4]:form1|:form2}
744 /// Polish (requires repeated form):
745 /// {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2}
746 static void HandlePluralModifier(const Diagnostic &DInfo, unsigned ValNo,
747  const char *Argument, unsigned ArgumentLen,
748  SmallVectorImpl<char> &OutStr) {
749  const char *ArgumentEnd = Argument + ArgumentLen;
750  while (true) {
751  assert(Argument < ArgumentEnd && "Plural expression didn't match.");
752  const char *ExprEnd = Argument;
753  while (*ExprEnd != ':') {
754  assert(ExprEnd != ArgumentEnd && "Plural missing expression end");
755  ++ExprEnd;
756  }
757  if (EvalPluralExpr(ValNo, Argument, ExprEnd)) {
758  Argument = ExprEnd + 1;
759  ExprEnd = ScanFormat(Argument, ArgumentEnd, '|');
760 
761  // Recursively format the result of the plural clause into the
762  // output string.
763  DInfo.FormatDiagnostic(Argument, ExprEnd, OutStr);
764  return;
765  }
766  Argument = ScanFormat(Argument, ArgumentEnd - 1, '|') + 1;
767  }
768 }
769 
770 /// Returns the friendly description for a token kind that will appear
771 /// without quotes in diagnostic messages. These strings may be translatable in
772 /// future.
774  switch (Kind) {
775  case tok::identifier:
776  return "identifier";
777  default:
778  return nullptr;
779  }
780 }
781 
782 /// FormatDiagnostic - Format this diagnostic into a string, substituting the
783 /// formal arguments into the %0 slots. The result is appended onto the Str
784 /// array.
785 void Diagnostic::
787  if (!StoredDiagMessage.empty()) {
788  OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
789  return;
790  }
791 
792  StringRef Diag =
793  getDiags()->getDiagnosticIDs()->getDescription(getID());
794 
795  FormatDiagnostic(Diag.begin(), Diag.end(), OutStr);
796 }
797 
798 void Diagnostic::
799 FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
800  SmallVectorImpl<char> &OutStr) const {
801  // When the diagnostic string is only "%0", the entire string is being given
802  // by an outside source. Remove unprintable characters from this string
803  // and skip all the other string processing.
804  if (DiagEnd - DiagStr == 2 &&
805  StringRef(DiagStr, DiagEnd - DiagStr).equals("%0") &&
807  const std::string &S = getArgStdStr(0);
808  for (char c : S) {
809  if (llvm::sys::locale::isPrint(c) || c == '\t') {
810  OutStr.push_back(c);
811  }
812  }
813  return;
814  }
815 
816  /// FormattedArgs - Keep track of all of the arguments formatted by
817  /// ConvertArgToString and pass them into subsequent calls to
818  /// ConvertArgToString, allowing the implementation to avoid redundancies in
819  /// obvious cases.
821 
822  /// QualTypeVals - Pass a vector of arrays so that QualType names can be
823  /// compared to see if more information is needed to be printed.
824  SmallVector<intptr_t, 2> QualTypeVals;
826 
827  for (unsigned i = 0, e = getNumArgs(); i < e; ++i)
829  QualTypeVals.push_back(getRawArg(i));
830 
831  while (DiagStr != DiagEnd) {
832  if (DiagStr[0] != '%') {
833  // Append non-%0 substrings to Str if we have one.
834  const char *StrEnd = std::find(DiagStr, DiagEnd, '%');
835  OutStr.append(DiagStr, StrEnd);
836  DiagStr = StrEnd;
837  continue;
838  } else if (isPunctuation(DiagStr[1])) {
839  OutStr.push_back(DiagStr[1]); // %% -> %.
840  DiagStr += 2;
841  continue;
842  }
843 
844  // Skip the %.
845  ++DiagStr;
846 
847  // This must be a placeholder for a diagnostic argument. The format for a
848  // placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0".
849  // The digit is a number from 0-9 indicating which argument this comes from.
850  // The modifier is a string of digits from the set [-a-z]+, arguments is a
851  // brace enclosed string.
852  const char *Modifier = nullptr, *Argument = nullptr;
853  unsigned ModifierLen = 0, ArgumentLen = 0;
854 
855  // Check to see if we have a modifier. If so eat it.
856  if (!isDigit(DiagStr[0])) {
857  Modifier = DiagStr;
858  while (DiagStr[0] == '-' ||
859  (DiagStr[0] >= 'a' && DiagStr[0] <= 'z'))
860  ++DiagStr;
861  ModifierLen = DiagStr-Modifier;
862 
863  // If we have an argument, get it next.
864  if (DiagStr[0] == '{') {
865  ++DiagStr; // Skip {.
866  Argument = DiagStr;
867 
868  DiagStr = ScanFormat(DiagStr, DiagEnd, '}');
869  assert(DiagStr != DiagEnd && "Mismatched {}'s in diagnostic string!");
870  ArgumentLen = DiagStr-Argument;
871  ++DiagStr; // Skip }.
872  }
873  }
874 
875  assert(isDigit(*DiagStr) && "Invalid format for argument in diagnostic");
876  unsigned ArgNo = *DiagStr++ - '0';
877 
878  // Only used for type diffing.
879  unsigned ArgNo2 = ArgNo;
880 
882  if (ModifierIs(Modifier, ModifierLen, "diff")) {
883  assert(*DiagStr == ',' && isDigit(*(DiagStr + 1)) &&
884  "Invalid format for diff modifier");
885  ++DiagStr; // Comma.
886  ArgNo2 = *DiagStr++ - '0';
891  else {
892  // %diff only supports QualTypes. For other kinds of arguments,
893  // use the default printing. For example, if the modifier is:
894  // "%diff{compare $ to $|other text}1,2"
895  // treat it as:
896  // "compare %1 to %2"
897  const char *ArgumentEnd = Argument + ArgumentLen;
898  const char *Pipe = ScanFormat(Argument, ArgumentEnd, '|');
899  assert(ScanFormat(Pipe + 1, ArgumentEnd, '|') == ArgumentEnd &&
900  "Found too many '|'s in a %diff modifier!");
901  const char *FirstDollar = ScanFormat(Argument, Pipe, '$');
902  const char *SecondDollar = ScanFormat(FirstDollar + 1, Pipe, '$');
903  const char ArgStr1[] = { '%', static_cast<char>('0' + ArgNo) };
904  const char ArgStr2[] = { '%', static_cast<char>('0' + ArgNo2) };
905  FormatDiagnostic(Argument, FirstDollar, OutStr);
906  FormatDiagnostic(ArgStr1, ArgStr1 + 2, OutStr);
907  FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr);
908  FormatDiagnostic(ArgStr2, ArgStr2 + 2, OutStr);
909  FormatDiagnostic(SecondDollar + 1, Pipe, OutStr);
910  continue;
911  }
912  }
913 
914  switch (Kind) {
915  // ---- STRINGS ----
917  const std::string &S = getArgStdStr(ArgNo);
918  assert(ModifierLen == 0 && "No modifiers for strings yet");
919  OutStr.append(S.begin(), S.end());
920  break;
921  }
923  const char *S = getArgCStr(ArgNo);
924  assert(ModifierLen == 0 && "No modifiers for strings yet");
925 
926  // Don't crash if get passed a null pointer by accident.
927  if (!S)
928  S = "(null)";
929 
930  OutStr.append(S, S + strlen(S));
931  break;
932  }
933  // ---- INTEGERS ----
935  int64_t Val = getArgSInt(ArgNo);
936 
937  if (ModifierIs(Modifier, ModifierLen, "select")) {
938  HandleSelectModifier(*this, (unsigned)Val, Argument, ArgumentLen,
939  OutStr);
940  } else if (ModifierIs(Modifier, ModifierLen, "s")) {
941  HandleIntegerSModifier(Val, OutStr);
942  } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
943  HandlePluralModifier(*this, (unsigned)Val, Argument, ArgumentLen,
944  OutStr);
945  } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) {
946  HandleOrdinalModifier((unsigned)Val, OutStr);
947  } else {
948  assert(ModifierLen == 0 && "Unknown integer modifier");
949  llvm::raw_svector_ostream(OutStr) << Val;
950  }
951  break;
952  }
954  uint64_t Val = getArgUInt(ArgNo);
955 
956  if (ModifierIs(Modifier, ModifierLen, "select")) {
957  HandleSelectModifier(*this, Val, Argument, ArgumentLen, OutStr);
958  } else if (ModifierIs(Modifier, ModifierLen, "s")) {
959  HandleIntegerSModifier(Val, OutStr);
960  } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
961  HandlePluralModifier(*this, (unsigned)Val, Argument, ArgumentLen,
962  OutStr);
963  } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) {
964  HandleOrdinalModifier(Val, OutStr);
965  } else {
966  assert(ModifierLen == 0 && "Unknown integer modifier");
967  llvm::raw_svector_ostream(OutStr) << Val;
968  }
969  break;
970  }
971  // ---- TOKEN SPELLINGS ----
973  tok::TokenKind Kind = static_cast<tok::TokenKind>(getRawArg(ArgNo));
974  assert(ModifierLen == 0 && "No modifiers for token kinds yet");
975 
976  llvm::raw_svector_ostream Out(OutStr);
977  if (const char *S = tok::getPunctuatorSpelling(Kind))
978  // Quoted token spelling for punctuators.
979  Out << '\'' << S << '\'';
980  else if (const char *S = tok::getKeywordSpelling(Kind))
981  // Unquoted token spelling for keywords.
982  Out << S;
983  else if (const char *S = getTokenDescForDiagnostic(Kind))
984  // Unquoted translatable token name.
985  Out << S;
986  else if (const char *S = tok::getTokenName(Kind))
987  // Debug name, shouldn't appear in user-facing diagnostics.
988  Out << '<' << S << '>';
989  else
990  Out << "(null)";
991  break;
992  }
993  // ---- NAMES and TYPES ----
994  case DiagnosticsEngine::ak_identifierinfo: {
995  const IdentifierInfo *II = getArgIdentifier(ArgNo);
996  assert(ModifierLen == 0 && "No modifiers for strings yet");
997 
998  // Don't crash if get passed a null pointer by accident.
999  if (!II) {
1000  const char *S = "(null)";
1001  OutStr.append(S, S + strlen(S));
1002  continue;
1003  }
1004 
1005  llvm::raw_svector_ostream(OutStr) << '\'' << II->getName() << '\'';
1006  break;
1007  }
1017  StringRef(Modifier, ModifierLen),
1018  StringRef(Argument, ArgumentLen),
1019  FormattedArgs,
1020  OutStr, QualTypeVals);
1021  break;
1023  // Create a struct with all the info needed for printing.
1024  TemplateDiffTypes TDT;
1025  TDT.FromType = getRawArg(ArgNo);
1026  TDT.ToType = getRawArg(ArgNo2);
1027  TDT.ElideType = getDiags()->ElideType;
1028  TDT.ShowColors = getDiags()->ShowColors;
1029  TDT.TemplateDiffUsed = false;
1030  intptr_t val = reinterpret_cast<intptr_t>(&TDT);
1031 
1032  const char *ArgumentEnd = Argument + ArgumentLen;
1033  const char *Pipe = ScanFormat(Argument, ArgumentEnd, '|');
1034 
1035  // Print the tree. If this diagnostic already has a tree, skip the
1036  // second tree.
1037  if (getDiags()->PrintTemplateTree && Tree.empty()) {
1038  TDT.PrintFromType = true;
1039  TDT.PrintTree = true;
1041  StringRef(Modifier, ModifierLen),
1042  StringRef(Argument, ArgumentLen),
1043  FormattedArgs,
1044  Tree, QualTypeVals);
1045  // If there is no tree information, fall back to regular printing.
1046  if (!Tree.empty()) {
1047  FormatDiagnostic(Pipe + 1, ArgumentEnd, OutStr);
1048  break;
1049  }
1050  }
1051 
1052  // Non-tree printing, also the fall-back when tree printing fails.
1053  // The fall-back is triggered when the types compared are not templates.
1054  const char *FirstDollar = ScanFormat(Argument, ArgumentEnd, '$');
1055  const char *SecondDollar = ScanFormat(FirstDollar + 1, ArgumentEnd, '$');
1056 
1057  // Append before text
1058  FormatDiagnostic(Argument, FirstDollar, OutStr);
1059 
1060  // Append first type
1061  TDT.PrintTree = false;
1062  TDT.PrintFromType = true;
1064  StringRef(Modifier, ModifierLen),
1065  StringRef(Argument, ArgumentLen),
1066  FormattedArgs,
1067  OutStr, QualTypeVals);
1068  if (!TDT.TemplateDiffUsed)
1069  FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype,
1070  TDT.FromType));
1071 
1072  // Append middle text
1073  FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr);
1074 
1075  // Append second type
1076  TDT.PrintFromType = false;
1078  StringRef(Modifier, ModifierLen),
1079  StringRef(Argument, ArgumentLen),
1080  FormattedArgs,
1081  OutStr, QualTypeVals);
1082  if (!TDT.TemplateDiffUsed)
1083  FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype,
1084  TDT.ToType));
1085 
1086  // Append end text
1087  FormatDiagnostic(SecondDollar + 1, Pipe, OutStr);
1088  break;
1089  }
1090  }
1091 
1092  // Remember this argument info for subsequent formatting operations. Turn
1093  // std::strings into a null terminated string to make it be the same case as
1094  // all the other ones.
1096  continue;
1098  FormattedArgs.push_back(std::make_pair(Kind, getRawArg(ArgNo)));
1099  else
1100  FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_c_string,
1101  (intptr_t)getArgStdStr(ArgNo).c_str()));
1102  }
1103 
1104  // Append the type tree to the end of the diagnostics.
1105  OutStr.append(Tree.begin(), Tree.end());
1106 }
1107 
1109  StringRef Message)
1110  : ID(ID), Level(Level), Message(Message) {}
1111 
1113  const Diagnostic &Info)
1114  : ID(Info.getID()), Level(Level) {
1115  assert((Info.getLocation().isInvalid() || Info.hasSourceManager()) &&
1116  "Valid source location without setting a source manager for diagnostic");
1117  if (Info.getLocation().isValid())
1118  Loc = FullSourceLoc(Info.getLocation(), Info.getSourceManager());
1119  SmallString<64> Message;
1120  Info.FormatDiagnostic(Message);
1121  this->Message.assign(Message.begin(), Message.end());
1122  this->Ranges.assign(Info.getRanges().begin(), Info.getRanges().end());
1123  this->FixIts.assign(Info.getFixItHints().begin(), Info.getFixItHints().end());
1124 }
1125 
1127  StringRef Message, FullSourceLoc Loc,
1129  ArrayRef<FixItHint> FixIts)
1130  : ID(ID), Level(Level), Loc(Loc), Message(Message),
1131  Ranges(Ranges.begin(), Ranges.end()), FixIts(FixIts.begin(), FixIts.end())
1132 {
1133 }
1134 
1135 /// IncludeInDiagnosticCounts - This method (whose default implementation
1136 /// returns true) indicates whether the diagnostics handled by this
1137 /// DiagnosticConsumer should be included in the number of diagnostics
1138 /// reported by DiagnosticsEngine.
1140 
1141 void IgnoringDiagConsumer::anchor() {}
1142 
1144 
1146  DiagnosticsEngine::Level DiagLevel,
1147  const Diagnostic &Info) {
1148  Target.HandleDiagnostic(DiagLevel, Info);
1149 }
1150 
1153  Target.clear();
1154 }
1155 
1157  return Target.IncludeInDiagnosticCounts();
1158 }
1159 
1161  for (unsigned I = 0; I != NumCached; ++I)
1162  FreeList[I] = Cached + I;
1163  NumFreeListEntries = NumCached;
1164 }
1165 
1167  // Don't assert if we are in a CrashRecovery context, as this invariant may
1168  // be invalidated during a crash.
1169  assert((NumFreeListEntries == NumCached ||
1170  llvm::CrashRecoveryContext::isRecoveringFromCrash()) &&
1171  "A partial is on the lam");
1172 }
1173 
1174 char DiagnosticError::ID;
clang::DiagnosticsEngine::Level
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:194
clang::diag::Severity
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
Definition: DiagnosticIDs.h:82
clang::DiagnosticsEngine::Reset
void Reset()
Reset the state of the diagnostic object to its initial configuration.
Definition: Diagnostic.cpp:133
max
__DEVICE__ int max(int __a, int __b)
Definition: __clang_cuda_math.h:196
clang::threadSafety::sx::equals
bool equals(const til::SExpr *E1, const til::SExpr *E2)
Definition: ThreadSafetyCommon.h:63
clang::DiagnosticsEngine::ak_qual
@ ak_qual
Qualifiers.
Definition: Diagnostic.h:226
clang::DiagnosticIDs::getAllDiagnostics
static void getAllDiagnostics(diag::Flavor Flavor, std::vector< diag::kind > &Diags)
Get the set of all diagnostic IDs.
Definition: DiagnosticIDs.cpp:685
Specifiers.h
clang::diag::Severity::Error
@ Error
Present this diagnostic as an error.
clang::FullSourceLoc
A SourceLocation and its associated SourceManager.
Definition: SourceLocation.h:368
clang::DeclaratorContext::File
@ File
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:355
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:111
clang::Diagnostic::getArgStdStr
const std::string & getArgStdStr(unsigned Idx) const
Return the provided argument string specified by Idx.
Definition: Diagnostic.h:1578
clang::TemplateDiffTypes::TemplateDiffUsed
unsigned TemplateDiffUsed
Definition: Diagnostic.h:1813
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:121
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:78
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:450
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::StoredDiagnostic::StoredDiagnostic
StoredDiagnostic()=default
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:134
HandleSelectModifier
static void HandleSelectModifier(const Diagnostic &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, SmallVectorImpl< char > &OutStr)
HandleSelectModifier - Handle the integer 'select' modifier.
Definition: Diagnostic.cpp:605
clang::MultiVersionKind::Target
@ Target
clang::DiagnosticConsumer
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1722
clang::DiagnosticConsumer::NumErrors
unsigned NumErrors
Number of errors reported.
Definition: Diagnostic.h:1725
clang::tok::getPunctuatorSpelling
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!' or '', and returns NULL for literal and...
Definition: TokenKinds.cpp:31
clang::diag::Severity::Remark
@ Remark
Present this diagnostic as a remark.
clang::Diagnostic::getRawArg
uint64_t getRawArg(unsigned Idx) const
Return the specified non-string argument in an opaque form.
Definition: Diagnostic.h:1620
clang::DiagnosticIDs::Level
Level
The level of the diagnostic, after it has been through mapping.
Definition: DiagnosticIDs.h:169
SourceManager.h
clang::TemplateDiffTypes::ToType
intptr_t ToType
Definition: Diagnostic.h:1806
DiagnosticError.h
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:396
clang::StoredDiagnostic::getMessage
StringRef getMessage() const
Definition: Diagnostic.h:1695
clang::isPunctuation
LLVM_READONLY bool isPunctuation(unsigned char c)
Return true if this character is an ASCII punctuation character.
Definition: CharInfo.h:136
DiagnosticIDs.h
clang::diag::Group
Group
Definition: DiagnosticCategories.h:23
clang::Diagnostic::getDiags
const DiagnosticsEngine * getDiags() const
Definition: Diagnostic.h:1556
HandleOrdinalModifier
static void HandleOrdinalModifier(unsigned ValNo, SmallVectorImpl< char > &OutStr)
HandleOrdinalModifier - Handle the integer 'ord' modifier.
Definition: Diagnostic.cpp:639
clang::DiagnosticMapping::setUpgradedFromWarning
void setUpgradedFromWarning(bool Value)
Definition: DiagnosticIDs.h:143
End
SourceLocation End
Definition: USRLocFinder.cpp:167
getTokenDescForDiagnostic
static const char * getTokenDescForDiagnostic(tok::TokenKind Kind)
Returns the friendly description for a token kind that will appear without quotes in diagnostic messa...
Definition: Diagnostic.cpp:773
clang::StoredDiagnostic::getID
unsigned getID() const
Definition: Diagnostic.h:1692
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:626
clang::DiagnosticStorage::DiagRanges
SmallVector< CharSourceRange, 8 > DiagRanges
The list of ranges added to this diagnostic.
Definition: Diagnostic.h:176
Offset
unsigned Offset
Definition: Format.cpp:2381
clang::Diagnostic
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1547
clang::TemplateDiffTypes
Definition: Diagnostic.h:1804
TokenKinds.h
clang::DiagnosticConsumer::NumWarnings
unsigned NumWarnings
Number of warnings reported.
Definition: Diagnostic.h:1724
clang::DiagnosticsEngine::setDiagnosticGroupWarningAsError
bool setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled)
Set the warning-as-error flag for the given diagnostic group.
Definition: Diagnostic.cpp:419
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:555
clang::DiagnosticsEngine::ArgumentKind
ArgumentKind
Definition: Diagnostic.h:203
clang::StoredDiagnostic::range_begin
range_iterator range_begin() const
Definition: Diagnostic.h:1701
clang::SourceLocation::print
void print(raw_ostream &OS, const SourceManager &SM) const
Definition: SourceLocation.cpp:62
clang::ForwardingDiagnosticConsumer::IncludeInDiagnosticCounts
bool IncludeInDiagnosticCounts() const override
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
Definition: Diagnostic.cpp:1156
clang::diag::Flavor::WarningOrError
@ WarningOrError
A diagnostic that indicates a problem or potential problem.
EvalPluralExpr
static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End)
EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.
Definition: Diagnostic.cpp:680
clang::TemplateDiffTypes::FromType
intptr_t FromType
Definition: Diagnostic.h:1805
clang::threadSafety::sx::toString
std::string toString(const til::SExpr *E)
Definition: ThreadSafetyCommon.h:89
clang::diag::Severity::Fatal
@ Fatal
Present this diagnostic as a fatal error.
clang::StreamingDiagnostic
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1108
clang::DiagnosticsEngine::Clear
void Clear()
Clear out the current diagnostic.
Definition: Diagnostic.h:975
Diagnostic.h
clang::diag::DIAG_UPPER_LIMIT
@ DIAG_UPPER_LIMIT
Definition: DiagnosticIDs.h:59
clang::DiagnosticsEngine::EmitCurrentDiagnostic
bool EmitCurrentDiagnostic(bool Force=false)
Emit the current diagnostic and clear the diagnostic state.
Definition: Diagnostic.cpp:521
clang::Diagnostic::getNumArgs
unsigned getNumArgs() const
Definition: Diagnostic.h:1562
Depth
int Depth
Definition: ASTDiff.cpp:191
clang::DiagnosticMapping
Definition: DiagnosticIDs.h:101
clang::DiagnosticsEngine::Error
@ Error
Definition: Diagnostic.h:199
clang::Diagnostic::getArgCStr
const char * getArgCStr(unsigned Idx) const
Return the specified C string argument.
Definition: Diagnostic.h:1586
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:117
clang::DiagnosticsEngine::ak_attr
@ ak_attr
Attr *.
Definition: Diagnostic.h:247
clang::DiagnosticsEngine::getDiagnosticIDs
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
Definition: Diagnostic.h:550
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:1518
IdentifierTable.h
clang::DiagnosticsEngine::getClient
DiagnosticConsumer * getClient()
Definition: Diagnostic.h:565
clang::tok::getTokenName
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
Definition: TokenKinds.cpp:24
llvm::SmallString
Definition: LLVM.h:37
clang::DiagnosticsEngine::ak_qualtype_pair
@ ak_qualtype_pair
pair<QualType, QualType>
Definition: Diagnostic.h:244
clang::DiagnosticsEngine::ak_sint
@ ak_sint
int
Definition: Diagnostic.h:211
clang::StoredDiagnostic::range_end
range_iterator range_end() const
Definition: Diagnostic.h:1702
clang::Diagnostic::getArgUInt
uint64_t getArgUInt(unsigned Idx) const
Return the specified unsigned integer argument.
Definition: Diagnostic.h:1603
clang::operator<<
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
Definition: ASTContext.cpp:11823
clang::DiagnosticConsumer::~DiagnosticConsumer
virtual ~DiagnosticConsumer()
clang::DiagnosticsEngine::ak_tokenkind
@ ak_tokenkind
enum TokenKind : unsigned
Definition: Diagnostic.h:217
clang::DiagnosticConsumer::IncludeInDiagnosticCounts
virtual bool IncludeInDiagnosticCounts() const
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
Definition: Diagnostic.cpp:1139
clang::SourceManager::getDecomposedLoc
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Definition: SourceManager.h:1236
clang::StreamingDiagnostic::DiagStorageAllocator::DiagStorageAllocator
DiagStorageAllocator()
clang::Diagnostic::getArgSInt
int64_t getArgSInt(unsigned Idx) const
Return the specified signed integer argument.
Definition: Diagnostic.h:1595
clang::StoredDiagnostic
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
Definition: Diagnostic.h:1671
clang::SourceManager::getLocForStartOfFile
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
Definition: SourceManager.h:1118
clang::diag::Severity::Warning
@ Warning
Present this diagnostic as a warning.
clang::transformer::EditKind::Range
@ Range
clang::DiagnosticsEngine::ak_declarationname
@ ak_declarationname
DeclarationName.
Definition: Diagnostic.h:232
clang::DiagnosticMapping::getSeverity
diag::Severity getSeverity() const
Definition: DiagnosticIDs.h:122
ScanFormat
static const char * ScanFormat(const char *I, const char *E, char Target)
ScanForward - Scans forward, looking for the given character, skipping nested clauses and escaped cha...
Definition: Diagnostic.cpp:575
clang::TypeSpecifiersPipe::Pipe
@ Pipe
SourceLocation.h
clang::tok::TokenKind
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::DiagnosticsEngine::~DiagnosticsEngine
~DiagnosticsEngine()
Definition: Diagnostic.cpp:97
clang::StoredDiagnostic::getLocation
const FullSourceLoc & getLocation() const
Definition: Diagnostic.h:1694
CharInfo.h
clang::NullabilityKind::Unspecified
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
clang::Diagnostic::getLocation
const SourceLocation & getLocation() const
Definition: Diagnostic.h:1558
dump
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Definition: CoverageMappingGen.cpp:1519
clang::ForwardingDiagnosticConsumer::~ForwardingDiagnosticConsumer
~ForwardingDiagnosticConsumer() override
clang::tok::getKeywordSpelling
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
Definition: TokenKinds.cpp:40
llvm::ArrayRef
Definition: LLVM.h:34
clang::StreamingDiagnostic::AddString
void AddString(StringRef V) const
Definition: Diagnostic.h:1192
clang::StreamingDiagnostic::DiagStorageAllocator::~DiagStorageAllocator
~DiagStorageAllocator()
clang::Diagnostic::getFixItHints
ArrayRef< FixItHint > getFixItHints() const
Definition: Diagnostic.h:1651
HandleIntegerSModifier
static void HandleIntegerSModifier(unsigned ValNo, SmallVectorImpl< char > &OutStr)
HandleIntegerSModifier - Handle the integer 's' modifier.
Definition: Diagnostic.cpp:629
clang::DiagnosticsEngine::ak_nameddecl
@ ak_nameddecl
NamedDecl *.
Definition: Diagnostic.h:235
clang::StoredDiagnostic::fixit_end
fixit_iterator fixit_end() const
Definition: Diagnostic.h:1712
State
LineState State
Definition: UnwrappedLineFormatter.cpp:987
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:1145
DummyArgToStringFn
static void DummyArgToStringFn(DiagnosticsEngine::ArgumentKind AK, intptr_t QT, StringRef Modifier, StringRef Argument, ArrayRef< DiagnosticsEngine::ArgumentValue > PrevArgs, SmallVectorImpl< char > &Output, void *Cookie, ArrayRef< intptr_t > QualTypeVals)
Definition: Diagnostic.cpp:76
clang::Diagnostic::getSourceManager
SourceManager & getSourceManager() const
Definition: Diagnostic.h:1560
clang::StoredDiagnostic::getLevel
DiagnosticsEngine::Level getLevel() const
Definition: Diagnostic.h:1693
clang::diag::Flavor
Flavor
Flavors of diagnostics we can emit.
Definition: DiagnosticIDs.h:93
clang::DiagnosticMapping::setNoErrorAsFatal
void setNoErrorAsFatal(bool Value)
Definition: DiagnosticIDs.h:137
clang::DiagnosticMapping::setSeverity
void setSeverity(diag::Severity Value)
Definition: DiagnosticIDs.h:123
clang::DiagnosticsEngine::DiagnosticsEngine
DiagnosticsEngine(IntrusiveRefCntPtr< DiagnosticIDs > Diags, IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, DiagnosticConsumer *client=nullptr, bool ShouldOwnClient=true)
Definition: Diagnostic.cpp:86
clang::Diagnostic::getArgKind
DiagnosticsEngine::ArgumentKind getArgKind(unsigned Idx) const
Return the kind of the specified index.
Definition: Diagnostic.h:1570
clang::DiagnosticsEngine::ak_addrspace
@ ak_addrspace
address space
Definition: Diagnostic.h:223
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
std
Definition: Format.h:4125
clang::DiagnosticsEngine::dump
LLVM_DUMP_METHOD void dump() const
Definition: Diagnostic.cpp:103
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:111
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:873
ModifierIs
static bool ModifierIs(const char *Modifier, unsigned ModifierLen, const char(&Str)[StrLen])
ModifierIs - Return true if the specified modifier matches specified string.
Definition: Diagnostic.cpp:568
PartialDiagnostic.h
clang
Definition: CalledOnceCheck.h:17
clang::DiagnosticsEngine::ak_uint
@ ak_uint
unsigned
Definition: Diagnostic.h:214
clang::SourceManager::getDecomposedIncludedLoc
std::pair< FileID, unsigned > getDecomposedIncludedLoc(FileID FID) const
Returns the "included/expanded in" decomposed location of the given FileID.
Definition: SourceManager.cpp:1945
clang::Diagnostic::getRanges
ArrayRef< CharSourceRange > getRanges() const
Return an array reference for this diagnostic's ranges.
Definition: Diagnostic.h:1638
clang::DiagnosticsEngine::ak_c_string
@ ak_c_string
const char *
Definition: Diagnostic.h:208
clang::ComparisonCategoryType::Last
@ Last
clang::DiagnosticIDs::Ignored
@ Ignored
Definition: DiagnosticIDs.h:170
clang::DiagnosticError::ID
static char ID
Definition: DiagnosticError.h:47
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:159
clang::DiagnosticStorage::NumDiagArgs
unsigned char NumDiagArgs
The number of entries in Arguments.
Definition: Diagnostic.h:158
clang::isDigit
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
Definition: CharInfo.h:98
clang::prec::Level
Level
Definition: OperatorPrecedence.h:26
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:38
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::NullabilityKind::NullableResult
@ NullableResult
clang::DiagnosticConsumer::clear
virtual void clear()
Definition: Diagnostic.h:1733
unsigned
clang::ForwardingDiagnosticConsumer::clear
void clear() override
Definition: Diagnostic.cpp:1151
clang::NullabilityKind::Nullable
@ Nullable
Values of this type can be null.
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:480
clang::Diagnostic::hasSourceManager
bool hasSourceManager() const
Definition: Diagnostic.h:1559
c
__device__ __2f16 float c
Definition: __clang_hip_libdevice_declares.h:315
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:117
clang::TemplateDiffTypes::PrintFromType
unsigned PrintFromType
Definition: Diagnostic.h:1808
clang::TemplateDiffTypes::ShowColors
unsigned ShowColors
Definition: Diagnostic.h:1810
Tree
SyntaxTree::Impl & Tree
Definition: ASTDiff.cpp:193
clang::Diagnostic::getID
unsigned getID() const
Definition: Diagnostic.h:1557
llvm::SmallVectorImpl< char >
clang::TemplateDiffTypes::ElideType
unsigned ElideType
Definition: Diagnostic.h:1809
clang::TemplateDiffTypes::PrintTree
unsigned PrintTree
Definition: Diagnostic.h:1807
TestPluralRange
static bool TestPluralRange(unsigned Val, const char *&Start, const char *End)
TestPluralRange - Test if Val is in the parsed range. Modifies Start.
Definition: Diagnostic.cpp:663
clang::DiagnosticMapping::setNoWarningAsError
void setNoWarningAsError(bool Value)
Definition: DiagnosticIDs.h:134
clang::DiagnosticsEngine::ak_qualtype
@ ak_qualtype
QualType.
Definition: Diagnostic.h:229
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:786
clang::DiagnosticsEngine::Warning
@ Warning
Definition: Diagnostic.h:198
clang::NullabilityKind::NonNull
@ NonNull
Values of this type can never be null.
clang::SourceManager::getBufferOrFake
llvm::MemoryBufferRef getBufferOrFake(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
Definition: SourceManager.h:1023
clang::DiagnosticsEngine::ak_std_string
@ ak_std_string
std::string
Definition: Diagnostic.h:205
clang::DiagnosticsEngine::ak_declcontext
@ ak_declcontext
DeclContext *.
Definition: Diagnostic.h:241
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:180
clang::DiagnosticIDs::getWarningOptionForDiag
static StringRef getWarningOptionForDiag(unsigned DiagID)
Return the lowest-level warning option that enables the specified diagnostic.
Definition: DiagnosticIDs.cpp:625
HandlePluralModifier
static void HandlePluralModifier(const Diagnostic &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, SmallVectorImpl< char > &OutStr)
HandlePluralModifier - Handle the integer 'plural' modifier.
Definition: Diagnostic.cpp:746
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:47
clang::StoredDiagnostic::fixit_begin
fixit_iterator fixit_begin() const
Definition: Diagnostic.h:1711
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1523
PluralNumber
static unsigned PluralNumber(const char *&Start, const char *End)
PluralNumber - Parse an unsigned integer and advance Start.
Definition: Diagnostic.cpp:651
clang::DiagnosticsEngine::ak_nestednamespec
@ ak_nestednamespec
NestedNameSpecifier *.
Definition: Diagnostic.h:238