https://github.com/Kristianerik updated https://github.com/llvm/llvm-project/pull/229556
>From f03b9c847831425b254e67a7d85988fe9b87b92f Mon Sep 17 00:00:00 2001 From: Kristianerik <[email protected]> Date: Tue, 6 Oct 2026 13:23:50 -0700 Subject: [PATCH] [Sema] Fix crash constant-evaluating large arrays with initializer list or string literal --- clang/lib/AST/ExprConstant.cpp | 11 +++++++++-- clang/test/Sema/gh227533.c | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 clang/test/Sema/gh227533.c diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 34c3e39807c7f..b82caab970647 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15627,10 +15627,14 @@ namespace { bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E); bool VisitCXXConstructExpr(const CXXConstructExpr *E); bool VisitCXXConstructExpr(const CXXConstructExpr *E, - const LValue &Subobject, - APValue *Value, QualType Type); + const LValue &Subobject, APValue *Value, + QualType Type); bool VisitStringLiteral(const StringLiteral *E, QualType AllocType = QualType()) { + const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType( + AllocType.isNull() ? E->getType() : AllocType); + if (!CheckArraySize(Info, CAT, E->getExprLoc())) + return false; expandStringLiteral(Info, E, Result, AllocType); return true; } @@ -15770,6 +15774,9 @@ bool ArrayExprEvaluator::VisitCXXParenListOrInitListExpr( bool Success = true; + if (!CheckArraySize(Info, CAT, ExprToVisit->getExprLoc())) + return false; + unsigned NumEltsToInit = Args.size(); unsigned NumElts = CAT->getZExtSize(); diff --git a/clang/test/Sema/gh227533.c b/clang/test/Sema/gh227533.c new file mode 100644 index 0000000000000..3281b7c20d403 --- /dev/null +++ b/clang/test/Sema/gh227533.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s +// expected-no-diagnostics + +const char a[4294967296] = {0}; +int b(void) { return a[1]; } + +const char c[4294967296] = "x"; +int d(void) { return c[1]; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
