[clang] ba7dadf - [clang][bytecode] Fix initializing base casts (#104901)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 20 02:44:33 PDT 2024
Author: Timm Baeder
Date: 2024-08-20T11:44:30+02:00
New Revision: ba7dadf0e918cbb0e6867d78aebd0cc3fc843bcc
URL: https://github.com/llvm/llvm-project/commit/ba7dadf0e918cbb0e6867d78aebd0cc3fc843bcc
DIFF: https://github.com/llvm/llvm-project/commit/ba7dadf0e918cbb0e6867d78aebd0cc3fc843bcc.diff
LOG: [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.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Interp.h
clang/test/Modules/merge-using-decls.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 131b83ae8eb397..0af473f9bd0802 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -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);
@@ -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 * {
@@ -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 =
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index bad46e98304845..b805b7b246c51b 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -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;
@@ -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;
diff --git a/clang/test/Modules/merge-using-decls.cpp b/clang/test/Modules/merge-using-decls.cpp
index e9794a40837ef9..b678eb4e0f851f 100644
--- a/clang/test/Modules/merge-using-decls.cpp
+++ b/clang/test/Modules/merge-using-decls.cpp
@@ -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"
More information about the cfe-commits
mailing list