Path: blob/main_old/src/tests/compiler_tests/ConstantFoldingOverflow_test.cpp
1693 views
//1// Copyright 2016 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// ConstantFoldingOverflow_test.cpp:6// Tests for constant folding that results in floating point overflow.7// In IEEE floating point, the overflow result depends on which of the various rounding modes is8// chosen - it's either the maximum representable value or infinity.9// ESSL 3.00.6 section 4.5.1 says that the rounding mode cannot be set and is undefined, so the10// result in this case is not defined by the spec.11// We decide to overflow to infinity and issue a warning.12//1314#include "tests/test_utils/ConstantFoldingTest.h"1516using namespace sh;1718namespace19{2021class ConstantFoldingOverflowExpressionTest : public ConstantFoldingExpressionTest22{23public:24ConstantFoldingOverflowExpressionTest() {}2526void evaluateFloatOverflow(const std::string &floatString, bool positive)27{28evaluateFloat(floatString);29float expected = positive ? std::numeric_limits<float>::infinity()30: -std::numeric_limits<float>::infinity();31ASSERT_TRUE(constantFoundInAST(expected));32ASSERT_TRUE(hasWarning());33}34};3536} // anonymous namespace3738// Test that addition that overflows is evaluated correctly.39TEST_F(ConstantFoldingOverflowExpressionTest, Add)40{41const std::string &floatString = "2.0e38 + 2.0e38";42evaluateFloatOverflow(floatString, true);43}4445// Test that subtraction that overflows is evaluated correctly.46TEST_F(ConstantFoldingOverflowExpressionTest, Subtract)47{48const std::string &floatString = "2.0e38 - (-2.0e38)";49evaluateFloatOverflow(floatString, true);50}5152// Test that multiplication that overflows is evaluated correctly.53TEST_F(ConstantFoldingOverflowExpressionTest, Multiply)54{55const std::string &floatString = "1.0e30 * 1.0e10";56evaluateFloatOverflow(floatString, true);57}5859// Test that division that overflows is evaluated correctly.60TEST_F(ConstantFoldingOverflowExpressionTest, Divide)61{62const std::string &floatString = "1.0e30 / 1.0e-10";63evaluateFloatOverflow(floatString, true);64}656667