src/compiler/translator/ConstantUnion.cpp


Log

Author Commit Date CI Message
Olli Etuaho 4310354e 2016-10-10T12:28:13 Handle corner cases of shifting signed integers better Right-shifting a negative number should sign-extend according to the ESSL 3.00.6 spec. Implement sign-extending right shift so that it doesn't hit any undefined behavior in the C++ spec. Negative lhs operands are now allowed for bit-shift right. Also implement bit-shift left via conversion to unsigned integer, so that it does not hit signed integer overflow. Negative lhs operands are now allowed also for bit-shift left as well. BUG=chromium:654103 TEST=angle_unittests Change-Id: Iee241de9fd0d74c2f8a88219bddec690bb8e4db2 Reviewed-on: https://chromium-review.googlesource.com/395688 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Geoff Lang <geofflang@chromium.org>
Olli Etuaho 7f9a55f7 2016-10-03T14:32:08 Fix integer math overflows in the preprocessor Evaluating integer expressions in the ESSL preprocessor may result in overflowing the signed integer range. Implement wrapping overflow for preprocessor expressions in a way that doesn't hit any undefined behavior. In the ESSL spec, preprocessor expressions are defined to have mostly the same semantics as in C++. Since C++ doesn't define what happens on signed integer overflow, we choose to make most of the operators wrap on overflow for backward compatibility and consistency with the rest of the ESSL spec. We reuse the existing wrapping overflow helpers that are used for constant folding. To be able to do this, the type used in the preprocessor expression parser is changed from 64-bit to 32-bit. Shifting negative numbers is implemented as a logical shift. This cannot be disallowed since dEQP requires shaders shifting negative numbers to pass compilation. Undefined bitwise shifts where the offset is greater than 31 will now result in a compile-time error. A couple of test cases are now covered by the preprocessor tests rather than full compilation tests. This isolates the tests better and they run faster. BUG=chromium:652223 TEST=angle_unittests Change-Id: I84be40d404c10ecd0846c5d477e626a94a2a8587 Reviewed-on: https://chromium-review.googlesource.com/392146 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Olli Etuaho 1be4d493 2016-09-27T11:15:38 Fix handling integer overflow in constant folding Integer operations that overflow are defined to wrap in the ESSL 3.00.6 spec. Constant folding that happens inside the shader translator should also follow the wrapping rules. The new implementations of wrapping integer addition and subtraction use unsigned integers to perform calculations. Unsigned integers are defined to implement arithmetic in modulo 2^n in the C++ spec. This behavior is also leveraged to implement wrapping unsigned integer multiplication. The implementation of wrapping signed integer multiplication is slightly trickier. The operands are casted to a wider type to perform the multiplication in a way that doesn't overflow, and then the result is truncated and casted back to the narrower integer type. Incorrect tests that expected errors to be generated from integer overflow in constant folding are removed. BUG=chromium:637050 TEST=angle_unittests Change-Id: I0de7e25881d254803455fbf22907c192f49d09ff Reviewed-on: https://chromium-review.googlesource.com/390252 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Olli Etuaho 2cacb778 2016-09-26T08:50:40 Fix folding shifts when operands have different signedness The code used to incorrectly assert that the right-hand side of shift should have the same signedness as the left-hand side. Instead simply assert that both the lhs and rhs are integer typed, and also don't rely on aliasing via union when accessing bit shift operands. Also disallow constant folded bit shifts where the right hand side is greater than 31. Shifting with values greater than the width of the type has undefined results in both ESSL and C++. BUG=chromium:648135 TEST=angle_unittests Change-Id: I84a99abc55f0eeda549b4781e954d17ba7b87552 Reviewed-on: https://chromium-review.googlesource.com/389351 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Jamie Madill 44ebf6b4 2016-09-22T13:00:02 ConstantUnion: Error on undefined shift. BUG=chromium:648135 Change-Id: I41581f63af650564a0f61c1baeeb38017c8513ed Reviewed-on: https://chromium-review.googlesource.com/387470 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Jamie Madill 596018ce 2016-09-21T12:57:03 translator: Refactor Constant Union shift ops. In preparation for making them robust. BUG=chromium:648135 Change-Id: I88fc87d8887064fda04087c56de05d8725a6fe5f Reviewed-on: https://chromium-review.googlesource.com/387469 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Jamie Madill 5db69f57 2016-09-15T12:47:32 Add robust math to constant folding. Previously our multiplication and other operators could do overflows, which can lead to security bugs. BUG=chromium:637050 Change-Id: Icee22a87909e205b71bda1c5bc1627fcf5e26e90 Reviewed-on: https://chromium-review.googlesource.com/382678 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Jamie Madill 47cb73ab 2016-09-09T11:41:44 Refactor TConstantUnion. In preparation for constant folding fixes. BUG=chromium:637050 Change-Id: I9ea49ce96b34c6ac3d2f0478b8fc6732c59e28be Reviewed-on: https://chromium-review.googlesource.com/373741 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>