From 871d658c9ceb391df34e43d8f7af596c0b8a36df Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Wed, 28 Oct 2020 17:44:13 -0700 Subject: [FileCheck] Report missing prefixes when more than one is provided. If more than a prefix is provided - e.g. --check-prefixes=CHECK,FOO - we don't report if (say) FOO is never used. This may lead to a gap in our test coverage. This patch introduces a new option, --allow-unused-prefixes. It currently is set to true, keeping today's behavior. After we explicitly set it in tests where this behavior was actually intentional, we will switch it to false by default. Differential Revision: https://reviews.llvm.org/D90281 --- llvm/lib/FileCheck/FileCheck.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'llvm/lib/FileCheck/FileCheck.cpp') diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp index a0371cf..8e234b2 100644 --- a/llvm/lib/FileCheck/FileCheck.cpp +++ b/llvm/lib/FileCheck/FileCheck.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/FormatVariadic.h" #include #include +#include #include #include @@ -1825,8 +1826,10 @@ bool FileCheck::readCheckFile( // found. unsigned LineNumber = 1; - bool FoundUsedCheckPrefix = false; - while (1) { + std::set PrefixesNotFound(Req.CheckPrefixes.begin(), + Req.CheckPrefixes.end()); + const size_t DistinctPrefixes = PrefixesNotFound.size(); + while (true) { Check::FileCheckType CheckTy; // See if a prefix occurs in the memory buffer. @@ -1837,7 +1840,7 @@ bool FileCheck::readCheckFile( if (UsedPrefix.empty()) break; if (CheckTy != Check::CheckComment) - FoundUsedCheckPrefix = true; + PrefixesNotFound.erase(UsedPrefix); assert(UsedPrefix.data() == Buffer.data() && "Failed to move Buffer's start forward, or pointed prefix outside " @@ -1930,14 +1933,19 @@ bool FileCheck::readCheckFile( // 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 (!FoundUsedCheckPrefix && + const bool NoPrefixesFound = PrefixesNotFound.size() == DistinctPrefixes; + const bool SomePrefixesUnexpectedlyNotUsed = + !Req.AllowUnusedPrefixes && !PrefixesNotFound.empty(); + if ((NoPrefixesFound || SomePrefixesUnexpectedlyNotUsed) && (ImplicitNegativeChecks.empty() || !Req.IsDefaultCheckPrefix)) { errs() << "error: no check strings found with prefix" - << (Req.CheckPrefixes.size() > 1 ? "es " : " "); - for (size_t I = 0, E = Req.CheckPrefixes.size(); I != E; ++I) { - if (I != 0) + << (PrefixesNotFound.size() > 1 ? "es " : " "); + bool First = true; + for (StringRef MissingPrefix : PrefixesNotFound) { + if (!First) errs() << ", "; - errs() << "\'" << Req.CheckPrefixes[I] << ":'"; + errs() << "\'" << MissingPrefix << ":'"; + First = false; } errs() << '\n'; return true; -- cgit v1.1