Skip to content

Commit a9d97d4

Browse files
committed
[clang] introduce constexpr step limit opt-out
1 parent b1e00f6 commit a9d97d4

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

clang/docs/UsersManual.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4028,7 +4028,7 @@ Controlling implementation limits
40284028
Sets the limit for the number of full-expressions evaluated in a single
40294029
constant expression evaluation. This also controls the maximum size
40304030
of array and dynamic array allocation that can be constant evaluated.
4031-
The default is 1048576.
4031+
The default is 1048576, and the limit can be disabled with `-fconstexpr-steps=0`..
40324032

40334033
.. option:: -ftemplate-depth=N
40344034

clang/lib/AST/ByteCode/Interp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3686,6 +3686,9 @@ inline bool CheckDestruction(InterpState &S, CodePtr OpPC) {
36863686

36873687
inline bool CheckArraySize(InterpState &S, CodePtr OpPC, uint64_t NumElems) {
36883688
uint64_t Limit = S.getLangOpts().ConstexprStepLimit;
3689+
if (Limit == 0)
3690+
return true;
3691+
36893692
if (NumElems > Limit) {
36903693
S.FFDiag(S.Current->getSource(OpPC),
36913694
diag::note_constexpr_new_exceeds_limits)

clang/lib/AST/ExprConstant.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ namespace {
990990
// of arrays to avoid exhausting the system resources, as initialization
991991
// of each element is likely to take some number of steps anyway.
992992
uint64_t Limit = Ctx.getLangOpts().ConstexprStepLimit;
993-
if (ElemCount > Limit) {
993+
if (Limit != 0 && ElemCount > Limit) {
994994
if (Diag)
995995
FFDiag(Loc, diag::note_constexpr_new_exceeds_limits)
996996
<< ElemCount << Limit;
@@ -1016,6 +1016,9 @@ namespace {
10161016
}
10171017

10181018
bool nextStep(const Stmt *S) {
1019+
if (Ctx.getLangOpts().ConstexprStepLimit == 0)
1020+
return true;
1021+
10191022
if (!StepsLeft) {
10201023
FFDiag(S->getBeginLoc(), diag::note_constexpr_step_limit_exceeded);
10211024
return false;

0 commit comments

Comments
 (0)