Skip to content

Commit 65a2de7

Browse files
author
Georgii Rymar
committed
[FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix.
Imagine we have the following invocation: `FileCheck -check-prefix=UNKNOWN-PREFIX -implicit-check-not=something` When the check prefix does not exist it does not fail. This patch fixes the issue. Differential revision: https://reviews.llvm.org/D78024
1 parent cee80c0 commit 65a2de7

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsanitize=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-recover=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_implicit_conversion" --check-prefixes=CHECK
1+
// RUN: %clang_cc1 -fsanitize=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-recover=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_implicit_conversion"
22

33
// If we have an enum, it will be promoted to an unsigned integer.
44
// But both types are unsigned, and have same bitwidth.

llvm/include/llvm/Support/FileCheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct FileCheckRequest {
3131
bool AllowEmptyInput = false;
3232
bool MatchFullLines = false;
3333
bool IgnoreCase = false;
34+
bool IsDefaultCheckPrefix = false;
3435
bool EnableVarScope = false;
3536
bool AllowDeprecatedDagOverlap = false;
3637
bool Verbose = false;

llvm/lib/Support/FileCheck.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,7 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
13051305
// found.
13061306
unsigned LineNumber = 1;
13071307

1308+
bool FoundUsedPrefix = false;
13081309
while (1) {
13091310
Check::FileCheckType CheckTy;
13101311

@@ -1315,6 +1316,8 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
13151316
FindFirstMatchingPrefix(PrefixRE, Buffer, LineNumber, CheckTy);
13161317
if (UsedPrefix.empty())
13171318
break;
1319+
FoundUsedPrefix = true;
1320+
13181321
assert(UsedPrefix.data() == Buffer.data() &&
13191322
"Failed to move Buffer's start forward, or pointed prefix outside "
13201323
"of the buffer!");
@@ -1398,16 +1401,10 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
13981401
DagNotMatches = ImplicitNegativeChecks;
13991402
}
14001403

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)) {
14111408
errs() << "error: no check strings found with prefix"
14121409
<< (Req.CheckPrefixes.size() > 1 ? "es " : " ");
14131410
auto I = Req.CheckPrefixes.begin();
@@ -1423,6 +1420,15 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
14231420
return true;
14241421
}
14251422

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+
14261432
return false;
14271433
}
14281434

@@ -1888,8 +1894,10 @@ bool FileCheck::ValidateCheckPrefixes() {
18881894
Regex FileCheck::buildCheckPrefixRegex() {
18891895
// I don't think there's a way to specify an initial value for cl::list,
18901896
// so if nothing was specified, add the default
1891-
if (Req.CheckPrefixes.empty())
1897+
if (Req.CheckPrefixes.empty()) {
18921898
Req.CheckPrefixes.push_back("CHECK");
1899+
Req.IsDefaultCheckPrefix = true;
1900+
}
18931901

18941902
// We already validated the contents of CheckPrefixes so just concatenate
18951903
// them as alternatives.

llvm/test/FileCheck/implicit-check-not.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
; RUN: sed 's#^;.*##' %s | FileCheck -check-prefix=CHECK-PASS -implicit-check-not=warning: %s
2+
3+
; Check we report an error when an unknown prefix is used together with `-implicit-check-not`.
4+
; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=UNKNOWN-PREFIX -implicit-check-not=abc %s 2>&1 | FileCheck %s -DPREFIX=UNKNOWN-PREFIX -check-prefix CHECK-PREFIX-ERROR
5+
; CHECK-PREFIX-ERROR: error: no check strings found with prefix '[[PREFIX]]:'
6+
7+
; Check we report an error when the "CHECK" prefix is used explicitly with `-implicit-check-not`, but not present in the input.
8+
; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK -implicit-check-not=abc %s 2>&1 | FileCheck %s -DPREFIX=CHECK -check-prefix CHECK-PREFIX-ERROR
9+
10+
; Check we allow using `-implicit-check-not` when there is no `-check-prefix` specified and there
11+
; is no default `CHECK` line in an input.
12+
; RUN: sed 's#^;.*##' %s | FileCheck -implicit-check-not="unique_string" %s
13+
214
; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL1 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR1
315
; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL2 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR2
416
; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL3 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR3

llvm/test/tools/llvm-objcopy/MachO/strip-debug.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# RUN: yaml2obj %p/Inputs/strip-all-with-dwarf.yaml -o %t
44

55
# RUN: llvm-objcopy --strip-debug %t %t.stripped
6-
# RUN: llvm-readobj --sections %t.stripped | FileCheck /dev/null --check-prefix=NODWARF \
6+
# RUN: llvm-readobj --sections %t.stripped | FileCheck /dev/null \
77
# RUN: --implicit-check-not='Name: __debug' --implicit-check-not='Name: __apple'
88

99
## Make sure that all symbols are kept.

0 commit comments

Comments
 (0)