This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix crash when there is an invalid declaration with flag -Wcast-align
ClosedPublic

Authored by qdelacru on Jul 5 2021, 6:05 PM.

Details

Reviewers
aaron.ballman
Summary

When there is unknown type in a struct in code compiled with -Wcast-align, the compiler crashes due to clang::ASTContext::getASTRecordLayout() failing an assert.

repro.c:1:21: error: unknown type name 'doesnotexist'
struct { int hello; doesnotexist world; } foo;
                    ^
clang: /root/llvm-project/clang/lib/AST/RecordLayoutBuilder.cpp:3230: const clang::ASTRecordLayout& clang::ASTContext::getASTRecordLayout(const clang::RecordDecl*) const: Assertion `!D->isInvalidDecl() && "Cannot get layout of invalid decl!"' failed.

Added check that the RecordDecl is valid before calling getASTRecordLayout()

Diff Detail

Unit TestsFailed

Event Timeline

qdelacru requested review of this revision.Jul 5 2021, 6:05 PM
qdelacru created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2021, 6:05 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
qdelacru updated this revision to Diff 356591.Jul 5 2021, 8:14 PM

Fix format

qdelacru updated this revision to Diff 356836.Jul 6 2021, 4:49 PM
aaron.ballman accepted this revision.Jul 7 2021, 6:38 AM

Thank you for the fix, LGTM! Do you need help landing the change? If so, please let me know what name and email address you'd like me to use for patch attribution.

This revision is now accepted and ready to land.Jul 7 2021, 6:38 AM

Please use Queen Dela Cruz, qdelacru@cisco.com. Thanks!

aaron.ballman closed this revision.Jul 7 2021, 11:02 AM

Thank you for the fix! I've applied in 3c5721d77275d2a7bdaeeadd0b1c3864f1166110