diff --git a/clang/lib/AST/ByteCode/Context.h b/clang/lib/AST/ByteCode/Context.h index 9a66226807e4e..235a4e44a9342 100644 --- a/clang/lib/AST/ByteCode/Context.h +++ b/clang/lib/AST/ByteCode/Context.h @@ -47,7 +47,7 @@ class EvalIDScope; class Context final { public: /// Initialises the constexpr VM. - Context(ASTContext &Ctx); + explicit Context(ASTContext &Ctx); /// Cleans up the constexpr VM. ~Context(); diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index 3e1aade65afc8..a7afd3008afb8 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -298,7 +298,7 @@ bool EvalEmitter::emitRetValue(SourceInfo Info) { return false; if (std::optional APV = - Ptr.toRValue(S.getASTContext(), EvalResult.getSourceType())) { + Ptr.toRValue(Ctx, EvalResult.getSourceType())) { EvalResult.takeValue(std::move(*APV)); return true; } diff --git a/clang/lib/AST/ByteCode/Function.h b/clang/lib/AST/ByteCode/Function.h index 862b0b4a0d746..d9a286937cadd 100644 --- a/clang/lib/AST/ByteCode/Function.h +++ b/clang/lib/AST/ByteCode/Function.h @@ -148,7 +148,7 @@ class Function final { } /// Returns a parameter descriptor. - ParamDescriptor getParamDescriptor(unsigned Index) const { + const ParamDescriptor &getParamDescriptor(unsigned Index) const { return ParamDescriptors[Index]; } diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 9c9318fe0e55a..209319d069b6f 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -121,19 +121,19 @@ void InterpFrame::destroy(unsigned Idx) { } template -static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx, +static void print(llvm::raw_ostream &OS, const T &V, const Context &Ctx, QualType Ty) { if constexpr (std::is_same_v) { if (Ty->isPointerOrReferenceType()) - V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty); + V.toAPValue(Ctx.getASTContext()).printPretty(OS, Ctx.getASTContext(), Ty); else { - if (std::optional RValue = V.toRValue(ASTCtx, Ty)) - RValue->printPretty(OS, ASTCtx, Ty); + if (std::optional RValue = V.toRValue(Ctx, Ty)) + RValue->printPretty(OS, Ctx.getASTContext(), Ty); else OS << "..."; } } else { - V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty); + V.toAPValue(Ctx.getASTContext()).printPretty(OS, Ctx.getASTContext(), Ty); } } @@ -159,9 +159,10 @@ void InterpFrame::describe(llvm::raw_ostream &OS) const { if (shouldSkipInBacktrace(Func)) return; + const ASTContext &ASTCtx = S.getASTContext(); const Expr *CallExpr = Caller->getExpr(getRetPC()); const FunctionDecl *F = getCallee(); - auto PrintingPolicy = S.getASTContext().getPrintingPolicy(); + auto PrintingPolicy = ASTCtx.getPrintingPolicy(); PrintingPolicy.SuppressLambdaBody = true; bool IsMemberCall = false; @@ -180,39 +181,38 @@ void InterpFrame::describe(llvm::raw_ostream &OS) const { if (Object->getType()->isPointerType()) OS << "->"; else - OS << "."; + OS << '.'; } else if (const auto *OCE = dyn_cast_if_present(CallExpr)) { OCE->getArg(0)->printPretty(OS, /*Helper=*/nullptr, PrintingPolicy, /*Indentation=*/0); - OS << "."; + OS << '.'; } else if (const auto *M = dyn_cast(F)) { - print(OS, getThis(), S.getASTContext(), - S.getASTContext().getLValueReferenceType( - S.getASTContext().getCanonicalTagType(M->getParent()))); - OS << "."; + print(OS, getThis(), S.getContext(), + ASTCtx.getLValueReferenceType( + ASTCtx.getCanonicalTagType(M->getParent()))); + OS << '.'; } } - F->getNameForDiagnostic(OS, PrintingPolicy, - /*Qualified=*/false); + F->getNameForDiagnostic(OS, PrintingPolicy, /*Qualified=*/false); OS << '('; unsigned Off = 0; - + unsigned ParamIndex = ExplicitInstanceParam; Off += Func->hasRVO() ? primSize(PT_Ptr) : 0; Off += Func->hasThisPointer() ? primSize(PT_Ptr) : 0; llvm::ListSeparator Comma; for (const ParmVarDecl *Param : F->parameters().slice(ExplicitInstanceParam)) { OS << Comma; - QualType Ty = Param->getType(); - PrimType PrimTy = S.Ctx.classify(Ty).value_or(PT_Ptr); - - TYPE_SWITCH(PrimTy, print(OS, stackRef(Off), S.getASTContext(), Ty)); - Off += align(primSize(PrimTy)); + PrimType PrimT = Func->getParamDescriptor(ParamIndex).T; + TYPE_SWITCH(PrimT, + print(OS, stackRef(Off), S.getContext(), Param->getType())); + Off += align(primSize(PrimT)); + ++ParamIndex; } - OS << ")"; + OS << ')'; } SourceRange InterpFrame::getCallRange() const {