[PATCH] D156466: [clang][CGExprConstant] handle implicit widening/narrowing Int-to-Int casts

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 2 15:53:50 PDT 2023


efriedma added inline comments.


================
Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1152
+              return CI;
+            llvm::APInt A = CI->getValue().sextOrTrunc(DstWidth);
+            return llvm::ConstantInt::get(CGM.getLLVMContext(), A);
----------------
sextOrTrunc() is, in general, wrong; if FromType is unsigned, you need zextOrTrunc.  (This works transparently in HandleIntToIntCast because it's using APSInt, which tracks the sign bit of the operand.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156466



More information about the cfe-commits mailing list