@@ -67,12 +67,12 @@ const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB,
67
67
return DB;
68
68
}
69
69
70
- static void DummyArgToStringFn (DiagnosticsEngine::ArgumentKind AK, intptr_t QT,
71
- StringRef Modifier, StringRef Argument ,
72
- ArrayRef<DiagnosticsEngine::ArgumentValue> PrevArgs ,
73
- SmallVectorImpl< char > &Output ,
74
- void *Cookie,
75
- ArrayRef<intptr_t > QualTypeVals) {
70
+ static void
71
+ DummyArgToStringFn (DiagnosticsEngine::ArgumentKind AK, intptr_t QT ,
72
+ StringRef Modifier, StringRef Argument ,
73
+ ArrayRef<DiagnosticsEngine::ArgumentValue> PrevArgs ,
74
+ SmallVectorImpl< char > &Output, void *Cookie,
75
+ ArrayRef<intptr_t > QualTypeVals) {
76
76
StringRef Str = " <can't format argument>" ;
77
77
Output.append (Str.begin (), Str.end ());
78
78
}
@@ -94,9 +94,7 @@ DiagnosticsEngine::~DiagnosticsEngine() {
94
94
setClient (nullptr );
95
95
}
96
96
97
- void DiagnosticsEngine::dump () const {
98
- DiagStatesByLoc.dump (*SourceMgr);
99
- }
97
+ void DiagnosticsEngine::dump () const { DiagStatesByLoc.dump (*SourceMgr); }
100
98
101
99
void DiagnosticsEngine::dump (StringRef DiagName) const {
102
100
DiagStatesByLoc.dump (*SourceMgr, DiagName);
@@ -259,7 +257,8 @@ void DiagnosticsEngine::DiagStateMap::dump(SourceManager &SrcMgr,
259
257
260
258
bool PrintedOuterHeading = false ;
261
259
auto PrintOuterHeading = [&] {
262
- if (PrintedOuterHeading) return ;
260
+ if (PrintedOuterHeading)
261
+ return ;
263
262
PrintedOuterHeading = true ;
264
263
265
264
llvm::errs () << " File " << &File << " <FileID " << ID.getHashValue ()
@@ -272,8 +271,8 @@ void DiagnosticsEngine::DiagStateMap::dump(SourceManager &SrcMgr,
272
271
llvm::errs () << " parent " << File.Parent << " <FileID "
273
272
<< Decomp.first .getHashValue () << " > " ;
274
273
SrcMgr.getLocForStartOfFile (Decomp.first )
275
- .getLocWithOffset (Decomp.second )
276
- .print (llvm::errs (), SrcMgr);
274
+ .getLocWithOffset (Decomp.second )
275
+ .print (llvm::errs (), SrcMgr);
277
276
}
278
277
if (File.HasLocalTransitions )
279
278
llvm::errs () << " has_local_transitions" ;
@@ -286,14 +285,15 @@ void DiagnosticsEngine::DiagStateMap::dump(SourceManager &SrcMgr,
286
285
for (DiagStatePoint &Transition : File.StateTransitions ) {
287
286
bool PrintedInnerHeading = false ;
288
287
auto PrintInnerHeading = [&] {
289
- if (PrintedInnerHeading) return ;
288
+ if (PrintedInnerHeading)
289
+ return ;
290
290
PrintedInnerHeading = true ;
291
291
292
292
PrintOuterHeading ();
293
293
llvm::errs () << " " ;
294
294
SrcMgr.getLocForStartOfFile (ID)
295
- .getLocWithOffset (Transition.Offset )
296
- .print (llvm::errs (), SrcMgr);
295
+ .getLocWithOffset (Transition.Offset )
296
+ .print (llvm::errs (), SrcMgr);
297
297
llvm::errs () << " : state " << Transition.State << " :\n " ;
298
298
};
299
299
@@ -316,11 +316,21 @@ void DiagnosticsEngine::DiagStateMap::dump(SourceManager &SrcMgr,
316
316
llvm::errs () << " : " ;
317
317
318
318
switch (Mapping.second .getSeverity ()) {
319
- case diag::Severity::Ignored: llvm::errs () << " ignored" ; break ;
320
- case diag::Severity::Remark: llvm::errs () << " remark" ; break ;
321
- case diag::Severity::Warning: llvm::errs () << " warning" ; break ;
322
- case diag::Severity::Error: llvm::errs () << " error" ; break ;
323
- case diag::Severity::Fatal: llvm::errs () << " fatal" ; break ;
319
+ case diag::Severity::Ignored:
320
+ llvm::errs () << " ignored" ;
321
+ break ;
322
+ case diag::Severity::Remark:
323
+ llvm::errs () << " remark" ;
324
+ break ;
325
+ case diag::Severity::Warning:
326
+ llvm::errs () << " warning" ;
327
+ break ;
328
+ case diag::Severity::Error:
329
+ llvm::errs () << " error" ;
330
+ break ;
331
+ case diag::Severity::Fatal:
332
+ llvm::errs () << " fatal" ;
333
+ break ;
324
334
}
325
335
326
336
if (!Mapping.second .isUser ())
@@ -533,24 +543,28 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
533
543
// Drop the default section introduced by special case list, we only support
534
544
// exact diagnostic group names.
535
545
// FIXME: We should make this configurable in the parser instead.
536
- Sections.erase (" *" );
546
+ // FIXME: C++20 can use std::erase_if(Sections, [](Section &sec) { return
547
+ // sec.SectionStr == "*"; });
548
+ Sections.erase (
549
+ std::remove_if (Sections.begin (), Sections.end (),
550
+ [](Section &sec) { return sec.SectionStr == " *" ; }),
551
+ Sections.end ());
537
552
// Make sure we iterate sections by their line numbers.
538
- std::vector<std::pair<unsigned , const llvm::StringMapEntry<Section> *>>
539
- LineAndSectionEntry;
553
+ std::vector<std::pair<unsigned , const Section *>> LineAndSectionEntry;
540
554
LineAndSectionEntry.reserve (Sections.size ());
541
555
for (const auto &Entry : Sections) {
542
- StringRef DiagName = Entry.getKey () ;
556
+ StringRef DiagName = Entry.SectionStr ;
543
557
// Each section has a matcher with that section's name, attached to that
544
558
// line.
545
- const auto &DiagSectionMatcher = Entry.getValue (). SectionMatcher ;
559
+ const auto &DiagSectionMatcher = Entry.SectionMatcher ;
546
560
unsigned DiagLine = DiagSectionMatcher->Globs .at (DiagName).second ;
547
561
LineAndSectionEntry.emplace_back (DiagLine, &Entry);
548
562
}
549
563
llvm::sort (LineAndSectionEntry);
550
564
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
551
565
for (const auto &[_, SectionEntry] : LineAndSectionEntry) {
552
566
SmallVector<diag::kind> GroupDiags;
553
- StringRef DiagGroup = SectionEntry->getKey () ;
567
+ StringRef DiagGroup = SectionEntry->SectionStr ;
554
568
if (Diags.getDiagnosticIDs ()->getDiagnosticsInGroup (
555
569
WarningFlavor, DiagGroup, GroupDiags)) {
556
570
StringRef Suggestion =
@@ -563,7 +577,7 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
563
577
for (diag::kind Diag : GroupDiags)
564
578
// We're intentionally overwriting any previous mappings here to make sure
565
579
// latest one takes precedence.
566
- DiagToSection[Diag] = & SectionEntry-> getValue () ;
580
+ DiagToSection[Diag] = SectionEntry;
567
581
}
568
582
}
569
583
@@ -662,8 +676,8 @@ bool DiagnosticsEngine::EmitDiagnostic(const DiagnosticBuilder &DB,
662
676
Diagnostic Info (this , DB);
663
677
664
678
// Figure out the diagnostic level of this message.
665
- DiagnosticIDs::Level DiagLevel
666
- = Diags->getDiagnosticLevel (Info.getID (), Info.getLocation (), *this );
679
+ DiagnosticIDs::Level DiagLevel =
680
+ Diags->getDiagnosticLevel (Info.getID (), Info.getLocation (), *this );
667
681
668
682
Emitted = (DiagLevel != DiagnosticIDs::Ignored);
669
683
if (Emitted) {
@@ -715,7 +729,7 @@ Diagnostic::Diagnostic(const DiagnosticsEngine *DO, SourceLocation DiagLoc,
715
729
DiagnosticConsumer::~DiagnosticConsumer () = default ;
716
730
717
731
void DiagnosticConsumer::HandleDiagnostic (DiagnosticsEngine::Level DiagLevel,
718
- const Diagnostic &Info) {
732
+ const Diagnostic &Info) {
719
733
if (!IncludeInDiagnosticCounts ())
720
734
return ;
721
735
@@ -729,28 +743,33 @@ void DiagnosticConsumer::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
729
743
template <std::size_t StrLen>
730
744
static bool ModifierIs (const char *Modifier, unsigned ModifierLen,
731
745
const char (&Str)[StrLen]) {
732
- return StrLen- 1 == ModifierLen && memcmp (Modifier, Str, StrLen- 1 ) == 0 ;
746
+ return StrLen - 1 == ModifierLen && memcmp (Modifier, Str, StrLen - 1 ) == 0 ;
733
747
}
734
748
735
749
// / ScanForward - Scans forward, looking for the given character, skipping
736
750
// / nested clauses and escaped characters.
737
751
static const char *ScanFormat (const char *I, const char *E, char Target) {
738
752
unsigned Depth = 0 ;
739
753
740
- for ( ; I != E; ++I) {
741
- if (Depth == 0 && *I == Target) return I;
742
- if (Depth != 0 && *I == ' }' ) Depth--;
754
+ for (; I != E; ++I) {
755
+ if (Depth == 0 && *I == Target)
756
+ return I;
757
+ if (Depth != 0 && *I == ' }' )
758
+ Depth--;
743
759
744
760
if (*I == ' %' ) {
745
761
I++;
746
- if (I == E) break ;
762
+ if (I == E)
763
+ break ;
747
764
748
765
// Escaped characters get implicitly skipped here.
749
766
750
767
// Format specifier.
751
768
if (!isDigit (*I) && !isPunctuation (*I)) {
752
- for (I++; I != E && !isDigit (*I) && *I != ' {' ; I++) ;
753
- if (I == E) break ;
769
+ for (I++; I != E && !isDigit (*I) && *I != ' {' ; I++)
770
+ ;
771
+ if (I == E)
772
+ break ;
754
773
if (*I == ' {' )
755
774
Depth++;
756
775
}
@@ -767,14 +786,15 @@ static const char *ScanFormat(const char *I, const char *E, char Target) {
767
786
static void HandleSelectModifier (const Diagnostic &DInfo, unsigned ValNo,
768
787
const char *Argument, unsigned ArgumentLen,
769
788
SmallVectorImpl<char > &OutStr) {
770
- const char *ArgumentEnd = Argument+ ArgumentLen;
789
+ const char *ArgumentEnd = Argument + ArgumentLen;
771
790
772
791
// Skip over 'ValNo' |'s.
773
792
while (ValNo) {
774
793
const char *NextVal = ScanFormat (Argument, ArgumentEnd, ' |' );
775
- assert (NextVal != ArgumentEnd && " Value for integer select modifier was"
794
+ assert (NextVal != ArgumentEnd &&
795
+ " Value for integer select modifier was"
776
796
" larger than the number of options in the diagnostic string!" );
777
- Argument = NextVal+ 1 ; // Skip this string.
797
+ Argument = NextVal + 1 ; // Skip this string.
778
798
--ValNo;
779
799
}
780
800
@@ -973,15 +993,13 @@ static const char *getTokenDescForDiagnostic(tok::TokenKind Kind) {
973
993
// / FormatDiagnostic - Format this diagnostic into a string, substituting the
974
994
// / formal arguments into the %0 slots. The result is appended onto the Str
975
995
// / array.
976
- void Diagnostic::
977
- FormatDiagnostic (SmallVectorImpl<char > &OutStr) const {
996
+ void Diagnostic::FormatDiagnostic (SmallVectorImpl<char > &OutStr) const {
978
997
if (StoredDiagMessage.has_value ()) {
979
998
OutStr.append (StoredDiagMessage->begin (), StoredDiagMessage->end ());
980
999
return ;
981
1000
}
982
1001
983
- StringRef Diag =
984
- getDiags ()->getDiagnosticIDs ()->getDescription (getID ());
1002
+ StringRef Diag = getDiags ()->getDiagnosticIDs ()->getDescription (getID ());
985
1003
986
1004
FormatDiagnostic (Diag.begin (), Diag.end (), OutStr);
987
1005
}
@@ -1031,9 +1049,8 @@ void clang::EscapeStringForDiagnostic(StringRef Str,
1031
1049
}
1032
1050
}
1033
1051
1034
- void Diagnostic::
1035
- FormatDiagnostic (const char *DiagStr, const char *DiagEnd,
1036
- SmallVectorImpl<char > &OutStr) const {
1052
+ void Diagnostic::FormatDiagnostic (const char *DiagStr, const char *DiagEnd,
1053
+ SmallVectorImpl<char > &OutStr) const {
1037
1054
// When the diagnostic string is only "%0", the entire string is being given
1038
1055
// by an outside source. Remove unprintable characters from this string
1039
1056
// and skip all the other string processing.
@@ -1067,7 +1084,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1067
1084
DiagStr = StrEnd;
1068
1085
continue ;
1069
1086
} else if (isPunctuation (DiagStr[1 ])) {
1070
- OutStr.push_back (DiagStr[1 ]); // %% -> %.
1087
+ OutStr.push_back (DiagStr[1 ]); // %% -> %.
1071
1088
DiagStr += 2 ;
1072
1089
continue ;
1073
1090
}
@@ -1086,10 +1103,9 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1086
1103
// Check to see if we have a modifier. If so eat it.
1087
1104
if (!isDigit (DiagStr[0 ])) {
1088
1105
Modifier = DiagStr;
1089
- while (DiagStr[0 ] == ' -' ||
1090
- (DiagStr[0 ] >= ' a' && DiagStr[0 ] <= ' z' ))
1106
+ while (DiagStr[0 ] == ' -' || (DiagStr[0 ] >= ' a' && DiagStr[0 ] <= ' z' ))
1091
1107
++DiagStr;
1092
- ModifierLen = DiagStr- Modifier;
1108
+ ModifierLen = DiagStr - Modifier;
1093
1109
1094
1110
// If we have an argument, get it next.
1095
1111
if (DiagStr[0 ] == ' {' ) {
@@ -1098,8 +1114,8 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1098
1114
1099
1115
DiagStr = ScanFormat (DiagStr, DiagEnd, ' }' );
1100
1116
assert (DiagStr != DiagEnd && " Mismatched {}'s in diagnostic string!" );
1101
- ArgumentLen = DiagStr- Argument;
1102
- ++DiagStr; // Skip }.
1117
+ ArgumentLen = DiagStr - Argument;
1118
+ ++DiagStr; // Skip }.
1103
1119
}
1104
1120
}
1105
1121
@@ -1113,7 +1129,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1113
1129
if (ModifierIs (Modifier, ModifierLen, " diff" )) {
1114
1130
assert (*DiagStr == ' ,' && isDigit (*(DiagStr + 1 )) &&
1115
1131
" Invalid format for diff modifier" );
1116
- ++DiagStr; // Comma.
1132
+ ++DiagStr; // Comma.
1117
1133
ArgNo2 = *DiagStr++ - ' 0' ;
1118
1134
DiagnosticsEngine::ArgumentKind Kind2 = getArgKind (ArgNo2);
1119
1135
if (Kind == DiagnosticsEngine::ak_qualtype &&
@@ -1131,8 +1147,8 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1131
1147
" Found too many '|'s in a %diff modifier!" );
1132
1148
const char *FirstDollar = ScanFormat (Argument, Pipe, ' $' );
1133
1149
const char *SecondDollar = ScanFormat (FirstDollar + 1 , Pipe, ' $' );
1134
- const char ArgStr1[] = { ' %' , static_cast <char >(' 0' + ArgNo) };
1135
- const char ArgStr2[] = { ' %' , static_cast <char >(' 0' + ArgNo2) };
1150
+ const char ArgStr1[] = {' %' , static_cast <char >(' 0' + ArgNo)};
1151
+ const char ArgStr2[] = {' %' , static_cast <char >(' 0' + ArgNo2)};
1136
1152
FormatDiagnostic (Argument, FirstDollar, OutStr);
1137
1153
FormatDiagnostic (ArgStr1, ArgStr1 + 2 , OutStr);
1138
1154
FormatDiagnostic (FirstDollar + 1 , SecondDollar, OutStr);
@@ -1256,8 +1272,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1256
1272
getDiags ()->ConvertArgToString (Kind, getRawArg (ArgNo),
1257
1273
StringRef (Modifier, ModifierLen),
1258
1274
StringRef (Argument, ArgumentLen),
1259
- FormattedArgs,
1260
- OutStr, QualTypeVals);
1275
+ FormattedArgs, OutStr, QualTypeVals);
1261
1276
break ;
1262
1277
case DiagnosticsEngine::ak_qualtype_pair: {
1263
1278
// Create a struct with all the info needed for printing.
@@ -1280,8 +1295,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1280
1295
getDiags ()->ConvertArgToString (Kind, val,
1281
1296
StringRef (Modifier, ModifierLen),
1282
1297
StringRef (Argument, ArgumentLen),
1283
- FormattedArgs,
1284
- Tree, QualTypeVals);
1298
+ FormattedArgs, Tree, QualTypeVals);
1285
1299
// If there is no tree information, fall back to regular printing.
1286
1300
if (!Tree.empty ()) {
1287
1301
FormatDiagnostic (Pipe + 1 , ArgumentEnd, OutStr);
@@ -1303,11 +1317,10 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1303
1317
getDiags ()->ConvertArgToString (Kind, val,
1304
1318
StringRef (Modifier, ModifierLen),
1305
1319
StringRef (Argument, ArgumentLen),
1306
- FormattedArgs,
1307
- OutStr, QualTypeVals);
1320
+ FormattedArgs, OutStr, QualTypeVals);
1308
1321
if (!TDT.TemplateDiffUsed )
1309
- FormattedArgs.push_back (std::make_pair (DiagnosticsEngine::ak_qualtype,
1310
- TDT.FromType ));
1322
+ FormattedArgs.push_back (
1323
+ std::make_pair (DiagnosticsEngine::ak_qualtype, TDT.FromType ));
1311
1324
1312
1325
// Append middle text
1313
1326
FormatDiagnostic (FirstDollar + 1 , SecondDollar, OutStr);
@@ -1317,11 +1330,10 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1317
1330
getDiags ()->ConvertArgToString (Kind, val,
1318
1331
StringRef (Modifier, ModifierLen),
1319
1332
StringRef (Argument, ArgumentLen),
1320
- FormattedArgs,
1321
- OutStr, QualTypeVals);
1333
+ FormattedArgs, OutStr, QualTypeVals);
1322
1334
if (!TDT.TemplateDiffUsed )
1323
- FormattedArgs.push_back (std::make_pair (DiagnosticsEngine::ak_qualtype,
1324
- TDT.ToType ));
1335
+ FormattedArgs.push_back (
1336
+ std::make_pair (DiagnosticsEngine::ak_qualtype, TDT.ToType ));
1325
1337
1326
1338
// Append end text
1327
1339
FormatDiagnostic (SecondDollar + 1 , Pipe, OutStr);
@@ -1337,8 +1349,9 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1337
1349
else if (Kind != DiagnosticsEngine::ak_std_string)
1338
1350
FormattedArgs.push_back (std::make_pair (Kind, getRawArg (ArgNo)));
1339
1351
else
1340
- FormattedArgs.push_back (std::make_pair (DiagnosticsEngine::ak_c_string,
1341
- (intptr_t )getArgStdStr (ArgNo).c_str ()));
1352
+ FormattedArgs.push_back (
1353
+ std::make_pair (DiagnosticsEngine::ak_c_string,
1354
+ (intptr_t )getArgStdStr (ArgNo).c_str ()));
1342
1355
}
1343
1356
1344
1357
// Append the type tree to the end of the diagnostics.
@@ -1352,8 +1365,9 @@ StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
1352
1365
StoredDiagnostic::StoredDiagnostic (DiagnosticsEngine::Level Level,
1353
1366
const Diagnostic &Info)
1354
1367
: ID(Info.getID()), Level(Level) {
1355
- assert ((Info.getLocation ().isInvalid () || Info.hasSourceManager ()) &&
1356
- " Valid source location without setting a source manager for diagnostic" );
1368
+ assert (
1369
+ (Info.getLocation ().isInvalid () || Info.hasSourceManager ()) &&
1370
+ " Valid source location without setting a source manager for diagnostic" );
1357
1371
if (Info.getLocation ().isValid ())
1358
1372
Loc = FullSourceLoc (Info.getLocation (), Info.getSourceManager ());
1359
1373
SmallString<64 > Message;
@@ -1368,9 +1382,8 @@ StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
1368
1382
ArrayRef<CharSourceRange> Ranges,
1369
1383
ArrayRef<FixItHint> FixIts)
1370
1384
: ID(ID), Level(Level), Loc(Loc), Message(Message),
1371
- Ranges(Ranges.begin(), Ranges.end()), FixIts(FixIts.begin(), FixIts.end())
1372
- {
1373
- }
1385
+ Ranges(Ranges.begin(), Ranges.end()),
1386
+ FixIts(FixIts.begin(), FixIts.end()) {}
1374
1387
1375
1388
llvm::raw_ostream &clang::operator <<(llvm::raw_ostream &OS,
1376
1389
const StoredDiagnostic &SD) {
@@ -1391,8 +1404,7 @@ void IgnoringDiagConsumer::anchor() {}
1391
1404
ForwardingDiagnosticConsumer::~ForwardingDiagnosticConsumer () = default ;
1392
1405
1393
1406
void ForwardingDiagnosticConsumer::HandleDiagnostic (
1394
- DiagnosticsEngine::Level DiagLevel,
1395
- const Diagnostic &Info) {
1407
+ DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) {
1396
1408
Target.HandleDiagnostic (DiagLevel, Info);
1397
1409
}
1398
1410
0 commit comments