Thanks to visit codestin.com
Credit goes to github.com

Skip to content

spec: forbid infinite loops #2414

@amaiorano

Description

@amaiorano

Both DXC and FXC fail to compile when they detect infinite loops.

Given this simple wgsl shader:

[[stage(compute), workgroup_size(1)]]
fn main() {
  loop {}
}

Using tint to compile and validate with DXC:

$ out/build/x64-Debug/tint.exe ./infinite_loop.wgsl --validate --format hlsl
[numthreads(1, 1, 1)]
void main() {
  [loop] while (true) {
  }
  return;
}
error: validation errors
Function: main: error: Loop must have break. Use /Zi for source location.
Validation failed.

And compiling and validating with FXC:

$ out/build/x64-Debug/tint.exe ./infinite_loop.wgsl --validate --format hlsl --fxc
[numthreads(1, 1, 1)]
void main() {
  [loop] while (true) {
  }
  return;
}
C:\src\tint\Shader@0x00000276FDD4F920(3,10-21): warning X3557: loop doesn't seem to do anything, consider removing [loop]
C:\src\tint\Shader@0x00000276FDD4F920(3,10-21): warning X3551: infinite loop detected - loop writes no values
C:\src\tint\Shader@0x00000276FDD4F920(3,17-20): error X3696: infinite loop detected - loop never exits

As part of behaviour analysis, we can detect infinite loops. I think we should forbid them, and emit a compile error when they are detected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions