[PATCH] D136532: [clang][Interp] Implement left and right shifts

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 24 08:13:07 PDT 2022


aaron.ballman added inline comments.


================
Comment at: clang/lib/AST/Interp/Interp.h:1236-1237
 inline bool ShiftRight(InterpState &S, CodePtr OpPC, const T &V, unsigned RHS) {
   if (RHS >= V.bitWidth()) {
     S.Stk.push<T>(T::from(0, V.bitWidth()));
   } else {
----------------
This doesn't seem to match: https://eel.is/c++draft/expr.shift#1.sentence-4


================
Comment at: clang/lib/AST/Interp/Interp.h:1246-1256
   if (V.isSigned() && !S.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 (V.isNegative()) {
       const Expr *E = S.Current->getExpr(OpPC);
----------------
Why do `Shr` and `Shl` check for a negative shift amount to issue a diagnostic but we check for signed in `ShiftLeft` to issue a diagnostic? (I would have expected the checks to all live in the same place.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136532/new/

https://reviews.llvm.org/D136532



More information about the cfe-commits mailing list