This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix crashing altera-struct-pack-align on invalid RecordDecls
ClosedPublic

Authored by steakhal on Nov 19 2021, 9:13 AM.

Diff Detail

Event Timeline

steakhal created this revision.Nov 19 2021, 9:13 AM
steakhal requested review of this revision.Nov 19 2021, 9:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 19 2021, 9:13 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

What happens if this checker runs on a forward declared class?

struct Foo;

I'd expect the pack/alignment info is missing also in that case.

clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
54

I'd mention first that packing and alignment info are meaningless for invalid declarations.

steakhal updated this revision to Diff 389225.Nov 23 2021, 9:02 AM
steakhal marked an inline comment as done.
  • update comments
  • move no-crash comment inline to the class member declaration

What happens if this checker runs on a forward declared class?

The matcher recordDecl(isStruct(), **isDefinition()**, unless(isExpansionInSystemHeader())) filters that case.

Thanks for the review @martong!

clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
54

Makes sense.

martong accepted this revision.Nov 25 2021, 5:02 AM

LGTM!

This revision is now accepted and ready to land.Nov 25 2021, 5:02 AM

I plan to commit this stack on Monday.