From 15579a8e72589b4fdf45c8f5bca52e58dcc9ce1d Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Tue, 29 Apr 2025 05:47:22 +0200 Subject: [clang][bytecode] Check array sizes against step limit (#137679) --- clang/lib/AST/ByteCode/Compiler.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'clang/lib/AST/ByteCode/Compiler.cpp') diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 9a1e61b..fe8d05c 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -1862,6 +1862,13 @@ bool Compiler::visitInitList(ArrayRef Inits, if (Inits.size() == 1 && QT == Inits[0]->getType()) return this->delegate(Inits[0]); + const ConstantArrayType *CAT = + Ctx.getASTContext().getAsConstantArrayType(QT); + uint64_t NumElems = CAT->getZExtSize(); + + if (!this->emitCheckArraySize(NumElems, E)) + return false; + unsigned ElementIndex = 0; for (const Expr *Init : Inits) { if (const auto *EmbedS = @@ -1890,10 +1897,6 @@ bool Compiler::visitInitList(ArrayRef Inits, // Expand the filler expression. // FIXME: This should go away. if (ArrayFiller) { - const ConstantArrayType *CAT = - Ctx.getASTContext().getAsConstantArrayType(QT); - uint64_t NumElems = CAT->getZExtSize(); - for (; ElementIndex != NumElems; ++ElementIndex) { if (!this->visitArrayElemInit(ElementIndex, ArrayFiller)) return false; -- cgit v1.1