@@ -175,6 +175,8 @@ bool handleFixedPointOverflow(InterpState &S, CodePtr OpPC,
175175
176176bool isConstexprUnknown (const Pointer &P);
177177
178+ inline bool CheckArraySize (InterpState &S, CodePtr OpPC, uint64_t NumElems);
179+
178180enum class ShiftDir { Left, Right };
179181
180182// / Checks if the shift operation is legal.
@@ -3110,6 +3112,9 @@ inline bool AllocN(InterpState &S, CodePtr OpPC, PrimType T, const Expr *Source,
31103112 }
31113113 assert (NumElements.isPositive ());
31123114
3115+ if (!CheckArraySize (S, OpPC, static_cast <uint64_t >(NumElements)))
3116+ return false ;
3117+
31133118 DynamicAllocator &Allocator = S.getAllocator ();
31143119 Block *B =
31153120 Allocator.allocate (Source, T, static_cast <size_t >(NumElements),
@@ -3140,6 +3145,9 @@ inline bool AllocCN(InterpState &S, CodePtr OpPC, const Descriptor *ElementDesc,
31403145 }
31413146 assert (NumElements.isPositive ());
31423147
3148+ if (!CheckArraySize (S, OpPC, static_cast <uint64_t >(NumElements)))
3149+ return false ;
3150+
31433151 DynamicAllocator &Allocator = S.getAllocator ();
31443152 Block *B =
31453153 Allocator.allocate (ElementDesc, static_cast <size_t >(NumElements),
@@ -3246,6 +3254,17 @@ inline bool CheckDestruction(InterpState &S, CodePtr OpPC) {
32463254 return CheckDestructor (S, OpPC, Ptr);
32473255}
32483256
3257+ inline bool CheckArraySize (InterpState &S, CodePtr OpPC, uint64_t NumElems) {
3258+ uint64_t Limit = S.getLangOpts ().ConstexprStepLimit ;
3259+ if (NumElems > Limit) {
3260+ S.FFDiag (S.Current ->getSource (OpPC),
3261+ diag::note_constexpr_new_exceeds_limits)
3262+ << NumElems << Limit;
3263+ return false ;
3264+ }
3265+ return true ;
3266+ }
3267+
32493268// ===----------------------------------------------------------------------===//
32503269// Read opcode arguments
32513270// ===----------------------------------------------------------------------===//
0 commit comments