Index: lib/Support/FileCheck.cpp =================================================================== --- lib/Support/FileCheck.cpp +++ lib/Support/FileCheck.cpp @@ -737,6 +737,8 @@ // LineNumber keeps track of the line on which CheckPrefix instances are // found. unsigned LineNumber = 1; + bool HasNonLabelPrefix = false; + StringRef MatchedPrefix; while (1) { Check::FileCheckType CheckTy; @@ -746,6 +748,7 @@ CheckTy); if (UsedPrefix.empty()) break; + MatchedPrefix = UsedPrefix; assert(UsedPrefix.data() == Buffer.data() && "Failed to move Buffer's start forward, or pointed prefix outside " "of the buffer!"); @@ -763,8 +766,11 @@ return true; } - // Okay, we found the prefix, yay. Remember the rest of the line, but ignore - // leading whitespace. + // Okay, we found the prefix, yay. + if (CheckTy != Check::CheckLabel) + HasNonLabelPrefix = true; + + // Remember the rest of the line, but ignore leading whitespace. if (!(Req.NoCanonicalizeWhiteSpace && Req.MatchFullLines)) Buffer = Buffer.substr(Buffer.find_first_not_of(" \t")); @@ -840,6 +846,12 @@ return true; } + if (!HasNonLabelPrefix) + SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), + SourceMgr::DK_Warning, + "Prefix " + MatchedPrefix + " only occurs in a LABEL check, " + "this is probably not what you want."); + return false; } Index: test/FileCheck/check-prefixes-only-labels.txt =================================================================== --- /dev/null +++ test/FileCheck/check-prefixes-only-labels.txt @@ -0,0 +1,6 @@ +// RUN: FileCheck -check-prefix=FOO -input-file %s %s 2>&1 | FileCheck -check-prefix=WARNING %s + +foo +; FOO-LABEL: foo + +; WARNING: warning: Prefix FOO only occurs in a LABEL check, this is probably not what you want. Index: test/FileCheck/check-prefixes-only-labels2.txt =================================================================== --- /dev/null +++ test/FileCheck/check-prefixes-only-labels2.txt @@ -0,0 +1,13 @@ +// RUN: FileCheck -vv -check-prefixes=FOO,BAR -input-file %s %s 2>&1 | FileCheck -check-prefix=DONTWARN %s + +; Prefix FOO is only checked as a label check, but BAR is checked, that's why we +; shouldn't produce a diagnostic that there is a prefix only used in label checks: +; +; DONTWARN-NOT: warning: Prefix {{.*}} only occurs in a LABEL check, this is probably not what you want. + +foo +; FOO-LABEL: foo + +bar +; BAR: bar + Index: test/FileCheck/check-prefixes-only-labels3.txt =================================================================== --- /dev/null +++ test/FileCheck/check-prefixes-only-labels3.txt @@ -0,0 +1,11 @@ +// RUN: FileCheck -vv -check-prefix=FOO -input-file %s %s 2>&1 | FileCheck -check-prefix=DONTWARN %s + +; This is a very normal test, so make sure we don't complain about it: +; +; DONTWARN-NOT: warning: Prefix FOO only occurs in a LABEL check, this is probably not what you want. +foo +bar + +; FOO-LABEL: foo +; FOO: bar +