This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix diagnostic location for macro expansions
ClosedPublic

Authored by kadircet on Nov 20 2019, 7:19 AM.

Details

Summary

Diagnostic locations were broken when it was result of a macro
expansion. This patch fixes it by using expansion location instead of location
inside macro body.

Fixes https://github.com/clangd/clangd/issues/201.

Diff Detail

Event Timeline

kadircet created this revision.Nov 20 2019, 7:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 20 2019, 7:19 AM

Build result: pass - 60059 tests passed, 0 failed and 729 were skipped.
Log files: console-log.txt, CMakeCache.txt

hokein added inline comments.Nov 22 2019, 4:52 AM
clang-tools-extra/clangd/Diagnostics.cpp
121

should we use getExpansionLoc? getFileLoc returns a spelling location if it comes from a macro argument, but I think it doesn't matter.

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
944

this doesn't belong to IgnoreDiags any more, I think, should be DiagsInHeaders, the same to the newly-added test.

1012

could you add one more test case where foo is spelled at macro argument? I believe it was broken as well before this patch.

#define X(arg) arg
X(foo);
kadircet marked 5 inline comments as done.Nov 22 2019, 5:01 AM
kadircet added inline comments.
clang-tools-extra/clangd/Diagnostics.cpp
121

right

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
944

ah thanks!

kadircet updated this revision to Diff 230636.Nov 22 2019, 5:01 AM
kadircet marked 2 inline comments as done.
  • Address comments

Build result: pass - 60220 tests passed, 0 failed and 732 were skipped.

Log files: console-log.txt, CMakeCache.txt

hokein accepted this revision.Nov 25 2019, 1:12 AM
hokein added inline comments.
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
995

I'd move this to the end of the file, so that all DiagsInHeaders are grouped together.

This revision is now accepted and ready to land.Nov 25 2019, 1:12 AM
kadircet updated this revision to Diff 230849.Nov 25 2019, 1:45 AM
kadircet marked an inline comment as done.
  • Group similar tests together
This revision was automatically updated to reflect the committed changes.