This is an archive of the discontinued LLVM Phabricator instance.

[FileCheck] Extend -dump-input with substitutions
ClosedPublic

Authored by jdenny on Jul 12 2020, 6:45 PM.

Details

Summary

Substitutions are already reported in the diagnostics appearing before
the input dump in the case of failed directives, and they're reported
in traces (produced by -vv -dump-input=never) in the case of
successful directives. However, those reports are not always
convenient to view while investigating the input dump, so this patch
adds the substitution report to the input dump too. For example:

$ cat check
CHECK: hello [[WHAT:[a-z]+]]
CHECK: [[VERB]] [[WHAT]]

$ FileCheck -vv -DVERB=goodbye check < input |& tail -8
<<<<<<
           1: hello world
check:1       ^~~~~~~~~~~
           2: goodbye word
check:2'0     X~~~~~~~~~~~ error: no match found
check:2'1                  with "VERB" equal to "goodbye"
check:2'2                  with "WHAT" equal to "world"
>>>>>>

Without this patch, the location reported for a substitution for a
directive match is the directive's full match range. This location is
misleading as it implies the substitution itself matches that range.
This patch changes the reported location to just the match range start
to suggest the substitution is known at the start of the match. (As
in the above example, input dumps don't mark any range for
substitutions. The location info in that case simply identifies the
right line for the annotation.)

Diff Detail

Event Timeline

jdenny created this revision.Jul 12 2020, 6:45 PM

I agree that I'd like to have more info inline and this is going in the right direction, but what seems missing is still the check line itself.

Have you looked into localizing it as well?

<<<<<<
           1: hello world
check:1       ^~~~~~~~~~~ // CHECK: hello [[WHAT:[a-z]+]]
           2: goodbye word
check:2'0     X~~~~~~~~~~~ error: no match found
check:2'0     CHECK: [[VERB]] [[WHAT]]
check:2'1                  with "VERB" equal to "goodbye"
check:2'2                  with "WHAT" equal to "world"
>>>>>>

Ultimately with some scheme like this the following header can be entirely omitted:

error: CHECK: expected string not found in input
CHECK: [[VERB]] [[WHAT]]
       ^
<stdin>:2:1: note: scanning from here
goodbye word
^
<stdin>:2:1: note: with "VERB" equal to "goodbye"
goodbye word
^
<stdin>:2:1: note: with "WHAT" equal to "world"
goodbye word
^

Input file: <stdin>
Check file: check

-dump-input=help explains the following input dump.

I agree that I'd like to have more info inline and this is going in the right direction, but what seems missing is still the check line itself.

Have you looked into localizing it as well?

I too have been thinking that would be a good idea. However, it's a lower priority because, at least for tests I work with, check:1 makes it easy to find that info in a file I have to open anyway.

Ultimately with some scheme like this the following header can be entirely omitted:

Probably so.

I agree that I'd like to have more info inline and this is going in the right direction, but what seems missing is still the check line itself.

Have you looked into localizing it as well?

I too have been thinking that would be a good idea. However, it's a lower priority because, at least for tests I work with, check:1 makes it easy to find that info in a file I have to open anyway.

In other words, I think that should be a later patch. Is that OK?

In other words, I think that should be a later patch. Is that OK?

Absolutely!

Sorry, I've had some time off and the last few weeks when I have been working have been very busy for me. I've got this on my backlog, and will, if I can, try to come to it later in the week if nobody else does.

Sure. Thanks for the reply.

thopre added inline comments.Jul 28 2020, 1:19 PM
llvm/test/FileCheck/dump-input-annotations.txt
635

It should yes so you can rewrite the FIXME into something like "CHECK-NOT wrongly consider an undefined variable as a failure to match, fix first line input dump below once this is fixed".

IMHO, I think it should be fixed by making CheckNot handle UndefVarError errors and call a new printUndef and return true if any is found.

thopre accepted this revision.Jul 28 2020, 1:19 PM

LGTM with the fixed FIXME.

This revision is now accepted and ready to land.Jul 28 2020, 1:19 PM
jdenny updated this revision to Diff 281361.Jul 28 2020, 2:24 PM

Adjust the fixme as requested.

Thanks for the review.

llvm/test/FileCheck/dump-input-annotations.txt
635

Let me know if the new text isn't what you had in mind.

There should probably be a bugzilla for this. I'll try to look into it tomorrow.

thopre added inline comments.Jul 28 2020, 2:52 PM
llvm/test/FileCheck/dump-input-annotations.txt
635

LGTM. I'd be happy to fix it but can only look at it in about a week from now. If you do create a bugzilla please add me in Cc so that I see if it has been fixed or whether I should get to it.

This revision was automatically updated to reflect the committed changes.
jdenny added inline comments.Jul 28 2020, 4:38 PM
llvm/test/FileCheck/dump-input-annotations.txt
635

Bug is here:

https://bugs.llvm.org/show_bug.cgi?id=46880

I probably won't work on it anytime soon, so feel free to take it.