@@ -1305,6 +1305,7 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
1305
1305
// found.
1306
1306
unsigned LineNumber = 1 ;
1307
1307
1308
+ bool FoundUsedPrefix = false ;
1308
1309
while (1 ) {
1309
1310
Check::FileCheckType CheckTy;
1310
1311
@@ -1315,6 +1316,8 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
1315
1316
FindFirstMatchingPrefix (PrefixRE, Buffer, LineNumber, CheckTy);
1316
1317
if (UsedPrefix.empty ())
1317
1318
break ;
1319
+ FoundUsedPrefix = true ;
1320
+
1318
1321
assert (UsedPrefix.data () == Buffer.data () &&
1319
1322
" Failed to move Buffer's start forward, or pointed prefix outside "
1320
1323
" of the buffer!" );
@@ -1398,16 +1401,10 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
1398
1401
DagNotMatches = ImplicitNegativeChecks;
1399
1402
}
1400
1403
1401
- // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs,
1402
- // and use the first prefix as a filler for the error message.
1403
- if (!DagNotMatches.empty ()) {
1404
- CheckStrings->emplace_back (
1405
- Pattern (Check::CheckEOF, PatternContext.get (), LineNumber + 1 ),
1406
- *Req.CheckPrefixes .begin (), SMLoc::getFromPointer (Buffer.data ()));
1407
- std::swap (DagNotMatches, CheckStrings->back ().DagNotStrings );
1408
- }
1409
-
1410
- if (CheckStrings->empty ()) {
1404
+ // When there are no used prefixes we report an error except in the case that
1405
+ // no prefix is specified explicitly but -implicit-check-not is specified.
1406
+ if (!FoundUsedPrefix &&
1407
+ (ImplicitNegativeChecks.empty () || !Req.IsDefaultCheckPrefix )) {
1411
1408
errs () << " error: no check strings found with prefix"
1412
1409
<< (Req.CheckPrefixes .size () > 1 ? " es " : " " );
1413
1410
auto I = Req.CheckPrefixes .begin ();
@@ -1423,6 +1420,15 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
1423
1420
return true ;
1424
1421
}
1425
1422
1423
+ // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs,
1424
+ // and use the first prefix as a filler for the error message.
1425
+ if (!DagNotMatches.empty ()) {
1426
+ CheckStrings->emplace_back (
1427
+ Pattern (Check::CheckEOF, PatternContext.get (), LineNumber + 1 ),
1428
+ *Req.CheckPrefixes .begin (), SMLoc::getFromPointer (Buffer.data ()));
1429
+ std::swap (DagNotMatches, CheckStrings->back ().DagNotStrings );
1430
+ }
1431
+
1426
1432
return false ;
1427
1433
}
1428
1434
@@ -1888,8 +1894,10 @@ bool FileCheck::ValidateCheckPrefixes() {
1888
1894
Regex FileCheck::buildCheckPrefixRegex () {
1889
1895
// I don't think there's a way to specify an initial value for cl::list,
1890
1896
// so if nothing was specified, add the default
1891
- if (Req.CheckPrefixes .empty ())
1897
+ if (Req.CheckPrefixes .empty ()) {
1892
1898
Req.CheckPrefixes .push_back (" CHECK" );
1899
+ Req.IsDefaultCheckPrefix = true ;
1900
+ }
1893
1901
1894
1902
// We already validated the contents of CheckPrefixes so just concatenate
1895
1903
// them as alternatives.
0 commit comments