diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index f656687f9fb1f..9811f8da3a0ee 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -666,8 +666,8 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { } case CK_VectorSplat: { - assert(!classify(CE->getType())); - assert(classify(SubExpr->getType())); + assert(!canClassify(CE->getType())); + assert(canClassify(SubExpr->getType())); assert(CE->getType()->isVectorType()); if (!Initializing) { @@ -2069,7 +2069,7 @@ bool Compiler::visitCallArgs(ArrayRef Args, unsigned ArgIndex = 0; for (const Expr *Arg : Args) { - if (OptPrimType T = classify(Arg)) { + if (canClassify(Arg)) { if (!this->visit(Arg)) return false; } else { @@ -3154,7 +3154,7 @@ bool Compiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) { template bool Compiler::VisitCXXConstructExpr(const CXXConstructExpr *E) { QualType T = E->getType(); - assert(!classify(T)); + assert(!canClassify(T)); if (T->isRecordType()) { const CXXConstructorDecl *Ctor = E->getConstructor(); @@ -4149,7 +4149,7 @@ template bool Compiler::visit(const Expr *E) { // Create local variable to hold the return value. if (!E->isGLValue() && !E->getType()->isAnyComplexType() && - !classify(E->getType())) { + !canClassify(E->getType())) { std::optional LocalIndex = allocateLocal(E); if (!LocalIndex) return false; @@ -4169,7 +4169,7 @@ template bool Compiler::visit(const Expr *E) { template bool Compiler::visitInitializer(const Expr *E) { - assert(!classify(E->getType())); + assert(!canClassify(E->getType())); OptionScope Scope(this, /*NewDiscardResult=*/false, /*NewInitializing=*/true); @@ -4376,7 +4376,7 @@ bool Compiler::visitZeroArrayInitializer(QualType T, const Expr *E) { template bool Compiler::visitAssignment(const Expr *LHS, const Expr *RHS, const Expr *E) { - if (!classify(E->getType())) + if (!canClassify(E->getType())) return false; if (!this->visit(RHS)) diff --git a/clang/lib/AST/ByteCode/Compiler.h b/clang/lib/AST/ByteCode/Compiler.h index ee8327d8fee1e..d72ffa13f6b9d 100644 --- a/clang/lib/AST/ByteCode/Compiler.h +++ b/clang/lib/AST/ByteCode/Compiler.h @@ -256,6 +256,8 @@ class Compiler : public ConstStmtVisitor, bool>, OptPrimType classify(const Expr *E) const { return Ctx.classify(E); } OptPrimType classify(QualType Ty) const { return Ctx.classify(Ty); } + bool canClassify(const Expr *E) const { return Ctx.canClassify(E); } + bool canClassify(QualType T) const { return Ctx.canClassify(T); } /// Classifies a known primitive type. PrimType classifyPrim(QualType Ty) const { diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index f7f528c4e6484..b4e8a9930e668 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -501,7 +501,7 @@ const Function *Context::getOrCreateFunction(const FunctionDecl *FuncDecl) { // elsewhere in the code. QualType Ty = FuncDecl->getReturnType(); bool HasRVO = false; - if (!Ty->isVoidType() && !classify(Ty)) { + if (!Ty->isVoidType() && !canClassify(Ty)) { HasRVO = true; ParamTypes.push_back(PT_Ptr); ParamOffsets.push_back(ParamOffset); diff --git a/clang/lib/AST/ByteCode/Context.h b/clang/lib/AST/ByteCode/Context.h index 1c084acbe916b..a6d90bb385067 100644 --- a/clang/lib/AST/ByteCode/Context.h +++ b/clang/lib/AST/ByteCode/Context.h @@ -93,6 +93,25 @@ class Context final { return classify(E->getType()); } + bool canClassify(QualType T) { + if (const auto *BT = dyn_cast(T)) { + if (BT->isInteger() || BT->isFloatingPoint()) + return true; + if (BT->getKind() == BuiltinType::Bool) + return true; + } + + if (T->isArrayType() || T->isRecordType() || T->isAnyComplexType() || + T->isVectorType()) + return false; + return classify(T) != std::nullopt; + } + bool canClassify(const Expr *E) { + if (E->isGLValue()) + return true; + return canClassify(E->getType()); + } + const CXXMethodDecl * getOverridingFunction(const CXXRecordDecl *DynamicDecl, const CXXRecordDecl *StaticDecl,