Skip to content

Commit ba7dadf

Browse files
authored
[clang][bytecode] Fix initializing base casts (#104901)
Use delegate() there. To fix a follow-up problem, abort when a cast ends up on a valid Pointer that isn't a base class.
1 parent 66953c9 commit ba7dadf

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
214214
unsigned DerivedOffset = collectBaseOffset(QualType(ToMP->getClass(), 0),
215215
QualType(FromMP->getClass(), 0));
216216

217-
if (!this->visit(SubExpr))
217+
if (!this->delegate(SubExpr))
218218
return false;
219219

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

232-
if (!this->visit(SubExpr))
232+
if (!this->delegate(SubExpr))
233233
return false;
234234
return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
235235
}
236236

237237
case CK_UncheckedDerivedToBase:
238238
case CK_DerivedToBase: {
239-
if (!this->visit(SubExpr))
239+
if (!this->delegate(SubExpr))
240240
return false;
241241

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

267267
case CK_BaseToDerived: {
268-
if (!this->visit(SubExpr))
268+
if (!this->delegate(SubExpr))
269269
return false;
270270

271271
unsigned DerivedOffset =

clang/lib/AST/ByteCode/Interp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
15681568
if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
15691569
return false;
15701570
const Pointer &Result = Ptr.atField(Off);
1571-
if (Result.isPastEnd())
1571+
if (Result.isPastEnd() || !Result.isBaseClass())
15721572
return false;
15731573
S.Stk.push<Pointer>(Result);
15741574
return true;
@@ -1581,7 +1581,7 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off) {
15811581
if (!CheckSubobject(S, OpPC, Ptr, CSK_Base))
15821582
return false;
15831583
const Pointer &Result = Ptr.atField(Off);
1584-
if (Result.isPastEnd())
1584+
if (Result.isPastEnd() || !Result.isBaseClass())
15851585
return false;
15861586
S.Stk.push<Pointer>(Result);
15871587
return true;

clang/test/Modules/merge-using-decls.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// 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
99

1010
// 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
11+
// 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
1112

1213
#if ORDER == 1
1314
#include "a.h"

0 commit comments

Comments
 (0)