[clang] [clang][initlist] handle incomplete array type in Constant Expr Calculation (PR #155080)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 27 02:51:09 PDT 2025


================
@@ -4029,10 +4029,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 (isa<ConstantArrayType>(AT) &&
+          cast<ConstantArrayType>(AT)->getSize().ule(Index)) {
----------------
Fznamznon wrote:

isa and cast does isa two times. AFAIK llvm coding guide recommends to avoid that. Can we do
```suggestion
      if (auto *CAT = dyn_cast<ConstantArrayType>(AT); CAT && CAT->getSize().ule(Index)) {
```

https://github.com/llvm/llvm-project/pull/155080


More information about the cfe-commits mailing list