Changeset 259704 in webkit


Ignore:
Timestamp:
Apr 7, 2020 10:46:25 PM (4 years ago)
Author:
Fujii Hironori
Message:

[Clang 10] Fix -Wimplicit-int-float-conversion compilation warnings in TestWebKitAPI
https://bugs.webkit.org/show_bug.cgi?id=210067

Reviewed by Darin Adler.

There are test cases for overflow, non-overflow, underflow and
non-underflow edge cases in WTF.clampToIntegerFloat test.
maxPlusOne<int> can be used for overflow edge case, INT_MIN for
non-underflow. This change added code to calculate values for
non-overflow and underflow cases.

  • TestWebKitAPI/Tests/WTF/MathExtras.cpp:

(TestWebKitAPI::TEST(WTF.clampToIntegerFloat)):

  • TestWebKitAPI/Tests/WebCore/FloatRect.cpp:

(TestWebKitAPI::TEST(FloatRect.EnclosingIntRect)): Replaced
shiftMaxXEdgeTo(INT_MAX) with shiftMaxXEdgeTo(0) because it also
causes overflow for enclosingIntRect.

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r259699 r259704  
     12020-04-07  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        [Clang 10] Fix -Wimplicit-int-float-conversion compilation warnings in TestWebKitAPI
     4        https://bugs.webkit.org/show_bug.cgi?id=210067
     5
     6        Reviewed by Darin Adler.
     7
     8        There are test cases for overflow, non-overflow, underflow and
     9        non-underflow edge cases in WTF.clampToIntegerFloat test.
     10        maxPlusOne<int> can be used for overflow edge case, INT_MIN for
     11        non-underflow. This change added code to calculate values for
     12        non-overflow and underflow cases.
     13
     14        * TestWebKitAPI/Tests/WTF/MathExtras.cpp:
     15        (TestWebKitAPI::TEST(WTF.clampToIntegerFloat)):
     16        * TestWebKitAPI/Tests/WebCore/FloatRect.cpp:
     17        (TestWebKitAPI::TEST(FloatRect.EnclosingIntRect)): Replaced
     18        shiftMaxXEdgeTo(INT_MAX) with shiftMaxXEdgeTo(0) because it also
     19        causes overflow for enclosingIntRect.
     20
    1212020-04-07  Aakash Jain  <aakash_jain@apple.com>
    222
  • trunk/Tools/TestWebKitAPI/Tests/WTF/MathExtras.cpp

    r245214 r259704  
    9494    // due to the narrow mantissa. However it will properly checks within
    9595    // (close to the extreme) and outside the integer range.
    96     float maxInt = std::numeric_limits<int>::max();
     96    float overflowInt = maxPlusOne<int>;
     97    float maxInt = overflowInt;
     98    for (int i = 0; overflowInt == maxInt; i++)
     99        maxInt = overflowInt - i;
     100
    97101    float minInt = std::numeric_limits<int>::min();
    98     float overflowInt = maxInt * 1.1;
    99     float underflowInt = minInt * 1.1;
     102    float underflowInt = minInt;
     103    for (int i = 0; underflowInt == minInt; i++)
     104        underflowInt = minInt - i;
    100105
    101106    EXPECT_GT(overflowInt, maxInt);
    102107    EXPECT_LT(underflowInt, minInt);
    103108
    104     // If maxInt == 2^31 - 1 (ie on I32 architecture), the closest float used to represent it is 2^31.
    105     EXPECT_NEAR(clampToInteger(maxInt), maxInt, 1);
    106     EXPECT_EQ(clampToInteger(minInt), minInt);
    107 
    108     EXPECT_NEAR(clampToInteger(overflowInt), maxInt, 1);
    109     EXPECT_EQ(clampToInteger(underflowInt), minInt);
     109    EXPECT_EQ(clampToInteger(maxInt), static_cast<int>(maxInt));
     110    EXPECT_EQ(clampToInteger(minInt), std::numeric_limits<int>::min());
     111
     112    EXPECT_EQ(clampToInteger(overflowInt), std::numeric_limits<int>::max());
     113    EXPECT_EQ(clampToInteger(underflowInt), std::numeric_limits<int>::min());
    110114}
    111115
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/FloatRect.cpp

    r245179 r259704  
    771771
    772772    WebCore::FloatRect maxIntRect(INT_MIN, INT_MIN, 0, 0);
    773     maxIntRect.shiftMaxXEdgeTo(INT_MAX);
    774     maxIntRect.shiftMaxYEdgeTo(INT_MAX);
     773    maxIntRect.shiftMaxXEdgeTo(30);
     774    maxIntRect.shiftMaxYEdgeTo(30);
    775775
    776776    auto enclosed2 = WebCore::enclosingIntRect(maxIntRect);
Note: See TracChangeset for help on using the changeset viewer.