[clang] 65a2de7 - [FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix.
Georgii Rymar via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 05:01:07 PDT 2020
Author: Georgii Rymar
Date: 2020-04-16T15:00:50+03:00
New Revision: 65a2de7e6c986193a630e691686c527b08f292d5
URL: https://github.com/llvm/llvm-project/commit/65a2de7e6c986193a630e691686c527b08f292d5
DIFF: https://github.com/llvm/llvm-project/commit/65a2de7e6c986193a630e691686c527b08f292d5.diff
LOG: [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
Added:
Modified:
clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c
llvm/include/llvm/Support/FileCheck.h
llvm/lib/Support/FileCheck.cpp
llvm/test/FileCheck/implicit-check-not.txt
llvm/test/tools/llvm-objcopy/MachO/strip-debug.test
Removed:
################################################################################
diff --git a/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c b/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c
index 2e060cfcddef..e8f09975a26e 100644
--- a/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c
+++ b/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c
@@ -1,4 +1,4 @@
-// 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
+// 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"
// If we have an enum, it will be promoted to an unsigned integer.
// But both types are unsigned, and have same bitwidth.
diff --git a/llvm/include/llvm/Support/FileCheck.h b/llvm/include/llvm/Support/FileCheck.h
index 429e36cfcbb5..d218ef042257 100644
--- a/llvm/include/llvm/Support/FileCheck.h
+++ b/llvm/include/llvm/Support/FileCheck.h
@@ -31,6 +31,7 @@ struct FileCheckRequest {
bool AllowEmptyInput = false;
bool MatchFullLines = false;
bool IgnoreCase = false;
+ bool IsDefaultCheckPrefix = false;
bool EnableVarScope = false;
bool AllowDeprecatedDagOverlap = false;
bool Verbose = false;
diff --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp
index 0913b97fcdd0..71b1e8356137 100644
--- a/llvm/lib/Support/FileCheck.cpp
+++ b/llvm/lib/Support/FileCheck.cpp
@@ -1305,6 +1305,7 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
// found.
unsigned LineNumber = 1;
+ bool FoundUsedPrefix = false;
while (1) {
Check::FileCheckType CheckTy;
@@ -1315,6 +1316,8 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
FindFirstMatchingPrefix(PrefixRE, Buffer, LineNumber, CheckTy);
if (UsedPrefix.empty())
break;
+ FoundUsedPrefix = true;
+
assert(UsedPrefix.data() == Buffer.data() &&
"Failed to move Buffer's start forward, or pointed prefix outside "
"of the buffer!");
@@ -1398,16 +1401,10 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
DagNotMatches = ImplicitNegativeChecks;
}
- // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs,
- // and use the first prefix as a filler for the error message.
- if (!DagNotMatches.empty()) {
- CheckStrings->emplace_back(
- Pattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1),
- *Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data()));
- std::swap(DagNotMatches, CheckStrings->back().DagNotStrings);
- }
-
- if (CheckStrings->empty()) {
+ // When there are no used prefixes we report an error except in the case that
+ // no prefix is specified explicitly but -implicit-check-not is specified.
+ if (!FoundUsedPrefix &&
+ (ImplicitNegativeChecks.empty() || !Req.IsDefaultCheckPrefix)) {
errs() << "error: no check strings found with prefix"
<< (Req.CheckPrefixes.size() > 1 ? "es " : " ");
auto I = Req.CheckPrefixes.begin();
@@ -1423,6 +1420,15 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
return true;
}
+ // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs,
+ // and use the first prefix as a filler for the error message.
+ if (!DagNotMatches.empty()) {
+ CheckStrings->emplace_back(
+ Pattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1),
+ *Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data()));
+ std::swap(DagNotMatches, CheckStrings->back().DagNotStrings);
+ }
+
return false;
}
@@ -1888,8 +1894,10 @@ bool FileCheck::ValidateCheckPrefixes() {
Regex FileCheck::buildCheckPrefixRegex() {
// I don't think there's a way to specify an initial value for cl::list,
// so if nothing was specified, add the default
- if (Req.CheckPrefixes.empty())
+ if (Req.CheckPrefixes.empty()) {
Req.CheckPrefixes.push_back("CHECK");
+ Req.IsDefaultCheckPrefix = true;
+ }
// We already validated the contents of CheckPrefixes so just concatenate
// them as alternatives.
diff --git a/llvm/test/FileCheck/implicit-check-not.txt b/llvm/test/FileCheck/implicit-check-not.txt
index 3aea712d6506..95dd9fa782df 100644
--- a/llvm/test/FileCheck/implicit-check-not.txt
+++ b/llvm/test/FileCheck/implicit-check-not.txt
@@ -1,4 +1,16 @@
; RUN: sed 's#^;.*##' %s | FileCheck -check-prefix=CHECK-PASS -implicit-check-not=warning: %s
+
+; Check we report an error when an unknown prefix is used together with `-implicit-check-not`.
+; 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
+; CHECK-PREFIX-ERROR: error: no check strings found with prefix '[[PREFIX]]:'
+
+; Check we report an error when the "CHECK" prefix is used explicitly with `-implicit-check-not`, but not present in the input.
+; 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
+
+; Check we allow using `-implicit-check-not` when there is no `-check-prefix` specified and there
+; is no default `CHECK` line in an input.
+; RUN: sed 's#^;.*##' %s | FileCheck -implicit-check-not="unique_string" %s
+
; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL1 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR1
; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL2 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR2
; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL3 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR3
diff --git a/llvm/test/tools/llvm-objcopy/MachO/strip-debug.test b/llvm/test/tools/llvm-objcopy/MachO/strip-debug.test
index ff99b97f1047..817ca0ecb561 100644
--- a/llvm/test/tools/llvm-objcopy/MachO/strip-debug.test
+++ b/llvm/test/tools/llvm-objcopy/MachO/strip-debug.test
@@ -3,7 +3,7 @@
# RUN: yaml2obj %p/Inputs/strip-all-with-dwarf.yaml -o %t
# RUN: llvm-objcopy --strip-debug %t %t.stripped
-# RUN: llvm-readobj --sections %t.stripped | FileCheck /dev/null --check-prefix=NODWARF \
+# RUN: llvm-readobj --sections %t.stripped | FileCheck /dev/null \
# RUN: --implicit-check-not='Name: __debug' --implicit-check-not='Name: __apple'
## Make sure that all symbols are kept.
More information about the cfe-commits
mailing list