Skip to content

[clang][bytecode] Add canClassify() helper #152755

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 9, 2025
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
14 changes: 7 additions & 7 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ bool Compiler<Emitter>::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) {
Expand Down Expand Up @@ -2069,7 +2069,7 @@ bool Compiler<Emitter>::visitCallArgs(ArrayRef<const Expr *> Args,

unsigned ArgIndex = 0;
for (const Expr *Arg : Args) {
if (OptPrimType T = classify(Arg)) {
if (canClassify(Arg)) {
if (!this->visit(Arg))
return false;
} else {
Expand Down Expand Up @@ -3154,7 +3154,7 @@ bool Compiler<Emitter>::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) {
template <class Emitter>
bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
QualType T = E->getType();
assert(!classify(T));
assert(!canClassify(T));

if (T->isRecordType()) {
const CXXConstructorDecl *Ctor = E->getConstructor();
Expand Down Expand Up @@ -4149,7 +4149,7 @@ template <class Emitter> bool Compiler<Emitter>::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<unsigned> LocalIndex = allocateLocal(E);
if (!LocalIndex)
return false;
Expand All @@ -4169,7 +4169,7 @@ template <class Emitter> bool Compiler<Emitter>::visit(const Expr *E) {

template <class Emitter>
bool Compiler<Emitter>::visitInitializer(const Expr *E) {
assert(!classify(E->getType()));
assert(!canClassify(E->getType()));

OptionScope<Emitter> Scope(this, /*NewDiscardResult=*/false,
/*NewInitializing=*/true);
Expand Down Expand Up @@ -4376,7 +4376,7 @@ bool Compiler<Emitter>::visitZeroArrayInitializer(QualType T, const Expr *E) {
template <class Emitter>
bool Compiler<Emitter>::visitAssignment(const Expr *LHS, const Expr *RHS,
const Expr *E) {
if (!classify(E->getType()))
if (!canClassify(E->getType()))
return false;

if (!this->visit(RHS))
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/AST/ByteCode/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, 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 {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions clang/lib/AST/ByteCode/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ class Context final {
return classify(E->getType());
}

bool canClassify(QualType T) {
if (const auto *BT = dyn_cast<BuiltinType>(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,
Expand Down