[llvm] r205725 - When a CHECK-NEXT fails because there was no match on the next line, include

David Blaikie dblaikie at gmail.com
Mon Apr 7 10:41:20 PDT 2014


On Mon, Apr 7, 2014 at 10:09 AM, Richard Smith
<richard-llvm at metafoo.co.uk> wrote:
> Author: rsmith
> Date: Mon Apr  7 12:09:53 2014
> New Revision: 205725
>
> URL: http://llvm.org/viewvc/llvm-project?rev=205725&view=rev
> Log:
> When a CHECK-NEXT fails because there was no match on the next line, include
> the non-matching next line in the diagnostic to make the problem more obvious.

Excellent!

Any chance of a test case? (we have a few in llvm/test/FileCheck)

>
> Modified:
>     llvm/trunk/utils/FileCheck/FileCheck.cpp
>
> Modified: llvm/trunk/utils/FileCheck/FileCheck.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileCheck/FileCheck.cpp?rev=205725&r1=205724&r2=205725&view=diff
> ==============================================================================
> --- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
> +++ llvm/trunk/utils/FileCheck/FileCheck.cpp Mon Apr  7 12:09:53 2014
> @@ -965,7 +965,8 @@ static void PrintCheckFailed(const Sourc
>
>  /// CountNumNewlinesBetween - Count the number of newlines in the specified
>  /// range.
> -static unsigned CountNumNewlinesBetween(StringRef Range) {
> +static unsigned CountNumNewlinesBetween(StringRef Range,
> +                                        const char *&FirstNewLine) {
>    unsigned NumNewLines = 0;
>    while (1) {
>      // Scan for newline.
> @@ -980,6 +981,9 @@ static unsigned CountNumNewlinesBetween(
>          (Range[0] != Range[1]))
>        Range = Range.substr(1);
>      Range = Range.substr(1);
> +
> +    if (NumNewLines == 1)
> +      FirstNewLine = Range.begin();
>    }
>  }
>
> @@ -1039,7 +1043,8 @@ bool CheckString::CheckNext(const Source
>               SMLoc::getFromPointer(Buffer.data())))->getBufferStart() &&
>           "CHECK-NEXT can't be the first check in a file");
>
> -  unsigned NumNewLines = CountNumNewlinesBetween(Buffer);
> +  const char *FirstNewLine = 0;
> +  unsigned NumNewLines = CountNumNewlinesBetween(Buffer, FirstNewLine);
>
>    if (NumNewLines == 0) {
>      SM.PrintMessage(Loc, SourceMgr::DK_Error, Prefix +
> @@ -1058,6 +1063,8 @@ bool CheckString::CheckNext(const Source
>                      SourceMgr::DK_Note, "'next' match was here");
>      SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), SourceMgr::DK_Note,
>                      "previous match ended here");
> +    SM.PrintMessage(SMLoc::getFromPointer(FirstNewLine), SourceMgr::DK_Note,
> +                    "non-matching line after previous match is here");
>      return true;
>    }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list