aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorCongcong Cai <congcongcai0907@163.com>2025-09-04 22:28:42 +0800
committerGitHub <noreply@github.com>2025-09-04 14:28:42 +0000
commita3186bed6acdc85d1e121305a2537ee3353f3660 (patch)
tree0938205dfcd97a1d840af234481891bb727d56b9 /clang/lib/AST/ExprConstant.cpp
parent3e10bdd18e88fe971fc10398775077dfdcb3554b (diff)
downloadllvm-a3186bed6acdc85d1e121305a2537ee3353f3660.zip
llvm-a3186bed6acdc85d1e121305a2537ee3353f3660.tar.gz
llvm-a3186bed6acdc85d1e121305a2537ee3353f3660.tar.bz2
[clang][initlist] handle incomplete array type in Constant Expr Calculation (#155080)
fix: #151716 In #65918, support of incomplete array type is added in TryReferenceListInitialization. It causes the crash in Constant Expr Calculation since it only considers the case where it is ConstantArrayType. This patch wants to add support for incomplete array type also.
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 66362d4..f0592b0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -4030,10 +4030,12 @@ findSubobject(EvalInfo &Info, const Expr *E, const CompleteObject &Obj,
LastField = nullptr;
if (ObjType->isArrayType()) {
// Next subobject is an array element.
- const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(ObjType);
- assert(CAT && "vla in literal type?");
+ const ArrayType *AT = Info.Ctx.getAsArrayType(ObjType);
+ assert((isa<ConstantArrayType>(AT) || isa<IncompleteArrayType>(AT)) &&
+ "vla in literal type?");
uint64_t Index = Sub.Entries[I].getAsArrayIndex();
- if (CAT->getSize().ule(Index)) {
+ if (const auto *CAT = dyn_cast<ConstantArrayType>(AT);
+ CAT && CAT->getSize().ule(Index)) {
// Note, it should not be possible to form a pointer with a valid
// designator which points more than one past the end of the array.
if (Info.getLangOpts().CPlusPlus11)
@@ -4044,12 +4046,13 @@ findSubobject(EvalInfo &Info, const Expr *E, const CompleteObject &Obj,
return handler.failed();
}
- ObjType = CAT->getElementType();
+ ObjType = AT->getElementType();
if (O->getArrayInitializedElts() > Index)
O = &O->getArrayInitializedElt(Index);
else if (!isRead(handler.AccessKind)) {
- if (!CheckArraySize(Info, CAT, E->getExprLoc()))
+ if (const auto *CAT = dyn_cast<ConstantArrayType>(AT);
+ CAT && !CheckArraySize(Info, CAT, E->getExprLoc()))
return handler.failed();
expandArray(*O, Index);