aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-07-20 20:22:38 +0200
committerTimm Bäder <tbaeder@redhat.com>2024-07-22 16:59:31 +0200
commit613d2c393992eee470405f1859aaf5fd1837e36c (patch)
treebbbe55ddd7c6d45ff3db5f410f774c3f2bc894f2
parentd8e0b0d6854757c4fc0c120995cf76457c347a1e (diff)
downloadllvm-613d2c393992eee470405f1859aaf5fd1837e36c.zip
llvm-613d2c393992eee470405f1859aaf5fd1837e36c.tar.gz
llvm-613d2c393992eee470405f1859aaf5fd1837e36c.tar.bz2
[clang][Interp][NFC] Avoid hitting an assertion in invalid code
-rw-r--r--clang/lib/AST/Interp/Pointer.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp
index 229007c..3324691 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -149,6 +149,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
CharUnits Offset = CharUnits::Zero();
auto getFieldOffset = [&](const FieldDecl *FD) -> CharUnits {
+ // This shouldn't happen, but if it does, don't crash inside
+ // getASTRecordLayout.
+ if (FD->getParent()->isInvalidDecl())
+ return CharUnits::Zero();
const ASTRecordLayout &Layout = ASTCtx.getASTRecordLayout(FD->getParent());
unsigned FieldIndex = FD->getFieldIndex();
return ASTCtx.toCharUnitsFromBits(Layout.getFieldOffset(FieldIndex));