Skip to content

Commit

Permalink
Merge pull request KhronosGroup#2655 from ShabbyX/fix-ubsan
Browse files Browse the repository at this point in the history
Fix UBSAN error with negating 0x8000'0000
  • Loading branch information
greg-lunarg authored Jun 4, 2021
2 parents 6bdcb4b + 10a7137 commit de2cb9d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion glslang/MachineIndependent/Constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType)
case EbtDouble:
case EbtFloat16:
case EbtFloat: newConstArray[i].setDConst(-unionArray[i].getDConst()); break;
case EbtInt: newConstArray[i].setIConst(-unionArray[i].getIConst()); break;
// Note: avoid UBSAN error regarding negating 0x80000000
case EbtInt: newConstArray[i].setIConst(
unionArray[i].getIConst() == 0x80000000
? -0x7FFFFFFF - 1
: -unionArray[i].getIConst());
break;
case EbtUint: newConstArray[i].setUConst(static_cast<unsigned int>(-static_cast<int>(unionArray[i].getUConst()))); break;
#ifndef GLSLANG_WEB
case EbtInt8: newConstArray[i].setI8Const(-unionArray[i].getI8Const()); break;
Expand Down

0 comments on commit de2cb9d

Please sign in to comment.