This is an archive of the discontinued LLVM Phabricator instance.

[VerifyDiagnosticConsumer] Fix last line being discarded when parsing newline
Needs ReviewPublic

Authored by vangthao on Jun 2 2022, 12:35 PM.

Details

Summary

In expected diagnostic checks containing newlines, anything after the last
newline would be discarded since we stop parsing directly after the last newline.
Fix this behavior so that any remaining string after the last newline is
appended instead of ignored.

Diff Detail

Event Timeline

vangthao created this revision.Jun 2 2022, 12:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2022, 12:35 PM
vangthao requested review of this revision.Jun 2 2022, 12:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2022, 12:35 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thank you for the patch!

clang/test/SemaCXX/references.cpp
93

Can you please explain in detail what bug are you fixing?
In my understanding if we stop parsing after the last newline then the existing test would have failed. The difference seems to be only the white-space.
Am I missing something?

vangthao added inline comments.Oct 17 2022, 7:24 PM
clang/test/SemaCXX/references.cpp
93

In my understanding if we stop parsing after the last newline then the existing test would have failed.

The reason it does not fail is because we do not perform an exact match. We only do a partial match since contains() is used here when matching https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp#L102.

We parsed the following from the expected-warning check:

direct base 'A' is inaccessible due to ambiguity:
    struct C -> B -> A

and the actual output from clang is:

direct base 'A' is inaccessible due to ambiguity:
    struct C -> B -> A
    struct C -> A

The output from clang does contain the expected warning that we parsed but not all of it since we discarded the last line of \nstruct C -> struct A from the check. You can verify that by adding anything on this line. It will not fail the test because we are not checking for it.