Skip to content

Commit

Permalink
guard against INF values in CompactValue
Browse files Browse the repository at this point in the history
Summary:
After this diff D13403925 that got rid of `-ffast-math` we started to have a very odd behavior on Yoga when using release builds.

After digging a while we found that certain set of conditions on O2 and O3 optimization levels was causing Origami to set some `INFINITE` values on Yoga.

We found the root of the problem and fix it on Origami side. But I'm wondering if guarding agains `INFINITE` on Yoga side would be good too. Since now Yoga it's not using `-ffast-math` anymore, and I think infinite is not a a valid value anywhere on Yoga side, it seems to support the reason to guard against it.

I'm happy to abandon this diff if you guys think this is not a good solution.

Reviewed By: davidaurelio

Differential Revision: D13679319

fbshipit-source-id: 061448fea9d1a8496362ff07dc46b546e7f1ffa3
  • Loading branch information
Eduardo Roman authored and facebook-github-bot committed Jan 16, 2019
1 parent 71321f7 commit 604a9a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/CompactValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ TEST(YogaTest, compact_value_can_represent_undefined) {
ASSERT_FALSE(c.isAuto());
}

TEST(YogaTest, compact_value_manages_infinity_as_undefined) {
auto c = CompactValue{
YGValue{std::numeric_limits<float>::infinity(), YGUnitUndefined}};
YGValue v = c;
ASSERT_EQ(v, YGValueUndefined);
ASSERT_NE(v, YGValueAuto);
ASSERT_NE(v, (YGValue{-1.25, YGUnitPoint}));
ASSERT_NE(v, (YGValue{25, YGUnitPercent}));
ASSERT_TRUE(c.isUndefined());
ASSERT_FALSE(c.isAuto());
}

TEST(YogaTest, compact_value_can_represent_auto) {
auto c = CompactValue{YGValue{0, YGUnitAuto}};
YGValue v = c;
Expand Down
3 changes: 2 additions & 1 deletion yoga/CompactValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class CompactValue {

template <YGUnit Unit>
static CompactValue ofMaybe(float value) noexcept {
return std::isnan(value) ? ofUndefined() : of<Unit>(value);
return std::isnan(value) || std::isinf(value) ? ofUndefined()
: of<Unit>(value);
}

static constexpr CompactValue ofZero() noexcept {
Expand Down

0 comments on commit 604a9a9

Please sign in to comment.