Skip to content

Commit 613d2c3

Browse files
committed
[clang][Interp][NFC] Avoid hitting an assertion in invalid code
1 parent d8e0b0d commit 613d2c3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

clang/lib/AST/Interp/Pointer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
149149
CharUnits Offset = CharUnits::Zero();
150150

151151
auto getFieldOffset = [&](const FieldDecl *FD) -> CharUnits {
152+
// This shouldn't happen, but if it does, don't crash inside
153+
// getASTRecordLayout.
154+
if (FD->getParent()->isInvalidDecl())
155+
return CharUnits::Zero();
152156
const ASTRecordLayout &Layout = ASTCtx.getASTRecordLayout(FD->getParent());
153157
unsigned FieldIndex = FD->getFieldIndex();
154158
return ASTCtx.toCharUnitsFromBits(Layout.getFieldOffset(FieldIndex));

0 commit comments

Comments
 (0)