This is an archive of the discontinued LLVM Phabricator instance.

[AST] Fix a crash on calling getASTRecordLayout on an invalid RecordDecl.
AbandonedPublic

Authored by hokein on Aug 12 2020, 6:15 AM.

Details

Reviewers
sammccall
rsmith
Summary

The getASTRecordLayout method requires a valid decl.

Diff Detail

Event Timeline

hokein created this revision.Aug 12 2020, 6:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2020, 6:15 AM
hokein requested review of this revision.Aug 12 2020, 6:15 AM
hokein added inline comments.Aug 12 2020, 6:21 AM
clang/lib/AST/ASTContext.cpp
2463

another proper fix might be change the getPreferredTypeAlign signature to support error handling (e.g. return a bool), but that would require a large invasive change for its callers, not sure it is worth.

I think the current implementation is OK, as the result doesn't really matter for an invalid RecordDecl, and we do similar thing int getTypeInfoImpl (returning a fake Align/Width for invalid decl).

sammccall accepted this revision.Aug 12 2020, 8:02 AM
sammccall added inline comments.
clang/lib/AST/ASTContext.cpp
2463

I think this is fine though it could be clearer/more explicit about how the special case is handled.

if (RT->getDecl()->isInvalidDecl())
  return ABIAlign;
This revision is now accepted and ready to land.Aug 12 2020, 8:02 AM