mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-03 11:46:09 +00:00
tint: fix extractBits edge case
If count is highest and offset is non-zero, or vice-versa, we'd overflow the count + offset > bit-width check. This CL fixes this case. Bug: tint:1581 Bug: chromium:1381810 Change-Id: I6ee60ec1a13230fca6f4bb6407cd33bcc6730eb7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/109162 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
0a7364815c
commit
a70e365313
@ -1901,18 +1901,18 @@ ConstEval::Result ConstEval::extractBits(const sem::Type* ty,
|
|||||||
NumberUT in_offset = args[1]->As<NumberUT>();
|
NumberUT in_offset = args[1]->As<NumberUT>();
|
||||||
NumberUT in_count = args[2]->As<NumberUT>();
|
NumberUT in_count = args[2]->As<NumberUT>();
|
||||||
|
|
||||||
constexpr UT w = sizeof(UT) * 8;
|
|
||||||
if ((in_offset + in_count) > w) {
|
|
||||||
AddError("'offset + 'count' must be less than or equal to the bit width of 'e'",
|
|
||||||
source);
|
|
||||||
return utils::Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cast all to unsigned
|
// Cast all to unsigned
|
||||||
UT e = static_cast<UT>(in_e);
|
UT e = static_cast<UT>(in_e);
|
||||||
UT o = static_cast<UT>(in_offset);
|
UT o = static_cast<UT>(in_offset);
|
||||||
UT c = static_cast<UT>(in_count);
|
UT c = static_cast<UT>(in_count);
|
||||||
|
|
||||||
|
constexpr UT w = sizeof(UT) * 8;
|
||||||
|
if (o > w || c > w || (o + c) > w) {
|
||||||
|
AddError("'offset + 'count' must be less than or equal to the bit width of 'e'",
|
||||||
|
source);
|
||||||
|
return utils::Failure;
|
||||||
|
}
|
||||||
|
|
||||||
NumberT result;
|
NumberT result;
|
||||||
if (c == UT{0}) {
|
if (c == UT{0}) {
|
||||||
// The result is 0 if c is 0
|
// The result is 0 if c is 0
|
||||||
|
@ -1226,6 +1226,8 @@ INSTANTIATE_TEST_SUITE_P(ExtractBits,
|
|||||||
std::make_tuple(33, 33), //
|
std::make_tuple(33, 33), //
|
||||||
std::make_tuple(34, 34), //
|
std::make_tuple(34, 34), //
|
||||||
std::make_tuple(1000, 1000), //
|
std::make_tuple(1000, 1000), //
|
||||||
|
std::make_tuple(u32::Highest(), 1), //
|
||||||
|
std::make_tuple(1, u32::Highest()), //
|
||||||
std::make_tuple(u32::Highest(), u32::Highest())));
|
std::make_tuple(u32::Highest(), u32::Highest())));
|
||||||
|
|
||||||
std::vector<Case> Pack4x8snormCases() {
|
std::vector<Case> Pack4x8snormCases() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user