[WHLSL] The name resolver does not deal with nativeFunctionDeclaration
authorrmorisset@apple.com <rmorisset@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jun 2019 00:06:17 +0000 (00:06 +0000)
committerrmorisset@apple.com <rmorisset@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jun 2019 00:06:17 +0000 (00:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198306

Reviewed by Saam Barati.

We currently have a crash in the nameResolver when trying to use the full standard library.
What is happening is that because we don't specify anything to do to nativeFunctionDeclarations, names in their parameters
are added to the global environment. And so as soon as we have two such parameters with the same name, the name resolver fails.

Tested by adding two native functions that share a parameter name to the standard library.

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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246524 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt

index 265bd9e..0331deb 100644 (file)
@@ -1,5 +1,22 @@
 2019-06-17  Robin Morisset  <rmorisset@apple.com>
 
+        [WHLSL] The name resolver does not deal with nativeFunctionDeclaration
+        https://bugs.webkit.org/show_bug.cgi?id=198306
+
+        Reviewed by Saam Barati.
+
+        We currently have a crash in the nameResolver when trying to use the full standard library.
+        What is happening is that because we don't specify anything to do to nativeFunctionDeclarations, names in their parameters
+        are added to the global environment. And so as soon as we have two such parameters with the same name, the name resolver fails.
+
+        Tested by adding two native functions that share a parameter name to the standard library.
+
+        * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp:
+        (WebCore::WHLSL::NameResolver::visit):
+        * Modules/webgpu/WHLSL/WHLSLNameResolver.h:
+
+2019-06-17  Robin Morisset  <rmorisset@apple.com>
+
         [WHLSL] Remove backtracking from parseAttributeBlock
         https://bugs.webkit.org/show_bug.cgi?id=198934
 
index 21ca18d..c800429 100644 (file)
@@ -94,6 +94,16 @@ void NameResolver::visit(AST::FunctionDefinition& functionDefinition)
     newNameResolver.checkErrorAndVisit(functionDefinition.block());
 }
 
+void NameResolver::visit(AST::NativeFunctionDeclaration& nativeFunctionDeclaration)
+{
+    NameContext newNameContext(&m_nameContext);
+    NameResolver newNameResolver(newNameContext);
+    newNameResolver.setCurrentFunctionDefinition(m_currentFunction);
+    checkErrorAndVisit(nativeFunctionDeclaration.type());
+    for (auto& parameter : nativeFunctionDeclaration.parameters())
+        newNameResolver.checkErrorAndVisit(parameter);
+}
+
 void NameResolver::visit(AST::Block& block)
 {
     NameContext nameContext(&m_nameContext);
index 8fb4a34..89f0866 100644 (file)
@@ -43,14 +43,14 @@ public:
 
     virtual ~NameResolver() = default;
 
-    void visit(AST::FunctionDefinition&) override;
-
     void setCurrentFunctionDefinition(AST::FunctionDefinition* functionDefinition)
     {
         m_currentFunction = functionDefinition;
     }
 
 private:
+    void visit(AST::FunctionDefinition&) override;
+    void visit(AST::NativeFunctionDeclaration&) override;
     void visit(AST::TypeReference&) override;
     void visit(AST::Block&) override;
     void visit(AST::IfStatement&) override;
index 0749481..ec28410 100644 (file)
@@ -625,4 +625,7 @@ operator float4(float x, float y, float z, float w) {
     return result;
 }
 
+native ushort Sample(Texture1D<ushort>, sampler, float location);
+native ushort Sample(Texture1D<ushort>, sampler, float location, int offset);
+
 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=192890 Insert the rest of the standard library once the parser is fast enough