@@ -175,6 +175,8 @@ bool handleFixedPointOverflow(InterpState &S, CodePtr OpPC,
175
175
176
176
bool isConstexprUnknown (const Pointer &P);
177
177
178
+ inline bool CheckArraySize (InterpState &S, CodePtr OpPC, uint64_t NumElems);
179
+
178
180
enum class ShiftDir { Left, Right };
179
181
180
182
// / Checks if the shift operation is legal.
@@ -3110,6 +3112,9 @@ inline bool AllocN(InterpState &S, CodePtr OpPC, PrimType T, const Expr *Source,
3110
3112
}
3111
3113
assert (NumElements.isPositive ());
3112
3114
3115
+ if (!CheckArraySize (S, OpPC, static_cast <uint64_t >(NumElements)))
3116
+ return false ;
3117
+
3113
3118
DynamicAllocator &Allocator = S.getAllocator ();
3114
3119
Block *B =
3115
3120
Allocator.allocate (Source, T, static_cast <size_t >(NumElements),
@@ -3140,6 +3145,9 @@ inline bool AllocCN(InterpState &S, CodePtr OpPC, const Descriptor *ElementDesc,
3140
3145
}
3141
3146
assert (NumElements.isPositive ());
3142
3147
3148
+ if (!CheckArraySize (S, OpPC, static_cast <uint64_t >(NumElements)))
3149
+ return false ;
3150
+
3143
3151
DynamicAllocator &Allocator = S.getAllocator ();
3144
3152
Block *B =
3145
3153
Allocator.allocate (ElementDesc, static_cast <size_t >(NumElements),
@@ -3246,6 +3254,17 @@ inline bool CheckDestruction(InterpState &S, CodePtr OpPC) {
3246
3254
return CheckDestructor (S, OpPC, Ptr);
3247
3255
}
3248
3256
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
+
3249
3268
// ===----------------------------------------------------------------------===//
3250
3269
// Read opcode arguments
3251
3270
// ===----------------------------------------------------------------------===//
0 commit comments