Skip to content

Commit

Permalink
[WGSL] Constant size for array types should be concretized
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=274149
rdar://127986684

Reviewed by Mike Wyrzykowski.

The size of an array type has to be a concrete integer, but we were using the
constant value without concretizing, so 64-bit integers were allowed.

* Source/WebGPU/WGSL/TypeCheck.cpp:
(WGSL::TypeChecker::visit):
* Source/WebGPU/WGSL/tests/invalid/array.wgsl:

Canonical link: https://commits.webkit.org/278761@main
  • Loading branch information
tadeuzagallo committed May 14, 2024
1 parent b99c497 commit 6dae8e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Source/WebGPU/WGSL/TypeCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1708,10 +1708,13 @@ void TypeChecker::visit(AST::ArrayTypeExpression& array)

auto value = array.maybeElementCount()->constantValue();
if (value.has_value()) {
auto elementCount = value->integerValue();
if (elementCount < 1) {
typeError(array.span(), "array count must be greater than 0"_s);
return;
int64_t elementCount = 0;
if (convertValue(array.maybeElementCount()->span(), concretize(elementCountType, m_types), value)) {
elementCount = value->integerValue();
if (elementCount < 1) {
typeError(array.span(), "array count must be greater than 0"_s);
return;
}
}
size = { static_cast<unsigned>(elementCount) };
} else
Expand Down
3 changes: 3 additions & 0 deletions Source/WebGPU/WGSL/tests/invalid/array.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// CHECK-L: 'array' requires at least 1 template argument
var<private> a:array;

// CHECK-L: value 4294967296 cannot be represented as 'i32'
@group(0) @binding(0) var<storage, read_write> b: array<u32, (1<<32)>;

fn testArrayLengthMismatch() {
// CHECK-L: array count must be greater than 0
let x1 = array<i32, 0>();
Expand Down

0 comments on commit 6dae8e2

Please sign in to comment.