Title: [246700] trunk
Revision
246700
Author
[email protected]
Date
2019-06-21 15:14:56 -0700 (Fri, 21 Jun 2019)

Log Message

[WHLSL] Code that accesses an undefined variable crashes
https://bugs.webkit.org/show_bug.cgi?id=198775

Reviewed by Myles C. Maxfield.

Source/WebCore:

Myles mostly fixed this in r246631 when he made NameResolver propagate
its error to its parent NameResolver. However, there was still one bug
where we ended up calling setError twice for an if statement. This patch
fixes that and adds tests.

Tests: webgpu/whlsl-use-undefined-variable-2.html
       webgpu/whlsl-use-undefined-variable.html

* Modules/webgpu/WHLSL/WHLSLNameResolver.cpp:
(WebCore::WHLSL::NameResolver::visit):

LayoutTests:

* webgpu/whlsl-use-undefined-variable-2-expected.txt: Added.
* webgpu/whlsl-use-undefined-variable-2.html: Added.
* webgpu/whlsl-use-undefined-variable-expected.txt: Added.
* webgpu/whlsl-use-undefined-variable.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (246699 => 246700)


--- trunk/LayoutTests/ChangeLog	2019-06-21 22:08:58 UTC (rev 246699)
+++ trunk/LayoutTests/ChangeLog	2019-06-21 22:14:56 UTC (rev 246700)
@@ -1,3 +1,15 @@
+2019-06-21  Saam Barati  <[email protected]>
+
+        [WHLSL] Code that accesses an undefined variable crashes
+        https://bugs.webkit.org/show_bug.cgi?id=198775
+
+        Reviewed by Myles C. Maxfield.
+
+        * webgpu/whlsl-use-undefined-variable-2-expected.txt: Added.
+        * webgpu/whlsl-use-undefined-variable-2.html: Added.
+        * webgpu/whlsl-use-undefined-variable-expected.txt: Added.
+        * webgpu/whlsl-use-undefined-variable.html: Added.
+
 2019-06-21  Truitt Savell  <[email protected]>
 
         Unreviewed, rolling out r246611.

Added: trunk/LayoutTests/webgpu/whlsl-use-undefined-variable-2-expected.txt (0 => 246700)


--- trunk/LayoutTests/webgpu/whlsl-use-undefined-variable-2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webgpu/whlsl-use-undefined-variable-2-expected.txt	2019-06-21 22:14:56 UTC (rev 246700)
@@ -0,0 +1,5 @@
+PASS Should not crash.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/webgpu/whlsl-use-undefined-variable-2.html (0 => 246700)


--- trunk/LayoutTests/webgpu/whlsl-use-undefined-variable-2.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/whlsl-use-undefined-variable-2.html	2019-06-21 22:14:56 UTC (rev 246700)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+const shaderSource = `
+[numthreads(1, 1, 1)]
+compute void computeShader(device float[] buffer : register(u0), float3 threadID : SV_DispatchThreadID) {
+    float4 vec = float4(x,x,x,x);
+}
+`;
+let resultsFloat32Array;
+async function start() {
+    const adapter = await navigator.gpu.requestAdapter();
+    const device = await adapter.requestDevice();
+
+    const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true});
+    const computeStage = {module: shaderModule, entryPoint: "computeShader"};
+
+    const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "storage-buffer"}]};
+    const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
+    const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]};
+    const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor);
+
+    const computePipelineDescriptor = {computeStage, layout: pipelineLayout};
+    const computePipeline = device.createComputePipeline(computePipelineDescriptor);
+
+    testPassed("Should not crash.");
+}
+window.jsTestIsAsync = true;
+window.addEventListener("load", function() {
+    start().then(function() {
+        finishJSTest();
+    }, function() {
+        finishJSTest();
+    });
+});
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/webgpu/whlsl-use-undefined-variable-expected.txt (0 => 246700)


--- trunk/LayoutTests/webgpu/whlsl-use-undefined-variable-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webgpu/whlsl-use-undefined-variable-expected.txt	2019-06-21 22:14:56 UTC (rev 246700)
@@ -0,0 +1,5 @@
+PASS Should not crash.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/webgpu/whlsl-use-undefined-variable.html (0 => 246700)


