[clang] [ExprConstant] Handle shift overflow the same way as other kinds of overflow (PR #99579)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 18 16:47:09 PDT 2024
================
@@ -2849,19 +2849,23 @@ static bool handleIntIntBinOp(EvalInfo &Info, const BinaryOperator *E,
if (SA != RHS) {
Info.CCEDiag(E, diag::note_constexpr_large_shift)
<< RHS << E->getType() << LHS.getBitWidth();
+ if (!Info.noteUndefinedBehavior())
+ return false;
} else if (LHS.isSigned() && !Info.getLangOpts().CPlusPlus20) {
// C++11 [expr.shift]p2: A signed left shift must have a non-negative
// operand, and must not overflow the corresponding unsigned type.
// C++2a [expr.shift]p2: E1 << E2 is the unique value congruent to
// E1 x 2^E2 module 2^N.
- if (LHS.isNegative())
+ if (LHS.isNegative()) {
Info.CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS;
- else if (LHS.countl_zero() < SA)
+ if (!Info.noteUndefinedBehavior())
+ return false;
+ } else if (LHS.countl_zero() < SA) {
----------------
efriedma-quic wrote:
This code is under a `LHS.isSigned() && !Info.getLangOpts().CPlusPlus20` guard.
https://github.com/llvm/llvm-project/pull/99579
More information about the cfe-commits
mailing list