Respect the result type during constant folding.

Previously, expressions like `(1.0 + myConstHalfVar)` would create a
FloatLiteral node of type `$floatLiteral`, instead of `half`. This could
cause an assertion if the IRNode containing that FloatLiteral value was
strict about types.

Example assertion: http://screen/5x9XXhxygRgk9rz

Change-Id: I42bf8285790d7939f07a6597e222bb6ac96d709b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402781
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2021-04-29 23:06:12 -04:00 committed by Skia Commit-Bot
parent e4c4322da6
commit e26dcf5eae
2 changed files with 4 additions and 4 deletions

View File

@ -409,9 +409,9 @@ std::unique_ptr<Expression> ConstantFolder::Simplify(const Context& context,
// precision to calculate the results and hope the result makes sense.
// TODO(skia:10932): detect and handle integer overflow properly.
using SKSL_UINT = uint64_t;
#define RESULT(t, op) t ## Literal::Make(context, offset, leftVal op rightVal)
#define URESULT(t, op) t ## Literal::Make(context, offset, (SKSL_UINT) leftVal op \
(SKSL_UINT) rightVal)
#define RESULT(t, op) t ## Literal::Make(offset, leftVal op rightVal, &resultType)
#define URESULT(t, op) t ## Literal::Make(offset, (SKSL_UINT)(leftVal) op \
(SKSL_UINT)(rightVal), &resultType)
if (left->is<IntLiteral>() && right->is<IntLiteral>()) {
SKSL_INT leftVal = left->as<IntLiteral>().value();
SKSL_INT rightVal = right->as<IntLiteral>().value();

View File

@ -29,7 +29,7 @@ public:
: INHERITED(offset, kExpressionKind, type)
, fValue(value) {}
// Makes a literal of $intLiteral type.
// Makes a literal of $floatLiteral type.
static std::unique_ptr<FloatLiteral> Make(const Context& context, int offset, float value) {
return std::make_unique<FloatLiteral>(offset, value, context.fTypes.fFloatLiteral.get());
}