summaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Compiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/AST/ByteCode/Compiler.cpp')
-rw-r--r--clang/lib/AST/ByteCode/Compiler.cpp80
1 files changed, 57 insertions, 23 deletions
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 900312401bbd..036f9608bf3c 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -3427,6 +3427,38 @@ bool Compiler<Emitter>::VisitBlockExpr(const BlockExpr *E) {
}
template <class Emitter>
+bool Compiler<Emitter>::VisitCXXTypeidExpr(const CXXTypeidExpr *E) {
+ const Type *TypeInfoType = E->getType().getTypePtr();
+
+ if (!E->isPotentiallyEvaluated()) {
+ if (DiscardResult)
+ return true;
+
+ if (E->isTypeOperand())
+ return this->emitGetTypeid(
+ E->getTypeOperand(Ctx.getASTContext()).getTypePtr(), TypeInfoType, E);
+ return this->emitGetTypeid(E->getExprOperand()->getType().getTypePtr(),
+ TypeInfoType, E);
+ }
+
+ // Otherwise, we need to evaluate the expression operand.
+ assert(E->getExprOperand());
+ assert(E->getExprOperand()->isLValue());
+
+ if (!Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E))
+ return false;
+
+ if (!this->visit(E->getExprOperand()))
+ return false;
+
+ if (!this->emitGetTypeidPtr(TypeInfoType, E))
+ return false;
+ if (DiscardResult)
+ return this->emitPopPtr(E);
+ return true;
+}
+
+template <class Emitter>
bool Compiler<Emitter>::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) {
assert(Ctx.getLangOpts().CPlusPlus);
return this->emitConstBool(E->getValue(), E);
@@ -4974,20 +5006,35 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
LabelTy LabelEnd = this->getLabel();
if (!this->jumpFalse(LabelElse))
return false;
- if (!visitStmt(IS->getThen()))
- return false;
+ {
+ LocalScope<Emitter> ThenScope(this);
+ if (!visitStmt(IS->getThen()))
+ return false;
+ if (!ThenScope.destroyLocals())
+ return false;
+ }
if (!this->jump(LabelEnd))
return false;
this->emitLabel(LabelElse);
- if (!visitStmt(Else))
- return false;
+ {
+ LocalScope<Emitter> ElseScope(this);
+ if (!visitStmt(Else))
+ return false;
+ if (!ElseScope.destroyLocals())
+ return false;
+ }
this->emitLabel(LabelEnd);
} else {
LabelTy LabelEnd = this->getLabel();
if (!this->jumpFalse(LabelEnd))
return false;
- if (!visitStmt(IS->getThen()))
- return false;
+ {
+ LocalScope<Emitter> ThenScope(this);
+ if (!visitStmt(IS->getThen()))
+ return false;
+ if (!ThenScope.destroyLocals())
+ return false;
+ }
this->emitLabel(LabelEnd);
}
@@ -6483,19 +6530,6 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) {
QualType ToType = E->getType();
std::optional<PrimType> ToT = classify(ToType);
- if (ToType->isNullPtrType()) {
- if (!this->discard(SubExpr))
- return false;
-
- return this->emitNullPtr(0, nullptr, E);
- }
-
- if (FromType->isNullPtrType() && ToT) {
- if (!this->discard(SubExpr))
- return false;
-
- return visitZeroInitializer(*ToT, ToType, E);
- }
assert(!ToType->isReferenceType());
// Prepare storage for the result in case we discard.
@@ -6528,8 +6562,8 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) {
return false;
}
- if (!ToT || ToT == PT_Ptr) {
- if (!this->emitBitCastPtr(E))
+ if (!ToT) {
+ if (!this->emitBitCast(E))
return false;
return DiscardResult ? this->emitPopPtr(E) : true;
}
@@ -6545,8 +6579,8 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) {
ToType->isSpecificBuiltinType(BuiltinType::Char_U));
uint32_t ResultBitWidth = std::max(Ctx.getBitWidth(ToType), 8u);
- if (!this->emitBitCast(*ToT, ToTypeIsUChar || ToType->isStdByteType(),
- ResultBitWidth, TargetSemantics, E))
+ if (!this->emitBitCastPrim(*ToT, ToTypeIsUChar || ToType->isStdByteType(),
+ ResultBitWidth, TargetSemantics, E))
return false;
if (DiscardResult)