[PATCH] D78024: [FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 09:07:03 PDT 2020


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay, thopre, probinson.
Herald added subscribers: hiraditya, arichardson.
Herald added a reviewer: alexshap.
Herald added a reviewer: rupprecht.

Imagine we have the following invocation:

`FileCheck -check-prefix=UNKNOWN-PREFIX -implicit-check-not=something`

When the check prefix does not exist I'd expect it to fail, but it does not.

This patch fixes the issue.


https://reviews.llvm.org/D78024

Files:
  llvm/lib/Support/FileCheck.cpp
  llvm/test/FileCheck/implicit-check-not.txt
  llvm/test/tools/llvm-objcopy/MachO/strip-debug.test


Index: llvm/test/tools/llvm-objcopy/MachO/strip-debug.test
===================================================================
--- llvm/test/tools/llvm-objcopy/MachO/strip-debug.test
+++ 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.
Index: llvm/test/FileCheck/implicit-check-not.txt
===================================================================
--- llvm/test/FileCheck/implicit-check-not.txt
+++ llvm/test/FileCheck/implicit-check-not.txt
@@ -1,4 +1,14 @@
 ; 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 | not FileCheck -check-prefix=UNKNOWN-PREFIX -implicit-check-not=abc %s 2>&1 | FileCheck %s -check-prefix CHECK-PREFIX-ERROR
+; CHECK-PREFIX-ERROR: error: no check strings found with prefix 'UNKNOWN-PREFIX:'
+
+; Check we allow using `-implicit-check-not` when there is no `-check-prefix` specified and there
+; is no default `CHECK` line in an input. Use an arbitrary random unique string as an
+; argument for `-implicit-check-not`.
+; RUN: sed 's#^;.*##' %s | FileCheck -implicit-check-not="c9e72085-aade-469a-9ad7-c206e1cfe7a9" %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
Index: llvm/lib/Support/FileCheck.cpp
===================================================================
--- llvm/lib/Support/FileCheck.cpp
+++ llvm/lib/Support/FileCheck.cpp
@@ -1274,6 +1274,7 @@
   // found.
   unsigned LineNumber = 1;
 
+  bool FoundPrefix = false;
   while (1) {
     Check::FileCheckType CheckTy;
 
@@ -1284,6 +1285,8 @@
         FindFirstMatchingPrefix(PrefixRE, Buffer, LineNumber, CheckTy);
     if (UsedPrefix.empty())
       break;
+    FoundPrefix = true;
+
     assert(UsedPrefix.data() == Buffer.data() &&
            "Failed to move Buffer's start forward, or pointed prefix outside "
            "of the buffer!");
@@ -1367,9 +1370,13 @@
     DagNotMatches = ImplicitNegativeChecks;
   }
 
-  // Add an EOF pattern for any trailing CHECK-DAG/-NOTs, and use the first
-  // prefix as a filler for the error message.
-  if (!DagNotMatches.empty()) {
+  // 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.
+  // We do not allow using -implicit-check-not when an explicitly specified
+  // check prefix is not present in the input buffer.
+  bool IsDefaultPrefix =
+      Req.CheckPrefixes.size() == 1 && Req.CheckPrefixes[0] == "CHECK";
+  if ((IsDefaultPrefix || FoundPrefix) && !DagNotMatches.empty()) {
     CheckStrings->emplace_back(
         Pattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1),
         *Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78024.256986.patch
Type: text/x-patch
Size: 3657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200413/90e7c234/attachment.bin>


More information about the llvm-commits mailing list