tint/writer: Check for inf / nan after casting to f32.
When abstract floats are supported, FloatLiteralExpression may hold values outside of the range of a f32. When we call FloatToString(), we may emit an 'inf', which is not a token for any backend. Cast to f32 first, to ensure behavior remains consistent. Note: Once the resolver materializes, and we constant fold, the backends shouldn't see any values outside of a f32. Bug: tint:1504 Change-Id: I11942304a063d72302dad32e0d6d4e04aa39b5f8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91425 Reviewed-by: David Neto <dneto@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
3e6bf1ae73
commit
3ad927cc73
|
@ -2183,13 +2183,14 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression*
|
|||
return true;
|
||||
},
|
||||
[&](const ast::FloatLiteralExpression* l) {
|
||||
if (std::isinf(l->value)) {
|
||||
auto f32 = static_cast<float>(l->value);
|
||||
if (std::isinf(f32)) {
|
||||
out << (l->value >= 0 ? "uintBitsToFloat(0x7f800000u)"
|
||||
: "uintBitsToFloat(0xff800000u)");
|
||||
} else if (std::isnan(l->value)) {
|
||||
out << "uintBitsToFloat(0x7fc00000u)";
|
||||
} else {
|
||||
out << FloatToString(static_cast<float>(l->value)) << "f";
|
||||
out << FloatToString(f32) << "f";
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
|
|
@ -3139,13 +3139,14 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression*
|
|||
out << (l->value ? "true" : "false");
|
||||
return true;
|
||||
},
|
||||
[&](const ast::FloatLiteralExpression* fl) {
|
||||
if (std::isinf(fl->value)) {
|
||||
out << (fl->value >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)");
|
||||
} else if (std::isnan(fl->value)) {
|
||||
[&](const ast::FloatLiteralExpression* l) {
|
||||
auto f32 = static_cast<float>(l->value);
|
||||
if (std::isinf(f32)) {
|
||||
out << (f32 >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)");
|
||||
} else if (std::isnan(f32)) {
|
||||
out << "asfloat(0x7fc00000u)";
|
||||
} else {
|
||||
out << FloatToString(static_cast<float>(fl->value)) << "f";
|
||||
out << FloatToString(f32) << "f";
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
|
|
@ -1544,12 +1544,13 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression*
|
|||
return true;
|
||||
},
|
||||
[&](const ast::FloatLiteralExpression* l) {
|
||||
if (std::isinf(l->value)) {
|
||||
out << (l->value >= 0 ? "INFINITY" : "-INFINITY");
|
||||
} else if (std::isnan(l->value)) {
|
||||
auto f32 = static_cast<float>(l->value);
|
||||
if (std::isinf(f32)) {
|
||||
out << (f32 >= 0 ? "INFINITY" : "-INFINITY");
|
||||
} else if (std::isnan(f32)) {
|
||||
out << "NAN";
|
||||
} else {
|
||||
out << FloatToString(static_cast<float>(l->value)) << "f";
|
||||
out << FloatToString(f32) << "f";
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue