@@ -89,9 +89,10 @@ namespace {
89
89
class StandardDirective : public Directive {
90
90
public:
91
91
StandardDirective (SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc,
92
- bool MatchAnyLine, StringRef Text, unsigned Min,
93
- unsigned Max)
94
- : Directive(DirectiveLoc, DiagnosticLoc, MatchAnyLine, Text, Min, Max) {}
92
+ bool MatchAnyFileAndLine, bool MatchAnyLine, StringRef Text,
93
+ unsigned Min, unsigned Max)
94
+ : Directive(DirectiveLoc, DiagnosticLoc, MatchAnyFileAndLine,
95
+ MatchAnyLine, Text, Min, Max) {}
95
96
96
97
bool isValid (std::string &Error) override {
97
98
// all strings are considered valid; even empty ones
@@ -107,9 +108,10 @@ class StandardDirective : public Directive {
107
108
class RegexDirective : public Directive {
108
109
public:
109
110
RegexDirective (SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc,
110
- bool MatchAnyLine, StringRef Text, unsigned Min, unsigned Max,
111
- StringRef RegexStr)
112
- : Directive(DirectiveLoc, DiagnosticLoc, MatchAnyLine, Text, Min, Max),
111
+ bool MatchAnyFileAndLine, bool MatchAnyLine, StringRef Text,
112
+ unsigned Min, unsigned Max, StringRef RegexStr)
113
+ : Directive(DirectiveLoc, DiagnosticLoc, MatchAnyFileAndLine,
114
+ MatchAnyLine, Text, Min, Max),
113
115
Regex (RegexStr) {}
114
116
115
117
bool isValid (std::string &Error) override {
@@ -294,11 +296,13 @@ struct UnattachedDirective {
294
296
// Attach the specified directive to the line of code indicated by
295
297
// \p ExpectedLoc.
296
298
void attachDirective (DiagnosticsEngine &Diags, const UnattachedDirective &UD,
297
- SourceLocation ExpectedLoc, bool MatchAnyLine = false ) {
299
+ SourceLocation ExpectedLoc,
300
+ bool MatchAnyFileAndLine = false ,
301
+ bool MatchAnyLine = false ) {
298
302
// Construct new directive.
299
- std::unique_ptr<Directive> D =
300
- Directive::create ( UD.RegexKind , UD.DirectivePos , ExpectedLoc,
301
- MatchAnyLine, UD.Text , UD.Min , UD.Max );
303
+ std::unique_ptr<Directive> D = Directive::create (
304
+ UD.RegexKind , UD.DirectivePos , ExpectedLoc, MatchAnyFileAndLine ,
305
+ MatchAnyLine, UD.Text , UD.Min , UD.Max );
302
306
303
307
std::string Error;
304
308
if (!D->isValid (Error)) {
@@ -498,6 +502,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
498
502
// Next optional token: @
499
503
SourceLocation ExpectedLoc;
500
504
StringRef Marker;
505
+ bool MatchAnyFileAndLine = false ;
501
506
bool MatchAnyLine = false ;
502
507
if (!PH.Next (" @" )) {
503
508
ExpectedLoc = Pos;
@@ -526,26 +531,39 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
526
531
StringRef Filename (PH.C , PH.P -PH.C );
527
532
PH.Advance ();
528
533
529
- // Lookup file via Preprocessor, like a #include.
530
- const DirectoryLookup *CurDir;
531
- Optional<FileEntryRef> File =
532
- PP->LookupFile (Pos, Filename, false , nullptr , nullptr , CurDir,
533
- nullptr , nullptr , nullptr , nullptr , nullptr );
534
- if (!File) {
535
- Diags.Report (Pos.getLocWithOffset (PH.C -PH.Begin ),
536
- diag::err_verify_missing_file) << Filename << KindStr;
537
- continue ;
538
- }
539
-
540
- const FileEntry *FE = &File->getFileEntry ();
541
- if (SM.translateFile (FE).isInvalid ())
542
- SM.createFileID (FE, Pos, SrcMgr::C_User);
543
-
544
- if (PH.Next (Line) && Line > 0 )
545
- ExpectedLoc = SM.translateFileLineCol (FE, Line, 1 );
546
- else if (PH.Next (" *" )) {
534
+ if (Filename == " *" ) {
535
+ MatchAnyFileAndLine = true ;
536
+ if (!PH.Next (" *" )) {
537
+ Diags.Report (Pos.getLocWithOffset (PH.C - PH.Begin ),
538
+ diag::err_verify_missing_line)
539
+ << " '*'" ;
540
+ continue ;
541
+ }
547
542
MatchAnyLine = true ;
548
- ExpectedLoc = SM.translateFileLineCol (FE, 1 , 1 );
543
+ ExpectedLoc = SourceLocation ();
544
+ } else {
545
+ // Lookup file via Preprocessor, like a #include.
546
+ const DirectoryLookup *CurDir;
547
+ Optional<FileEntryRef> File =
548
+ PP->LookupFile (Pos, Filename, false , nullptr , nullptr , CurDir,
549
+ nullptr , nullptr , nullptr , nullptr , nullptr );
550
+ if (!File) {
551
+ Diags.Report (Pos.getLocWithOffset (PH.C - PH.Begin ),
552
+ diag::err_verify_missing_file)
553
+ << Filename << KindStr;
554
+ continue ;
555
+ }
556
+
557
+ const FileEntry *FE = &File->getFileEntry ();
558
+ if (SM.translateFile (FE).isInvalid ())
559
+ SM.createFileID (FE, Pos, SrcMgr::C_User);
560
+
561
+ if (PH.Next (Line) && Line > 0 )
562
+ ExpectedLoc = SM.translateFileLineCol (FE, Line, 1 );
563
+ else if (PH.Next (" *" )) {
564
+ MatchAnyLine = true ;
565
+ ExpectedLoc = SM.translateFileLineCol (FE, 1 , 1 );
566
+ }
549
567
}
550
568
} else if (PH.Next (" *" )) {
551
569
MatchAnyLine = true ;
@@ -631,7 +649,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
631
649
}
632
650
633
651
if (Marker.empty ())
634
- attachDirective (Diags, D, ExpectedLoc, MatchAnyLine);
652
+ attachDirective (Diags, D, ExpectedLoc, MatchAnyFileAndLine, MatchAnyLine);
635
653
else
636
654
Markers.addDirective (Marker, D);
637
655
FoundDirective = true ;
@@ -877,7 +895,7 @@ static unsigned PrintExpected(DiagnosticsEngine &Diags,
877
895
SmallString<256 > Fmt;
878
896
llvm::raw_svector_ostream OS (Fmt);
879
897
for (const auto *D : DL) {
880
- if (D->DiagnosticLoc .isInvalid ())
898
+ if (D->DiagnosticLoc .isInvalid () || D-> MatchAnyFileAndLine )
881
899
OS << " \n File *" ;
882
900
else
883
901
OS << " \n File " << SourceMgr.getFilename (D->DiagnosticLoc );
@@ -937,7 +955,7 @@ static unsigned CheckLists(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
937
955
continue ;
938
956
}
939
957
940
- if (!D.DiagnosticLoc .isInvalid () &&
958
+ if (!D.DiagnosticLoc .isInvalid () && !D. MatchAnyFileAndLine &&
941
959
!IsFromSameFile (SourceMgr, D.DiagnosticLoc , II->first ))
942
960
continue ;
943
961
@@ -1114,11 +1132,13 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
1114
1132
std::unique_ptr<Directive> Directive::create (bool RegexKind,
1115
1133
SourceLocation DirectiveLoc,
1116
1134
SourceLocation DiagnosticLoc,
1135
+ bool MatchAnyFileAndLine,
1117
1136
bool MatchAnyLine, StringRef Text,
1118
1137
unsigned Min, unsigned Max) {
1119
1138
if (!RegexKind)
1120
1139
return std::make_unique<StandardDirective>(DirectiveLoc, DiagnosticLoc,
1121
- MatchAnyLine, Text, Min, Max);
1140
+ MatchAnyFileAndLine,
1141
+ MatchAnyLine, Text, Min, Max);
1122
1142
1123
1143
// Parse the directive into a regular expression.
1124
1144
std::string RegexStr;
@@ -1143,6 +1163,7 @@ std::unique_ptr<Directive> Directive::create(bool RegexKind,
1143
1163
}
1144
1164
}
1145
1165
1146
- return std::make_unique<RegexDirective>(
1147
- DirectiveLoc, DiagnosticLoc, MatchAnyLine, Text, Min, Max, RegexStr);
1166
+ return std::make_unique<RegexDirective>(DirectiveLoc, DiagnosticLoc,
1167
+ MatchAnyFileAndLine, MatchAnyLine,
1168
+ Text, Min, Max, RegexStr);
1148
1169
}
0 commit comments