From d01355645b1fece147163e1cfe9f71d9c704860e Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Tue, 20 May 2025 11:19:24 +0200 Subject: [clang][bytecode] Check downcasts for the correct type (#140689) In multiple inheritance/diamond scenarios, we might arrive at the wrong type. --- clang/lib/AST/ByteCode/Compiler.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'clang/lib/AST/ByteCode/Compiler.cpp') diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 3638054..54a4647 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -296,12 +296,15 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { case CK_BaseToDerived: { if (!this->delegate(SubExpr)) return false; - unsigned DerivedOffset = collectBaseOffset(SubExpr->getType(), CE->getType()); - return this->emitGetPtrDerivedPop( - DerivedOffset, /*NullOK=*/CE->getType()->isPointerType(), CE); + const Type *TargetType = CE->getType().getTypePtr(); + if (TargetType->isPointerOrReferenceType()) + TargetType = TargetType->getPointeeType().getTypePtr(); + return this->emitGetPtrDerivedPop(DerivedOffset, + /*NullOK=*/CE->getType()->isPointerType(), + TargetType, CE); } case CK_FloatingCast: { -- cgit v1.1