This is an archive of the discontinued LLVM Phabricator instance.

[clang] Show verify prefix in error messages
ClosedPublic

Authored by tbaeder on Jul 7 2023, 1:31 AM.

Details

Diff Detail

Event Timeline

tbaeder created this revision.Jul 7 2023, 1:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2023, 1:31 AM
tbaeder requested review of this revision.Jul 7 2023, 1:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2023, 1:31 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tbaeder updated this revision to Diff 538058.Jul 7 2023, 3:20 AM

I'm not opposed but I am wondering what the need is for this? (It'd be good to capture that information in the patch summary as well.) Some examples showing where this helps to correct the issue would be useful.

When passing a different prefix via -verify=foo, the error messages now say "error: 'foo-error' diagnostics seen but not expected", etc.

I'm often working in test files where two different prefixes are used and I'm always confused about which one of the two the error messages are talking about.

When passing a different prefix via -verify=foo, the error messages now say "error: 'foo-error' diagnostics seen but not expected", etc.

I'm often working in test files where two different prefixes are used and I'm always confused about which one of the two the error messages are talking about.

What I'm confused by is that we list the line numbers of the failures, so the prefix only seems like it's helpful in a case where two prefixes use the same message and the same severity on the same line. e.g., // foo-error {{whatever}} bar-error {{whatever}}. In the other cases, either the line number is different, or the severity is different, or the message is different which I thought was giving sufficient context.

When passing a different prefix via -verify=foo, the error messages now say "error: 'foo-error' diagnostics seen but not expected", etc.

I'm often working in test files where two different prefixes are used and I'm always confused about which one of the two the error messages are talking about.

What I'm confused by is that we list the line numbers of the failures, so the prefix only seems like it's helpful in a case where two prefixes use the same message and the same severity on the same line. e.g., // foo-error {{whatever}} bar-error {{whatever}}. In the other cases, either the line number is different, or the severity is different, or the message is different which I thought was giving sufficient context.

This is also reported as being on line 4:

// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info -verify=bar %s 2>&1


static_assert(true); // foo \
                     // bar-error {{failed}}

which is also the case if line 4 contained another foo-error {{failed}} which didn't trigger, leaving developers wondering which one it is.

When passing a different prefix via -verify=foo, the error messages now say "error: 'foo-error' diagnostics seen but not expected", etc.

I'm often working in test files where two different prefixes are used and I'm always confused about which one of the two the error messages are talking about.

What I'm confused by is that we list the line numbers of the failures, so the prefix only seems like it's helpful in a case where two prefixes use the same message and the same severity on the same line. e.g., // foo-error {{whatever}} bar-error {{whatever}}. In the other cases, either the line number is different, or the severity is different, or the message is different which I thought was giving sufficient context.

This is also reported as being on line 4:

// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info -verify=bar %s 2>&1


static_assert(true); // foo \
                     // bar-error {{failed}}

which is also the case if line 4 contained another foo-error {{failed}} which didn't trigger, leaving developers wondering which one it is.

Okay, we do that often enough in our tests (along with two diagnostics on the same line directly) that this seems pretty reasonable to me.

Can you add some test coverage where the prefix is not the default expected?

The change looks great: (from error: 'error' diagnostics seen but not expected: to error: 'expected-error' diagnostics seen but not expected).
When I read Clang tests, I was confused by what error meant. I eventually figured out -verify is special. The new diagnostic is clearer and more helpful.

tbaeder updated this revision to Diff 542768.Jul 20 2023, 11:03 PM

Precommit CI found relevant failures that should be addressed.

tbaeder updated this revision to Diff 543260.Jul 23 2023, 12:45 AM
MaskRay added inline comments.Jul 23 2023, 12:57 AM
clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
881

The variables are immediately used. I think in this case our convention is omit the blank line (and in general I think we omit blank lines for many more cases, compared to some other projects (GNU, Linux kernel, etc)).

clang/test/Frontend/verify.c
159

This may need a comment explaining that this is not recognized as a directive.

tbaeder updated this revision to Diff 543298.Jul 23 2023, 10:05 AM
tbaeder marked an inline comment as done.
tbaeder added inline comments.Jul 23 2023, 10:08 AM
clang/test/Frontend/verify.c
159

Not sure I follow, what isn't being recognized as a directive?

This revision is now accepted and ready to land.Aug 10 2023, 4:44 AM
MaskRay accepted this revision.Aug 11 2023, 11:32 AM
This revision was automatically updated to reflect the committed changes.