This is an archive of the discontinued LLVM Phabricator instance.

[libtooling][clang-tidy] Fix crashing on rendering invalid SourceRanges
ClosedPublic

Authored by steakhal on Nov 19 2021, 8:59 AM.

Details

Summary

Invalid SourceRanges can occur generally if the code does not compile,
thus we expect clang error diagnostics.
Unlike clang, clang-tidy did not swallow invalid source ranges, but
tried to highlight them, and blow various assertions.

The following two examples produce invalid source ranges, but this is
not a complete list:

void test(x); // error: unknown type name 'x'
struct Foo {
  member; // error: C++ requires a type specifier for all declarations
};

Thanks @whisperity helping me fix this.

Diff Detail

Event Timeline

steakhal created this revision.Nov 19 2021, 8:59 AM
steakhal requested review of this revision.Nov 19 2021, 8:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 19 2021, 8:59 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
xazax.hun accepted this revision.Nov 19 2021, 12:19 PM
This revision is now accepted and ready to land.Nov 19 2021, 12:19 PM
whisperity added inline comments.Nov 22 2021, 1:49 AM
clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
102

EXPECT_TRUE(Errors[0].Message.Ranges.empty());? But I'm not sure if the data structure used there supports this.

steakhal updated this revision to Diff 388850.Nov 22 2021, 3:13 AM
steakhal marked an inline comment as done.
  • prefer empty() over size() == 0