Skip to content

Commit

Permalink
GLSL: Fix integer overflow warnings in Constant.cpp
Browse files Browse the repository at this point in the history
New versions of Clang warn:

```
glslang/MachineIndependent/Constant.cpp(216,114):
error: overflow in expression; result is -9223372036854775808 with type 'long long' [-Werror,-Winteger-overflow]
                else if (rightUnionArray[i].getI64Const() == -1 && leftUnionArray[i].getI64Const() == (long long)-0x8000000000000000ll)
                                                                                                                 ^
glslang/MachineIndependent/Constant.cpp(217,61):
error: overflow in expression; result is -9223372036854775808 with type 'long long' [-Werror,-Winteger-overflow]
                    newConstArray[i].setI64Const((long long)-0x8000000000000000ll);
                                                            ^
2 errors generated.
```

Using LLONG_MIN instead avoids the problem. I think it's also more
clear, and the code for EOpMod further down already does this.
  • Loading branch information
zmodem authored and jeremy-lunarg committed Feb 2, 2023
1 parent 5137ce1 commit 7341a21
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions glslang/MachineIndependent/Constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* right

case EbtInt64:
if (rightUnionArray[i] == 0ll)
newConstArray[i].setI64Const(0x7FFFFFFFFFFFFFFFll);
else if (rightUnionArray[i].getI64Const() == -1 && leftUnionArray[i].getI64Const() == (long long)-0x8000000000000000ll)
newConstArray[i].setI64Const((long long)-0x8000000000000000ll);
newConstArray[i].setI64Const(LLONG_MAX);
else if (rightUnionArray[i].getI64Const() == -1 && leftUnionArray[i].getI64Const() == LLONG_MIN)
newConstArray[i].setI64Const(LLONG_MIN);
else
newConstArray[i].setI64Const(leftUnionArray[i].getI64Const() / rightUnionArray[i].getI64Const());
break;
Expand Down

0 comments on commit 7341a21

Please sign in to comment.