https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/212722
Decls already have a reference to the ASTContext, so no need to pass another one. >From f9cbae9938d8b9e3960ec036691ffb44e85eca50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Wed, 29 Jul 2026 11:09:26 +0200 Subject: [PATCH] [clang][AST] Remove ASTContext parameter from getFlexibleArrayInitChars Decls already have a reference to the ASTContext, so no need to pass another one. --- clang/include/clang/AST/Decl.h | 2 +- clang/lib/AST/Decl.cpp | 4 +++- clang/lib/AST/ExprConstant.cpp | 2 +- clang/lib/CodeGen/CGDecl.cpp | 2 +- clang/lib/CodeGen/CodeGenModule.cpp | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 0a6f256afa2cc..421005c25d35d 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -1737,7 +1737,7 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> { /// necessary to store those elements. Otherwise, returns zero. /// /// This can only be called for declarations where hasInit() is true. - CharUnits getFlexibleArrayInitChars(const ASTContext &Ctx) const; + CharUnits getFlexibleArrayInitChars() const; /// Apply a deduced address space, if one isn't already set. void assignAddressSpace(const ASTContext &Ctxt, LangAS AS); diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 5a76a726cd1f1..cf50ec78e4b15 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2837,7 +2837,7 @@ bool VarDecl::hasFlexibleArrayInit(const ASTContext &Ctx) const { return !InitTy->isZeroSize(); } -CharUnits VarDecl::getFlexibleArrayInitChars(const ASTContext &Ctx) const { +CharUnits VarDecl::getFlexibleArrayInitChars() const { assert(hasInit() && "Expect initializer to check for flexible array init"); auto *RD = getType()->getAsRecordDecl(); if (!RD || !RD->hasFlexibleArrayMember()) @@ -2845,6 +2845,8 @@ CharUnits VarDecl::getFlexibleArrayInitChars(const ASTContext &Ctx) const { auto *List = dyn_cast<InitListExpr>(getInit()->IgnoreParens()); if (!List || List->getNumInits() == 0) return CharUnits::Zero(); + + const ASTContext &Ctx = getASTContext(); const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1); auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType()); if (!InitTy) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 9d69de2a7c6fd..b6ae9ed964034 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -16684,7 +16684,7 @@ static void addFlexibleArrayMemberInitSize(EvalInfo &Info, const QualType &T, if (const auto *V = LV.getLValueBase().dyn_cast<const ValueDecl *>()) if (const auto *VD = dyn_cast<VarDecl>(V)) if (VD->hasInit()) - Size += VD->getFlexibleArrayInitChars(Info.Ctx); + Size += VD->getFlexibleArrayInitChars(); } /// Helper for tryEvaluateBuiltinObjectSize -- Given an LValue, this will diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 29bc47130c4cd..34d55a878b947 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -384,7 +384,7 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D, #ifndef NDEBUG CharUnits VarSize = CGM.getContext().getTypeSizeInChars(D.getType()) + - D.getFlexibleArrayInitChars(getContext()); + D.getFlexibleArrayInitChars(); CharUnits CstSize = CharUnits::fromQuantity( CGM.getDataLayout().getTypeAllocSize(Init->getType())); assert(VarSize == CstSize && "Emitted constant has unexpected size"); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e7c1d182fd20d..03a0620ecaafe 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -6479,7 +6479,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, #ifndef NDEBUG CharUnits VarSize = getContext().getTypeSizeInChars(ASTTy) + - InitDecl->getFlexibleArrayInitChars(getContext()); + InitDecl->getFlexibleArrayInitChars(); CharUnits CstSize = CharUnits::fromQuantity( getDataLayout().getTypeAllocSize(Init->getType())); assert(VarSize == CstSize && "Emitted constant has unexpected size"); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
