Skip to content

[clang][bytecode] Fix initializing base casts #104901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
unsigned DerivedOffset = collectBaseOffset(QualType(ToMP->getClass(), 0),
QualType(FromMP->getClass(), 0));

if (!this->visit(SubExpr))
if (!this->delegate(SubExpr))
return false;

return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
Expand All @@ -229,14 +229,14 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
unsigned DerivedOffset = collectBaseOffset(QualType(FromMP->getClass(), 0),
QualType(ToMP->getClass(), 0));

if (!this->visit(SubExpr))
if (!this->delegate(SubExpr))
return false;
return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
}

case CK_UncheckedDerivedToBase:
case CK_DerivedToBase: {
if (!this->visit(SubExpr))
if (!this->delegate(SubExpr))
return false;

const auto extractRecordDecl = [](QualType Ty) -> const CXXRecordDecl * {
Expand Down Expand Up @@ -265,7 +265,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
}

case CK_BaseToDerived: {
if (!this->visit(SubExpr))
if (!this->delegate(SubExpr))
return false;

unsigned DerivedOffset =
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
return false;
const Pointer &Result = Ptr.atField(Off);
if (Result.isPastEnd())
if (Result.isPastEnd() || !Result.isBaseClass())
return false;
S.Stk.push<Pointer>(Result);
return true;
Expand All @@ -1581,7 +1581,7 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off) {
if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
return false;
const Pointer &Result = Ptr.atField(Off);
if (Result.isPastEnd())
if (Result.isPastEnd() || !Result.isBaseClass())
return false;
S.Stk.push<Pointer>(Result);
return true;
Expand Down
1 change: 1 addition & 0 deletions clang/test/Modules/merge-using-decls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++11 %s -DORDER=2

// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++17 %s -DORDER=2
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fmodules -fimplicit-module-maps -fexperimental-new-constant-interpreter -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++98 %s -DORDER=1

#if ORDER == 1
#include "a.h"
Expand Down
Loading