--- trunk/LayoutTests/webgpu/whlsl-use-undefined-variable.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/whlsl-use-undefined-variable.html	2019-06-21 22:14:56 UTC (rev 246700)
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+const shaderSource = `
+[numthreads(1, 1, 1)]
+compute void computeShader(device float[] buffer : register(u0), float3 threadID : SV_DispatchThreadID) {
+    float foo;
+    if (foo) {
+        x = x + 1;
+    }
+}
+`;
+let resultsFloat32Array;
+async function start() {
+    const adapter = await navigator.gpu.requestAdapter();
+    const device = await adapter.requestDevice();
+
+    const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true});
+    const computeStage = {module: shaderModule, entryPoint: "computeShader"};
+
+    const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "storage-buffer"}]};
+    const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
+    const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]};
+    const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor);
+
+    const computePipelineDescriptor = {computeStage, layout: pipelineLayout};
+    const computePipeline = device.createComputePipeline(computePipelineDescriptor);
+
+    testPassed("Should not crash.");
+}
+window.jsTestIsAsync = true;
+window.addEventListener("load", function() {
+    start().then(function() {
+        finishJSTest();
+    }, function() {
+        finishJSTest();
+    });
+});
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (246699 => 246700)


--- trunk/Source/WebCore/ChangeLog	2019-06-21 22:08:58 UTC (rev 246699)
+++ trunk/Source/WebCore/ChangeLog	2019-06-21 22:14:56 UTC (rev 246700)
@@ -1,3 +1,21 @@
+2019-06-21  Saam Barati  <[email protected]>
+
+        [WHLSL] Code that accesses an undefined variable crashes
+        https://bugs.webkit.org/show_bug.cgi?id=198775
+
+        Reviewed by Myles C. Maxfield.
+
+        Myles mostly fixed this in r246631 when he made NameResolver propagate
+        its error to its parent NameResolver. However, there was still one bug
+        where we ended up calling setError twice for an if statement. This patch
+        fixes that and adds tests.
+
+        Tests: webgpu/whlsl-use-undefined-variable-2.html
+               webgpu/whlsl-use-undefined-variable.html
+
+        * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp:
+        (WebCore::WHLSL::NameResolver::visit):
+
 2019-06-21  Truitt Savell  <[email protected]>
 
         Unreviewed, rolling out r246611.

Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp (246699 => 246700)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp	2019-06-21 22:08:58 UTC (rev 246699)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp	2019-06-21 22:14:56 UTC (rev 246700)
@@ -120,14 +120,20 @@
 void NameResolver::visit(AST::IfStatement& ifStatement)
 {
     checkErrorAndVisit(ifStatement.conditional());
-    NameContext nameContext(&m_nameContext);
-    NameResolver newNameResolver(*this, nameContext);
-    newNameResolver.checkErrorAndVisit(ifStatement.body());
-    if (newNameResolver.error())
-        setError();
-    else if (ifStatement.elseBody()) {
+    if (error())
+        return;
+
+    {
         NameContext nameContext(&m_nameContext);
         NameResolver newNameResolver(*this, nameContext);
+        newNameResolver.checkErrorAndVisit(ifStatement.body());
+    }
+    if (error())
+        return;
+
+    if (ifStatement.elseBody()) {
+        NameContext nameContext(&m_nameContext);
+        NameResolver newNameResolver(*this, nameContext);
         newNameResolver.checkErrorAndVisit(*ifStatement.elseBody());
     }
 }
@@ -135,6 +141,9 @@
 void NameResolver::visit(AST::WhileLoop& whileLoop)
 {
     checkErrorAndVisit(whileLoop.conditional());
+    if (error())
+        return;
+
     NameContext nameContext(&m_nameContext);
     NameResolver newNameResolver(*this, nameContext);
     newNameResolver.checkErrorAndVisit(whileLoop.body());
@@ -142,9 +151,12 @@
 
 void NameResolver::visit(AST::DoWhileLoop& whileLoop)
 {
-    NameContext nameContext(&m_nameContext);
-    NameResolver newNameResolver(*this, nameContext);
-    newNameResolver.checkErrorAndVisit(whileLoop.body());
+    {
+        NameContext nameContext(&m_nameContext);
+        NameResolver newNameResolver(*this, nameContext);
+        newNameResolver.checkErrorAndVisit(whileLoop.body());
+    }
+
     checkErrorAndVisit(whileLoop.conditional());
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to