llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: None (Tsche) <details> <summary>Changes</summary> To address @<!-- -->AaronBallman's feedback from https://github.com/llvm/llvm-project/pull/143785 this patch implements an explicit opt-out for `-fconstexpr-steps` by setting `-fconstexpr-steps=0`. This does not change any defaults, but gives users an easy way to opt out of this limit altogether (and instead let the compiler reach the system's resource limits). Currently users set `constexpr-steps` to some arbitrary high number (and I mean _arbitrary_ - see the tables in the previous PR). This isn't actually opting out of the limit though - you're still bound by the upper bound of the counter's type. If you have enough resources to evaluate more than 18446744073709551615 steps that's bad news. In any case, `=0` conveys the intent clearer. This is in line with how we handle other flags, ie `-ftemplate-backtrace-limit` or `-ferror-limit`. Please advise if a similar opt-out would be desirable for `-fconstexpr-depth` (and possibly `-ftemplate-depth`?). --- Full diff: https://github.com/llvm/llvm-project/pull/160440.diff 3 Files Affected: - (modified) clang/docs/UsersManual.rst (+1-1) - (modified) clang/lib/AST/ByteCode/Interp.h (+3) - (modified) clang/lib/AST/ExprConstant.cpp (+4-1) ``````````diff diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index a8bbf146431ea..1a062475728dd 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -4028,7 +4028,7 @@ Controlling implementation limits Sets the limit for the number of full-expressions evaluated in a single constant expression evaluation. This also controls the maximum size of array and dynamic array allocation that can be constant evaluated. - The default is 1048576. + The default is 1048576, and the limit can be disabled with `-fconstexpr-steps=0`.. .. option:: -ftemplate-depth=N diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index b3b4b998439cc..deba2d294abe9 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -3686,6 +3686,9 @@ inline bool CheckDestruction(InterpState &S, CodePtr OpPC) { inline bool CheckArraySize(InterpState &S, CodePtr OpPC, uint64_t NumElems) { uint64_t Limit = S.getLangOpts().ConstexprStepLimit; + if (Limit == 0) + return true; + if (NumElems > Limit) { S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_new_exceeds_limits) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index d10e2afeb2341..0fe3fce5b64a8 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -990,7 +990,7 @@ namespace { // of arrays to avoid exhausting the system resources, as initialization // of each element is likely to take some number of steps anyway. uint64_t Limit = Ctx.getLangOpts().ConstexprStepLimit; - if (ElemCount > Limit) { + if (Limit != 0 && ElemCount > Limit) { if (Diag) FFDiag(Loc, diag::note_constexpr_new_exceeds_limits) << ElemCount << Limit; @@ -1016,6 +1016,9 @@ namespace { } bool nextStep(const Stmt *S) { + if (Ctx.getLangOpts().ConstexprStepLimit == 0) + return true; + if (!StepsLeft) { FFDiag(S->getBeginLoc(), diag::note_constexpr_step_limit_exceeded); return false; `````````` </details> https://github.com/llvm/llvm-project/pull/160440 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits