Author: Timm Bäder Date: 2024-05-13T17:21:39+02:00 New Revision: 257013e4f5cbdf644646da9ec3d60d6209c9bf25
URL: https://github.com/llvm/llvm-project/commit/257013e4f5cbdf644646da9ec3d60d6209c9bf25 DIFF: https://github.com/llvm/llvm-project/commit/257013e4f5cbdf644646da9ec3d60d6209c9bf25.diff LOG: [clang][Interp] Handle VariableArrayTypes Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/Program.cpp clang/test/AST/Interp/arrays.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index c0eae5ab20ed6..7b10482dff23f 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2159,7 +2159,9 @@ bool ByteCodeExprGen<Emitter>::VisitCXXConstructExpr( if (T->isArrayType()) { const ConstantArrayType *CAT = Ctx.getASTContext().getAsConstantArrayType(E->getType()); - assert(CAT); + if (!CAT) + return false; + size_t NumElems = CAT->getZExtSize(); const Function *Func = getFunction(E->getConstructor()); if (!Func || !Func->isConstexpr()) diff --git a/clang/lib/AST/Interp/Program.cpp b/clang/lib/AST/Interp/Program.cpp index 87c767f85e799..6606149f1f697 100644 --- a/clang/lib/AST/Interp/Program.cpp +++ b/clang/lib/AST/Interp/Program.cpp @@ -386,7 +386,8 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty, // Array of unknown bounds - cannot be accessed and pointer arithmetic // is forbidden on pointers to such objects. - if (isa<IncompleteArrayType>(ArrayType)) { + if (isa<IncompleteArrayType>(ArrayType) || + isa<VariableArrayType>(ArrayType)) { if (std::optional<PrimType> T = Ctx.classify(ElemTy)) { return allocateDescriptor(D, *T, MDSize, IsTemporary, Descriptor::UnknownSize{}); diff --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp index abfcd09338ca2..70e87c4cd854b 100644 --- a/clang/test/AST/Interp/arrays.cpp +++ b/clang/test/AST/Interp/arrays.cpp @@ -560,6 +560,11 @@ namespace LocalVLA { // both-note@-4 {{function parameter 'size' with unknown value}} #endif } + + void f (unsigned int m) { + int e[2][m]; + e[0][0] = 0; + } } char melchizedek[2]; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits