25#include "llvm/ADT/IntrusiveRefCntPtr.h"
26#include "llvm/ADT/STLExtras.h"
27#include "llvm/ADT/SmallVector.h"
28#include "llvm/ADT/StringExtras.h"
29#include "llvm/ADT/StringMap.h"
30#include "llvm/ADT/StringRef.h"
31#include "llvm/Support/ConvertUTF.h"
32#include "llvm/Support/CrashRecoveryContext.h"
33#include "llvm/Support/Error.h"
34#include "llvm/Support/FormatVariadic.h"
35#include "llvm/Support/MemoryBuffer.h"
36#include "llvm/Support/SpecialCaseList.h"
37#include "llvm/Support/Unicode.h"
38#include "llvm/Support/VirtualFileSystem.h"
39#include "llvm/Support/raw_ostream.h"
71 StringRef Modifier, StringRef Argument,
75 StringRef Str =
"<can't format argument>";
76 Output.append(Str.begin(), Str.end());
82 :
public llvm::SpecialCaseList {
84 static std::unique_ptr<WarningsSpecialCaseList>
85 create(
const llvm::MemoryBuffer &Input, std::string &Err);
98 return DiagToSection.contains(DiagId);
102 llvm::DenseMap<diag::kind, const Section *> DiagToSection;
108 bool ShouldOwnClient)
109 : Diags(
std::move(diags)), DiagOpts(DiagOpts) {
125 DiagStatesByLoc.dump(*SourceMgr, DiagName);
129 bool ShouldOwnClient) {
130 Owner.reset(ShouldOwnClient ? client :
nullptr);
135 DiagStateOnPushStack.push_back(GetCurDiagState());
139 if (DiagStateOnPushStack.empty())
142 if (DiagStateOnPushStack.back() != GetCurDiagState()) {
144 PushDiagStatePoint(DiagStateOnPushStack.back(), Loc);
146 DiagStateOnPushStack.pop_back();
153 ErrorOccurred =
false;
154 UncompilableErrorOccurred =
false;
155 FatalErrorOccurred =
false;
156 UnrecoverableErrorOccurred =
false;
160 TrapNumErrorsOccurred = 0;
161 TrapNumUnrecoverableErrorsOccurred = 0;
168 DiagStatesByLoc.clear(
false);
169 DiagStateOnPushStack.clear();
173 DiagStates.emplace_back(*Diags);
174 DiagStatesByLoc.appendFirst(&DiagStates.back());
180 std::pair<iterator, bool>
Result = DiagMap.try_emplace(
Diag);
189 return Result.first->second;
192void DiagnosticsEngine::DiagStateMap::appendFirst(DiagState *State) {
193 assert(Files.empty() &&
"not first");
194 FirstDiagState = CurDiagState = State;
195 CurDiagStateLoc = SourceLocation();
198void DiagnosticsEngine::DiagStateMap::append(SourceManager &SrcMgr,
201 CurDiagState = State;
202 CurDiagStateLoc = Loc;
205 unsigned Offset = Decomp.second;
206 for (
File *F = getFile(SrcMgr, Decomp.first); F;
207 Offset = F->ParentOffset, F = F->Parent) {
208 F->HasLocalTransitions =
true;
209 auto &
Last = F->StateTransitions.back();
210 assert(
Last.Offset <= Offset &&
"state transitions added out of order");
212 if (
Last.Offset == Offset) {
213 if (
Last.State == State)
219 F->StateTransitions.push_back({State, Offset});
223DiagnosticsEngine::DiagState *
224DiagnosticsEngine::DiagStateMap::lookup(SourceManager &SrcMgr,
225 SourceLocation Loc)
const {
228 return FirstDiagState;
231 const File *F = getFile(SrcMgr, Decomp.first);
232 return F->lookup(Decomp.second);
235DiagnosticsEngine::DiagState *
236DiagnosticsEngine::DiagStateMap::File::lookup(
unsigned Offset)
const {
238 llvm::partition_point(StateTransitions, [=](
const DiagStatePoint &P) {
239 return P.Offset <= Offset;
241 assert(OnePastIt != StateTransitions.begin() &&
"missing initial state");
242 return OnePastIt[-1].State;
245DiagnosticsEngine::DiagStateMap::File *
246DiagnosticsEngine::DiagStateMap::getFile(SourceManager &SrcMgr,
249 if (LastLookupFileID != ID) {
251 LastLookupFile = getFileUncached(SrcMgr, ID);
252 LastLookupFileID =
ID;
254 return LastLookupFile;
257DiagnosticsEngine::DiagStateMap::File *
258DiagnosticsEngine::DiagStateMap::getFileUncached(SourceManager &SrcMgr,
261 auto [FilePtr, Inserted] = getOrInsertFile(ID);
270 F.Parent = getFile(SrcMgr, Decomp.first);
271 F.ParentOffset = Decomp.second;
272 F.StateTransitions.push_back({F.Parent->lookup(Decomp.second), 0});
281 F.StateTransitions.push_back({FirstDiagState, 0});
286void DiagnosticsEngine::DiagStateMap::dump(SourceManager &SrcMgr,
287 StringRef DiagName)
const {
288 llvm::errs() <<
"diagnostic state at ";
289 CurDiagStateLoc.print(llvm::errs(), SrcMgr);
290 llvm::errs() <<
": " << CurDiagState <<
"\n";
292 SmallVector<std::pair<FileID, File *>, 16> SortedFiles;
293 for (
const auto &[ID, FilePtr] : Files)
294 SortedFiles.emplace_back(ID, FilePtr.get());
295 llvm::sort(SortedFiles, llvm::less_first());
297 for (
auto &F : SortedFiles) {
301 bool PrintedOuterHeading =
false;
302 auto PrintOuterHeading = [&] {
303 if (PrintedOuterHeading)
305 PrintedOuterHeading =
true;
307 llvm::errs() <<
"File " << &
File <<
" <FileID " <<
ID.getHashValue()
312 assert(
File.ParentOffset == Decomp.second);
313 llvm::errs() <<
" parent " <<
File.Parent <<
" <FileID "
314 << Decomp.first.getHashValue() <<
"> ";
317 .
print(llvm::errs(), SrcMgr);
319 if (
File.HasLocalTransitions)
320 llvm::errs() <<
" has_local_transitions";
321 llvm::errs() <<
"\n";
324 if (DiagName.empty())
327 for (DiagStatePoint &Transition :
File.StateTransitions) {
328 bool PrintedInnerHeading =
false;
329 auto PrintInnerHeading = [&] {
330 if (PrintedInnerHeading)
332 PrintedInnerHeading =
true;
338 .
print(llvm::errs(), SrcMgr);
339 llvm::errs() <<
": state " << Transition.State <<
":\n";
342 if (DiagName.empty())
345 for (
auto &Mapping : *Transition.State) {
349 if (!DiagName.empty() && DiagName != Option)
355 llvm::errs() <<
"<unknown " << Mapping.first <<
">";
357 llvm::errs() << Option;
358 llvm::errs() <<
": ";
360 switch (Mapping.second.getSeverity()) {
362 llvm::errs() <<
"ignored";
365 llvm::errs() <<
"remark";
368 llvm::errs() <<
"warning";
371 llvm::errs() <<
"error";
374 llvm::errs() <<
"fatal";
378 if (!Mapping.second.isUser())
379 llvm::errs() <<
" default";
380 if (Mapping.second.isPragma())
381 llvm::errs() <<
" pragma";
382 if (Mapping.second.hasNoWarningAsError())
383 llvm::errs() <<
" no-error";
384 if (Mapping.second.hasNoErrorAsFatal())
385 llvm::errs() <<
" no-fatal";
386 if (Mapping.second.wasUpgradedFromWarning())
387 llvm::errs() <<
" overruled";
388 llvm::errs() <<
"\n";
394void DiagnosticsEngine::PushDiagStatePoint(DiagState *State,
395 SourceLocation Loc) {
396 assert(Loc.
isValid() &&
"Adding invalid loc point");
397 DiagStatesByLoc.append(*SourceMgr, Loc, State);
402 assert((Diags->isWarningOrExtension(
Diag) ||
404 "Cannot map errors into warnings!");
405 assert((L.
isInvalid() || SourceMgr) &&
"No SourceMgr for valid location");
409 bool WasUpgradedFromWarning =
false;
415 WasUpgradedFromWarning =
true;
428 if ((L.
isInvalid() || L == DiagStatesByLoc.getCurDiagStateLoc()) &&
429 DiagStatesByLoc.getCurDiagState()) {
434 DiagStatesByLoc.getCurDiagState()->setMapping(
Diag, Mapping);
441 DiagStates.push_back(*GetCurDiagState());
442 DiagStates.back().setMapping(
Diag, Mapping);
443 PushDiagStatePoint(&DiagStates.back(), L);
451 if (Diags->getDiagnosticsInGroup(Flavor, Group, GroupDiags))
454 Diags->setGroupSeverity(Group, Map);
538 std::vector<diag::kind> AllDiags;
543 if (Diags->isWarningOrExtension(
Diag))
547std::unique_ptr<DiagnosticsEngine::WarningsSpecialCaseList>
549 const llvm::MemoryBuffer &Input, std::string &Err) {
550 auto WarningSuppressionList = std::make_unique<WarningsSpecialCaseList>();
551 if (!WarningSuppressionList->createInternal(&Input, Err))
553 return WarningSuppressionList;
559 for (
const auto &SectionEntry : sections()) {
560 StringRef DiagGroup = SectionEntry.name();
561 if (DiagGroup ==
"*") {
568 if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
569 WarningFlavor, DiagGroup, GroupDiags)) {
570 StringRef Suggestion =
572 Diags.Report(diag::warn_unknown_diag_option)
573 <<
static_cast<unsigned>(WarningFlavor) << DiagGroup
574 << !Suggestion.empty() << Suggestion;
580 DiagToSection[
Diag] = &SectionEntry;
587 if (!WarningSuppressionList) {
590 Report(diag::err_drv_malformed_warning_suppression_mapping)
591 << Input.getBufferIdentifier() <<
Error;
594 WarningSuppressionList->processSections(*
this);
595 DiagSuppressionMapping = std::move(WarningSuppressionList);
600 const Section *DiagSection = DiagToSection.lookup(DiagId);
607 StringRef F = llvm::sys::path::remove_leading_dotslash(PLoc.
getFilename());
609 unsigned LastSup = DiagSection->getLastMatch(
"src", F,
"");
613 unsigned LastEmit = DiagSection->getLastMatch(
"src", F,
"emit");
614 return LastSup > LastEmit;
632 return DiagSuppressionMapping->isDiagSuppressed(DiagId, DiagLoc,
637 return DiagSuppressionMapping && DiagSuppressionMapping->hasSection(DiagId);
648 assert(Client &&
"DiagnosticConsumer not set!");
656 assert(DiagLevel !=
Ignored &&
"Cannot emit ignored diagnostics!");
658 "Trap diagnostics should not be consumed by the DiagnosticsEngine");
671 assert(
getClient() &&
"DiagnosticClient not set!");
674 unsigned DiagID = Info.
getID();
679 if (DiagLevel >=
Error) {
680 ++TrapNumErrorsOccurred;
681 if (Diags->isUnrecoverable(DiagID))
682 ++TrapNumUnrecoverableErrorsOccurred;
685 if (SuppressAllDiagnostics)
688 if (DiagLevel !=
Note) {
693 if (LastDiagLevel ==
Fatal)
694 FatalErrorOccurred =
true;
696 LastDiagLevel = DiagLevel;
701 if (FatalErrorOccurred) {
702 if (DiagLevel >=
Error && Client->IncludeInDiagnosticCounts())
713 if (DiagLevel >=
Error) {
714 if (Diags->isUnrecoverable(DiagID))
715 UnrecoverableErrorOccurred =
true;
718 if (Diags->isDefaultMappingAsError(DiagID))
719 UncompilableErrorOccurred =
true;
721 ErrorOccurred =
true;
722 if (Client->IncludeInDiagnosticCounts())
727 if (ErrorLimit && NumErrors > ErrorLimit && DiagLevel ==
Error) {
728 Report(diag::fatal_too_many_errors);
735 if (Info.
getID() == diag::fatal_too_many_errors)
736 FatalErrorOccurred =
true;
745 assert(
getClient() &&
"DiagnosticClient not set!");
755 Emitted = DiagLevel !=
Ignored;
761 Emitted = ProcessDiag(DB);
770 DiagLoc(DiagLoc), DiagID(DiagID), IsActive(
true) {
771 assert(DiagObj &&
"DiagnosticBuilder requires a valid DiagnosticsEngine!");
774DiagnosticBuilder::DiagnosticBuilder(
const DiagnosticBuilder &D)
778 FlagValue = D.FlagValue;
783 IsActive = D.IsActive;
784 IsForceEmit = D.IsForceEmit;
790 : DiagObj(DO), DiagLoc(DiagBuilder.DiagLoc), DiagID(DiagBuilder.DiagID),
791 FlagValue(DiagBuilder.FlagValue), DiagStorage(*DiagBuilder.
getStorage()) {
796 StringRef StoredDiagMessage)
797 : DiagObj(DO), DiagLoc(DiagLoc), DiagID(DiagID), DiagStorage(DiagStorage),
798 StoredDiagMessage(StoredDiagMessage) {}
814template <std::
size_t StrLen>
815static bool ModifierIs(
const char *Modifier,
unsigned ModifierLen,
816 const char (&Str)[StrLen]) {
817 return StrLen - 1 == ModifierLen && memcmp(Modifier, Str, StrLen - 1) == 0;
825 for (; I != E; ++I) {
826 if (Depth == 0 && *I ==
Target)
828 if (Depth != 0 && *I ==
'}')
840 for (I++; I != E && !
isDigit(*I) && *I !=
'{'; I++)
858 const char *Argument,
unsigned ArgumentLen,
860 const char *ArgumentEnd = Argument + ArgumentLen;
864 const char *NextVal =
ScanFormat(Argument, ArgumentEnd,
'|');
865 assert(NextVal != ArgumentEnd &&
866 "Value for integer select modifier was"
867 " larger than the number of options in the diagnostic string!");
868 Argument = NextVal + 1;
873 const char *EndPtr =
ScanFormat(Argument, ArgumentEnd,
'|');
885 OutStr.push_back(
's');
894 assert(ValNo != 0 &&
"ValNo must be strictly positive!");
896 llvm::raw_svector_ostream Out(OutStr);
900 Out << ValNo << llvm::getOrdinalSuffix(ValNo);
911 static constexpr std::array<std::pair<int64_t, char>, 4> Units = {
912 {{1'000'000'000'000L,
'T'},
913 {1'000'000'000L,
'G'},
917 llvm::raw_svector_ostream Out(OutStr);
922 for (
const auto &[UnitSize, UnitSign] : Units) {
923 if (ValNo >= UnitSize) {
924 Out << llvm::format(
"%0.2f%c", ValNo /
static_cast<double>(UnitSize),
936 while (Start != End && *Start >=
'0' && *Start <=
'9') {
953 assert(*Start ==
',' &&
"Bad plural expression syntax: expected ,");
956 assert(*Start ==
']' &&
"Bad plural expression syntax: expected )");
958 return Low <= Val && Val <= High;
973 assert(*Start ==
'=' &&
"Bad plural expression syntax: expected =");
975 unsigned ValMod = ValNo % Arg;
979 assert((
C ==
'[' || (
C >=
'0' &&
C <=
'9')) &&
980 "Bad plural expression syntax: unexpected character");
987 Start = std::find(Start, End,
',');
1029 const char *Argument,
unsigned ArgumentLen,
1031 const char *ArgumentEnd = Argument + ArgumentLen;
1033 assert(Argument < ArgumentEnd &&
"Plural expression didn't match.");
1034 const char *ExprEnd = Argument;
1035 while (*ExprEnd !=
':') {
1036 assert(ExprEnd != ArgumentEnd &&
"Plural missing expression end");
1040 Argument = ExprEnd + 1;
1041 ExprEnd =
ScanFormat(Argument, ArgumentEnd,
'|');
1048 Argument =
ScanFormat(Argument, ArgumentEnd - 1,
'|') + 1;
1057 case tok::identifier:
1058 return "identifier";
1068 if (StoredDiagMessage.has_value()) {
1069 OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
1082 bool ForCodepoint) {
1083 OutStr.reserve(OutStr.size() + Str.size());
1084 auto *Begin =
reinterpret_cast<const unsigned char *
>(Str.data());
1085 llvm::raw_svector_ostream OutStream(OutStr);
1086 unsigned Size = Str.size();
1087 const unsigned char *End = Begin + Size;
1089 unsigned Size = llvm::getUTF8SequenceSize(Begin, End);
1091 Size = llvm::findMaximalSubpartOfIllFormedUTF8Sequence(Begin, End);
1094 while (Begin != End) {
1096 OutStream << *Begin;
1100 if (ForCodepoint && *Begin < 0x80) {
1102 OutStream <<
"'" << *Begin <<
"'";
1107 if (llvm::isLegalUTF8Sequence(Begin, End)) {
1108 llvm::UTF32 CodepointValue;
1109 llvm::UTF32 *CpPtr = &CodepointValue;
1110 const unsigned char *CodepointBegin = Begin;
1111 const unsigned char *CodepointEnd =
1112 Begin + llvm::getNumBytesForUTF8(*Begin);
1113 llvm::ConversionResult Res = llvm::ConvertUTF8toUTF32(
1114 &Begin, CodepointEnd, &CpPtr, CpPtr + 1, llvm::strictConversion);
1117 llvm::conversionOK == Res &&
1118 "the sequence is legal UTF-8 but we couldn't convert it to UTF-32");
1119 assert(Begin == CodepointEnd &&
1120 "we must be further along in the string now");
1122 if (llvm::sys::unicode::isPrintable(CodepointValue) ||
1123 (!ForCodepoint && llvm::sys::unicode::isFormatting(CodepointValue))) {
1124 OutStream << (ForCodepoint ?
"'" :
"")
1125 << StringRef(
reinterpret_cast<const char *
>(CodepointBegin),
1126 std::distance(CodepointBegin, CodepointEnd))
1127 << (ForCodepoint ?
"' " :
"");
1132 OutStream << (ForCodepoint ?
"" :
"<") <<
"U+"
1133 << llvm::format_hex_no_prefix(CodepointValue, 4,
true)
1134 << (ForCodepoint ?
"" :
">");
1138 OutStream <<
"<0x" << llvm::format_hex_no_prefix(*Begin, 2,
true) <<
">";
1159 char ResultBuf[UNI_MAX_UTF8_BYTES_PER_CODE_POINT];
1160 char *ResultPtr = ResultBuf;
1161 if (!llvm::ConvertCodePointToUTF8(CP, ResultPtr))
1164 StringRef(ResultBuf, ResultPtr - ResultBuf));
1172 if (DiagEnd - DiagStr == 2 && StringRef(DiagStr, DiagEnd - DiagStr) ==
"%0" &&
1190 for (
unsigned i = 0, e =
getNumArgs(); i < e; ++i)
1194 while (DiagStr != DiagEnd) {
1195 if (DiagStr[0] !=
'%') {
1197 const char *StrEnd = std::find(DiagStr, DiagEnd,
'%');
1198 OutStr.append(DiagStr, StrEnd);
1202 OutStr.push_back(DiagStr[1]);
1215 const char *Modifier =
nullptr, *Argument =
nullptr;
1216 unsigned ModifierLen = 0, ArgumentLen = 0;
1221 while (DiagStr[0] ==
'-' || (DiagStr[0] >=
'a' && DiagStr[0] <=
'z'))
1223 ModifierLen = DiagStr - Modifier;
1226 if (DiagStr[0] ==
'{') {
1231 assert(DiagStr != DiagEnd &&
"Mismatched {}'s in diagnostic string!");
1232 ArgumentLen = DiagStr - Argument;
1237 assert(
isDigit(*DiagStr) &&
"Invalid format for argument in diagnostic");
1238 unsigned ArgNo = *DiagStr++ -
'0';
1241 unsigned ArgNo2 = ArgNo;
1244 if (
ModifierIs(Modifier, ModifierLen,
"diff")) {
1245 assert(*DiagStr ==
',' &&
isDigit(*(DiagStr + 1)) &&
1246 "Invalid format for diff modifier");
1248 ArgNo2 = *DiagStr++ -
'0';
1259 const char *ArgumentEnd = Argument + ArgumentLen;
1262 "Found too many '|'s in a %diff modifier!");
1264 const char *SecondDollar =
ScanFormat(FirstDollar + 1,
Pipe,
'$');
1265 const char ArgStr1[] = {
'%',
static_cast<char>(
'0' + ArgNo)};
1266 const char ArgStr2[] = {
'%',
static_cast<char>(
'0' + ArgNo2)};
1280 StringRef S = [&]() -> StringRef {
1285 return SZ ? SZ :
"(null)";
1287 bool Quoted =
false;
1288 if (
ModifierIs(Modifier, ModifierLen,
"quoted")) {
1290 OutStr.push_back(
'\'');
1292 assert(ModifierLen == 0 &&
"unknown modifier for string");
1296 OutStr.push_back(
'\'');
1303 if (
ModifierIs(Modifier, ModifierLen,
"select")) {
1306 }
else if (
ModifierIs(Modifier, ModifierLen,
"s")) {
1308 }
else if (
ModifierIs(Modifier, ModifierLen,
"plural")) {
1311 }
else if (
ModifierIs(Modifier, ModifierLen,
"ordinal")) {
1313 }
else if (
ModifierIs(Modifier, ModifierLen,
"human")) {
1316 assert(ModifierLen == 0 &&
"Unknown integer modifier");
1317 llvm::raw_svector_ostream(OutStr) << Val;
1324 if (
ModifierIs(Modifier, ModifierLen,
"select")) {
1326 }
else if (
ModifierIs(Modifier, ModifierLen,
"s")) {
1328 }
else if (
ModifierIs(Modifier, ModifierLen,
"plural")) {
1331 }
else if (
ModifierIs(Modifier, ModifierLen,
"ordinal")) {
1333 }
else if (
ModifierIs(Modifier, ModifierLen,
"human")) {
1336 assert(ModifierLen == 0 &&
"Unknown integer modifier");
1337 llvm::raw_svector_ostream(OutStr) << Val;
1344 assert(ModifierLen == 0 &&
"No modifiers for token kinds yet");
1346 llvm::raw_svector_ostream Out(OutStr);
1349 Out <<
'\'' << S <<
'\'';
1358 Out <<
'<' << S <<
'>';
1366 assert(ModifierLen == 0 &&
"No modifiers for strings yet");
1370 const char *S =
"(null)";
1371 OutStr.append(S, S + strlen(S));
1375 llvm::raw_svector_ostream(OutStr) <<
'\'' << II->
getName() <<
'\'';
1389 StringRef(Modifier, ModifierLen),
1390 StringRef(Argument, ArgumentLen),
1391 FormattedArgs, OutStr, QualTypeVals);
1403 const char *ArgumentEnd = Argument + ArgumentLen;
1408 if (
getDiags()->PrintTemplateTree && Tree.empty()) {
1412 StringRef(Modifier, ModifierLen),
1413 StringRef(Argument, ArgumentLen),
1414 FormattedArgs, Tree, QualTypeVals);
1416 if (!Tree.empty()) {
1424 const char *FirstDollar =
ScanFormat(Argument, ArgumentEnd,
'$');
1425 const char *SecondDollar =
ScanFormat(FirstDollar + 1, ArgumentEnd,
'$');
1434 StringRef(Modifier, ModifierLen),
1435 StringRef(Argument, ArgumentLen),
1436 FormattedArgs, OutStr, QualTypeVals);
1438 FormattedArgs.push_back(
1447 StringRef(Modifier, ModifierLen),
1448 StringRef(Argument, ArgumentLen),
1449 FormattedArgs, OutStr, QualTypeVals);
1451 FormattedArgs.push_back(
1466 FormattedArgs.push_back(std::make_pair(Kind,
getRawArg(ArgNo)));
1468 FormattedArgs.push_back(
1474 OutStr.append(Tree.begin(), Tree.end());
1479 : ID(ID), Level(Level), Message(Message) {}
1483 : ID(Info.
getID()), Level(Level) {
1486 "Valid source location without setting a source manager for diagnostic");
1491 this->Message.assign(Message.begin(), Message.end());
1500 : ID(ID), Level(Level), Loc(Loc), Message(Message),
1501 Ranges(Ranges.begin(), Ranges.end()),
1502 FixIts(FixIts.begin(), FixIts.end()) {}
1518void IgnoringDiagConsumer::anchor() {}
1524 Target.HandleDiagnostic(DiagLevel, Info);
1533 return Target.IncludeInDiagnosticCounts();
1537 for (
unsigned I = 0; I != NumCached; ++I)
1538 FreeList[I] = Cached + I;
1539 NumFreeListEntries = NumCached;
1545 assert((NumFreeListEntries == NumCached ||
1546 llvm::CrashRecoveryContext::isRecoveringFromCrash()) &&
1547 "A partial is on the lam");
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...
static void HandlePluralModifier(const Diagnostic &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, SmallVectorImpl< char > &OutStr)
HandlePluralModifier - Handle the integer 'plural' modifier.
static void HandleIntegerSModifier(unsigned ValNo, SmallVectorImpl< char > &OutStr)
HandleIntegerSModifier - Handle the integer 's' modifier.
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)
static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End)
EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.
static void HandleIntegerHumanModifier(int64_t ValNo, SmallVectorImpl< char > &OutStr)
static unsigned PluralNumber(const char *&Start, const char *End)
PluralNumber - Parse an unsigned integer and advance Start.
static void HandleSelectModifier(const Diagnostic &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, SmallVectorImpl< char > &OutStr)
HandleSelectModifier - Handle the integer 'select' modifier.
static bool ModifierIs(const char *Modifier, unsigned ModifierLen, const char(&Str)[StrLen])
ModifierIs - Return true if the specified modifier matches specified string.
static bool TestPluralRange(unsigned Val, const char *&Start, const char *End)
TestPluralRange - Test if Val is in the parsed range. Modifies Start.
static void HandleOrdinalModifier(unsigned ValNo, SmallVectorImpl< char > &OutStr)
HandleOrdinalModifier - Handle the integer 'ord' modifier.
static const char * getTokenDescForDiagnostic(tok::TokenKind Kind)
Returns the friendly description for a token kind that will appear without quotes in diagnostic messa...
Defines the Diagnostic-related interfaces.
static llvm::GlobalValue::DLLStorageClassTypes getStorage(CodeGenModule &CGM, StringRef Name)
Defines the Diagnostic IDs-related interfaces.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Result
Implement __builtin_bit_cast and related operations.
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.
llvm::MachO::Target Target
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the clang::TokenKind enum and support functions.
bool isDiagSuppressed(diag::kind DiagId, SourceLocation DiagLoc, const SourceManager &SM) const
bool hasSection(diag::kind DiagId) const
Whether a section applies to DiagId.
void processSections(DiagnosticsEngine &Diags)
static std::unique_ptr< WarningsSpecialCaseList > create(const llvm::MemoryBuffer &Input, std::string &Err)
A little helper class used to produce diagnostics.
void Clear() const
Clear out the current diagnostic.
friend class DiagnosticsEngine
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
virtual ~DiagnosticConsumer()
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.
unsigned NumErrors
Number of errors reported.
unsigned NumWarnings
Number of warnings reported.
virtual bool IncludeInDiagnosticCounts() const
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
void initCustomDiagMapping(DiagnosticMapping &, unsigned DiagID)
static StringRef getNearestOption(diag::Flavor Flavor, StringRef Group)
Get the diagnostic option with the closest edit distance to the given group name.
DiagnosticMapping getDefaultMapping(unsigned DiagID) const
Get the default mapping for this diagnostic.
static bool IsCustomDiag(diag::kind Diag)
static void getAllDiagnostics(diag::Flavor Flavor, std::vector< diag::kind > &Diags)
Get the set of all diagnostic IDs.
void setNoWarningAsError(bool Value)
void setSeverity(diag::Severity Value)
diag::Severity getSeverity() const
void setUpgradedFromWarning(bool Value)
void setNoErrorAsFatal(bool Value)
bool hasNoWarningAsError() const
Options for controlling the compiler diagnostics engine.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
Diagnostic(const DiagnosticsEngine *DO, const DiagnosticBuilder &DiagBuilder)
const SourceLocation & getLocation() const
const std::string & getArgStdStr(unsigned Idx) const
Return the provided argument string specified by Idx.
void FormatDiagnostic(SmallVectorImpl< char > &OutStr) const
Format this diagnostic into a string, substituting the formal arguments into the %0 slots.
uint64_t getRawArg(unsigned Idx) const
Return the specified non-string argument in an opaque form.
const char * getArgCStr(unsigned Idx) const
Return the specified C string argument.
const IdentifierInfo * getArgIdentifier(unsigned Idx) const
Return the specified IdentifierInfo argument.
SourceManager & getSourceManager() const
ArrayRef< FixItHint > getFixItHints() const
unsigned getNumArgs() const
bool hasSourceManager() const
DiagnosticsEngine::ArgumentKind getArgKind(unsigned Idx) const
Return the kind of the specified index.
int64_t getArgSInt(unsigned Idx) const
Return the specified signed integer argument.
uint64_t getArgUInt(unsigned Idx) const
Return the specified unsigned integer argument.
ArrayRef< CharSourceRange > getRanges() const
Return an array reference for this diagnostic's ranges.
const DiagnosticsEngine * getDiags() const
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
bool hasSourceManager() const
bool EmitDiagnostic(const DiagnosticBuilder &DB, bool Force=false)
Emit the diagnostic.
void setDiagSuppressionMapping(llvm::MemoryBuffer &Input)
Diagnostic suppression mappings can be used to suppress specific diagnostics in specific files.
DiagnosticsEngine(IntrusiveRefCntPtr< DiagnosticIDs > Diags, DiagnosticOptions &DiagOpts, DiagnosticConsumer *client=nullptr, bool ShouldOwnClient=true)
DiagStateSystemClass getDiagStateSystemClassForLoc(SourceLocation Loc) const
Returns whether Loc is in a system header and/or a system macro.
bool isSuppressedViaMapping(diag::kind DiagId, SourceLocation DiagLoc) const
void setSeverityForAll(diag::Flavor Flavor, diag::Severity Map, SourceLocation Loc=SourceLocation())
Add the specified mapping to all diagnostics of the specified flavor.
LLVM_DUMP_METHOD void dump() const
void ResetPragmas()
We keep a cache of FileIDs for diagnostics mapped by pragmas.
void setClient(DiagnosticConsumer *client, bool ShouldOwnClient=true)
Set the diagnostic client associated with this diagnostic object.
bool hasDiagSuppressionMappingFor(diag::kind DiagId) const
True if an active diagnostic suppression mapping has a section for DiagId, so that its severity can d...
SourceManager & getSourceManager() const
void pushMappings(SourceLocation Loc)
Copies the current DiagMappings and pushes the new copy onto the top of the stack.
void setSeverity(diag::kind Diag, diag::Severity Map, SourceLocation Loc)
This allows the client to specify that certain warnings are ignored.
Level
The level of the diagnostic, after it has been through mapping.
friend class DiagnosticBuilder
DiagnosticConsumer * getClient()
@ ak_nameddecl
NamedDecl *.
@ ak_declcontext
DeclContext *.
@ ak_addrspace
address space
@ ak_identifierinfo
IdentifierInfo.
@ ak_qualtype_pair
pair<QualType, QualType>
@ ak_attr_info
AttributeCommonInfo *.
@ ak_c_string
const char *
@ ak_declarationname
DeclarationName.
@ ak_tokenkind
enum TokenKind : unsigned
@ ak_std_string
std::string
@ ak_nestednamespec
NestedNameSpecifier *.
Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const
Based on the way the client configured the DiagnosticsEngine object, classify the specified diagnosti...
bool setDiagnosticGroupErrorAsFatal(StringRef Group, bool Enabled)
Set the error-as-fatal flag for the given diagnostic group.
bool setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled)
Set the warning-as-error flag for the given diagnostic group.
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.
bool setSeverityForGroup(diag::Flavor Flavor, StringRef Group, diag::Severity Map, SourceLocation Loc=SourceLocation())
Change an entire diagnostic group (e.g.
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...
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
void Reset(bool soft=false)
Reset the state of the diagnostic object to its initial configuration.
static FileID getSentinel()
bool IncludeInDiagnosticCounts() const override
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
~ForwardingDiagnosticConsumer() override
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.
A SourceLocation and its associated SourceManager.
bool hasManager() const
Checks whether the SourceManager is present.
const SourceManager & getManager() const
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
Represents an unpacked "presumed" location which can be presented to the user.
const char * getFilename() const
Return the presumed filename of this location.
Encodes a location in the source.
std::string printToString(const SourceManager &SM) const
bool isValid() const
Return true if this is a valid SourceLocation object.
void print(raw_ostream &OS, const SourceManager &SM) const
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
DiagnosticsEngine & getDiagnostics() const
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
llvm::MemoryBufferRef getBufferOrFake(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
bool isInSystemMacro(SourceLocation loc) const
Returns whether Loc is expanded from a macro in a system header.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
FileIDAndOffset getDecomposedIncludedLoc(FileID FID) const
Returns the "included/expanded in" decomposed location of the given FileID.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID.
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
range_iterator range_begin() const
StoredDiagnostic()=default
DiagnosticsEngine::Level getLevel() const
fixit_iterator fixit_begin() const
const FullSourceLoc & getLocation() const
range_iterator range_end() const
StringRef getMessage() const
fixit_iterator fixit_end() const
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
DiagStorageAllocator * Allocator
Allocator used to allocate storage for this diagnostic.
StreamingDiagnostic()=default
DiagnosticStorage * DiagStorage
void AddString(StringRef V) const
Flavor
Flavors of diagnostics we can emit.
@ WarningOrError
A diagnostic that indicates a problem or potential problem.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
@ Warning
Present this diagnostic as a warning.
@ Fatal
Present this diagnostic as a fatal error.
@ Error
Present this diagnostic as an error.
@ Remark
Present this diagnostic as a remark.
@ Ignored
Do not present this diagnostic, ignore it.
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!
Top level wrappers for InstallAPI frontend operations.
LLVM_READONLY bool isPrintable(unsigned char c)
Return true if this character is an ASCII printable character; that is, a character that should take ...
DiagStateSystemClass
Whether a source location is in a system header and/or a system macro.
std::pair< FileID, unsigned > FileIDAndOffset
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
@ Result
The result type of a method or function.
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
void EscapeStringForDiagnostic(StringRef Str, SmallVectorImpl< char > &OutStr)
EscapeStringForDiagnostic - Append Str to the diagnostic buffer, escaping non-printable characters an...
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
LLVM_READONLY bool isWhitespace(unsigned char c)
Return true if this character is horizontal or vertical ASCII whitespace: ' ', '\t',...
SmallString< 16 > EscapeSingleCodepointForDiagnostic(StringRef Str)
Displays a single Unicode codepoint in U+NNNN notation, optionally prepending the quoted codepoint it...
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
LLVM_READONLY bool isPunctuation(unsigned char c)
Return true if this character is an ASCII punctuation character.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type,...
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t int64_t
SmallVector< CharSourceRange, 8 > DiagRanges
The list of ranges added to this diagnostic.
SmallVector< FixItHint, 6 > FixItHints
If valid, provides a hint with some code to insert, remove, or modify at a particular position.
unsigned TemplateDiffUsed