[clang] [Sema] Fixed faulty shift count warning (PR #69521)
Björn Pettersson via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 19 04:12:06 PDT 2023
================
@@ -12120,8 +12120,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS,
auto FXSema = S.Context.getFixedPointSemantics(LHSExprType);
LeftSize = FXSema.getWidth() - (unsigned)FXSema.hasUnsignedPadding();
}
- llvm::APInt LeftBits(Right.getBitWidth(), LeftSize);
- if (Right.uge(LeftBits)) {
+ if (Right.uge(LeftSize)) {
----------------
bjope wrote:
I tried to understand why the old code used an APInt here.
What if you have something like ` x >> larger_than_64_bits_value`? I suspect that then the uge helper here will do a 64-bit unsigned compare. So it will truncate `Right` to 64 bits instead, right?
So I think the easiest way would be to compare to APInt:s. But make sure those are zero-extended to have a common size.
Maybe something like this:
```
unsigned CompareBits = std::max(Right.getBitWidth(), 64);
llvm::APInt LeftBits(CompareBits, LeftSize);
if (Right.zext(CompareBits).uge(LeftBits)) {
```
https://github.com/llvm/llvm-project/pull/69521
More information about the cfe-commits
mailing list