[PATCH] D140455: [Clang] Diagnose undefined behavior in a constant expression while evaluating a compound assignment with remainder as operand
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 9 12:23:36 PST 2023
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.
LGTM aside from some style nits. Can you also add a release note for the fix?
================
Comment at: clang/lib/AST/ExprConstant.cpp:2759-2760
APSInt &Result) {
+ bool HandleOverflowResult = true;
switch (Opcode) {
default:
----------------
================
Comment at: clang/lib/AST/ExprConstant.cpp:2777-2789
case BO_Rem:
if (RHS == 0) {
Info.FFDiag(E, diag::note_expr_divide_by_zero);
return false;
}
- Result = (Opcode == BO_Rem ? LHS % RHS : LHS / RHS);
// Check for overflow case: INT_MIN / -1 or INT_MIN % -1. APSInt supports
// this operation and gives the two's complement result.
----------------
================
Comment at: clang/test/CXX/expr/expr.const/p2-0x.cpp:304
+namespace CompoundAssignment {
+int constexpr rem() { // expected-error {{constexpr function never produces a constant expression}}
+ int x = ~__INT_MAX__;
----------------
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140455/new/
https://reviews.llvm.org/D140455
More information about the cfe-commits
mailing list