[PATCH] D85834: [AST] Fix a crash on calling getASTRecordLayout on an invalid RecordDecl.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 12 06:21:43 PDT 2020
hokein added inline comments.
================
Comment at: clang/lib/AST/ASTContext.cpp:2463
- unsigned PreferredAlign = static_cast<unsigned>(
- toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
- assert(PreferredAlign >= ABIAlign &&
- "PreferredAlign should be at least as large as ABIAlign.");
- return PreferredAlign;
+ if (!RT->getDecl()->isInvalidDecl()) {
+ unsigned PreferredAlign = static_cast<unsigned>(
----------------
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).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85834/new/
https://reviews.llvm.org/D85834
More information about the cfe-commits
mailing list