Ver código fonte

Fix spec violations. Simplify tests.

The original fix was accepting invalid GLSL. This reduces the scope of the fix to allow variable declarations to match section 4.2 (Scoping) of the GLSL 4.60 spec: "Each level of structure has its own name space for names given in member declarators; such names need only be unique within that name space."

This means that using a struct name as a member name is valid. The member name hides the type name within the struct.

Updated and simplified test cases to match.

The output of 400.frag's error needed to be updated to reflect the new grammar implementation changes. A struct_declarator can now accept TYPE_NAME in addition to IDENTIFIER, so the parser is now adding TYPE_NAME to the list of expected tokens.
Diego Novillo 3 semanas atrás
pai
commit
fa7cb74569

+ 1 - 1
Test/baseResults/400.frag.out

@@ -37,7 +37,7 @@ ERROR: 0:230: 'subroutine' : feature not yet implemented
 ERROR: 0:230: '' : default qualifier requires 'uniform', 'buffer', 'in', 'out' or 'shared' storage qualification 
 ERROR: 0:231: 'subroutine' : feature not yet implemented 
 ERROR: 0:232: 'subroutine' : feature not yet implemented 
-ERROR: 0:234: '' :  syntax error, unexpected PRECISE, expecting IDENTIFIER
+ERROR: 0:234: '' :  syntax error, unexpected PRECISE, expecting IDENTIFIER or TYPE_NAME
 ERROR: 39 compilation errors.  No code generated.
 
 

+ 0 - 22
Test/multiple_struct_names.frag

@@ -1,22 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-struct C
-{
-    vec4 u;
-};
-
-struct D
-{
-    vec2 v;
-};
-
-void main()
-{
-    float B, C, D; // Multiple struct names as variable names - should work
-    int B[5], C[3], D[2]; // Multiple struct names as array variable names - should work
-    vec2 B = vec2(1.0, 2.0), C = vec2(3.0, 4.0), D = vec2(5.0, 6.0); // Multiple struct names with initializers - should work
-} 

+ 14 - 0
Test/struct_name_as_array_member.frag

@@ -0,0 +1,14 @@
+#version 400
+
+// Test case for using a struct name as an array member name.
+struct B
+{
+    vec3 t;
+};
+
+struct K
+{
+    float A[2], B[3]; // This should work - struct name B is used as an array member name.
+};
+
+void main(){} 

+ 8 - 4
Test/struct_name_as_struct_member.frag

@@ -1,4 +1,9 @@
 #version 400
+
+// Original bug report from: https://github.com/KhronosGroup/glslang/issues/3931
+// Error was: "syntax error, unexpected TYPE_NAME, expecting IDENTIFIER" 
+// when defining a struct field with the same name as a previously defined
+// struct.
 struct B
 {
     vec3 t;
@@ -6,9 +11,8 @@ struct B
 
 struct K
 {
-    float A, B; // Struct name B as member name - should work
-    int B;      // Struct name B as member name - should work
-    vec2 B;     // Struct name B as member name - should work
+    float A, B; // This should work. The B field is in a different scope
+		// than the B struct.
 };
 
-void main(){} 
+void main(){} 

+ 0 - 14
Test/struct_name_as_struct_member_with_array.frag

@@ -1,14 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-struct K
-{
-    float A, B[10]; // Struct name B as array member name - should work
-    int B[5];       // Struct name B as array member name - should work
-    vec2 B[3];      // Struct name B as array member name - should work
-};
-
-void main(){} 

+ 0 - 12
Test/struct_name_as_variable.frag

@@ -1,12 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-void main()
-{
-    float B; // Struct name as variable name - should work
-    int B;   // Struct name as variable name - should work
-    vec2 B;  // Struct name as variable name - should work
-} 

+ 0 - 12
Test/struct_name_as_variable_with_array.frag

@@ -1,12 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-void main()
-{
-    float B[10]; // Struct name as array variable name - should work
-    int B[5];    // Struct name as array variable name - should work
-    vec2 B[3];   // Struct name as array variable name - should work
-} 

+ 0 - 12
Test/struct_name_as_variable_with_array_initializer.frag

@@ -1,12 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-void main()
-{
-    float B[2] = float[2](1.0, 2.0); // Struct name as array variable name with initializer - should work
-    int B[3] = int[3](1, 2, 3);      // Struct name as array variable name with initializer - should work
-    vec2 B[2] = vec2[2](vec2(1.0, 2.0), vec2(3.0, 4.0)); // Struct name as array variable name with initializer - should work
-} 

+ 0 - 12
Test/struct_name_as_variable_with_initializer.frag

@@ -1,12 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-void main()
-{
-    float B = 1.0; // Struct name as variable name with initializer - should work
-    int B = 42;    // Struct name as variable name with initializer - should work
-    vec2 B = vec2(1.0, 2.0); // Struct name as variable name with initializer - should work
-} 

+ 0 - 31
Test/struct_name_edge_cases.frag

@@ -1,31 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-struct C
-{
-    vec4 u;
-};
-
-void main()
-{
-    // Multiple declarations in one statement
-    float A, B, C; // B and C are struct names - should work
-    
-    // Array declarations
-    int B[10], C[5]; // B and C are struct names - should work
-    
-    // With initializers
-    vec2 B = vec2(1.0, 2.0), C = vec2(3.0, 4.0); // B and C are struct names - should work
-    
-    // Array with initializers
-    float B[2] = float[2](1.0, 2.0), C[2] = float[2](3.0, 4.0); // B and C are struct names - should work
-    
-    // Nested scope
-    {
-        float B = 1.0; // Struct name in nested scope - should work
-        int C = 42;    // Struct name in nested scope - should work
-    }
-} 

+ 0 - 14
Test/struct_name_in_compute_shader.comp

@@ -1,14 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-
-void main()
-{
-    float B = 1.0; // Struct name as local variable - should work
-    int B = 42;    // Struct name as local variable - should work
-    vec2 B = vec2(1.0, 2.0); // Struct name as local variable - should work
-} 

+ 0 - 10
Test/struct_name_in_declaration.frag

@@ -1,10 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-struct K
-{
-    float A, B; // This should now work correctly
-};
-void main(){} 

+ 0 - 15
Test/struct_name_in_function_params.frag

@@ -1,15 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-void func(float B, int B, vec2 B) // Struct name B as parameter names - should work
-{
-    // Function body
-}
-
-void main()
-{
-    func(1.0, 42, vec2(1.0, 2.0));
-} 

+ 0 - 18
Test/struct_name_in_function_params_with_array.frag

@@ -1,18 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-void func(float B[5], int B[3], vec2 B[2]) // Struct name B as array parameter names - should work
-{
-    // Function body
-}
-
-void main()
-{
-    float arr1[5] = float[5](1.0, 2.0, 3.0, 4.0, 5.0);
-    int arr2[3] = int[3](1, 2, 3);
-    vec2 arr3[2] = vec2[2](vec2(1.0, 2.0), vec2(3.0, 4.0));
-    func(arr1, arr2, arr3);
-} 

+ 0 - 13
Test/struct_name_in_middle.frag

@@ -1,13 +0,0 @@
-#version 400
-
-struct A {
-    float x;
-};
-
-struct B {
-    float y;
-};
-
-void main() {
-    float A, x, B;  // A and B are struct names, x is a regular variable
-} 

+ 0 - 17
Test/struct_name_in_vertex_shader.vert

@@ -1,17 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-layout(location = 0) in vec3 position;
-layout(location = 1) in vec3 normal;
-
-out vec3 B; // Struct name as output variable - should work
-
-void main()
-{
-    float B = 1.0; // Struct name as local variable - should work
-    vec3 B = normal; // Struct name as local variable - should work
-    gl_Position = vec4(position, 1.0);
-} 

+ 0 - 15
Test/struct_name_with_qualifiers.frag

@@ -1,15 +0,0 @@
-#version 400
-struct B
-{
-    vec3 t;
-};
-
-uniform float B; // Struct name as uniform variable - should work
-in vec3 B;       // Struct name as input variable - should work
-out vec4 B;      // Struct name as output variable - should work
-
-void main()
-{
-    const float B = 1.0; // Struct name as const variable - should work
-    vec4 B = vec4(1.0);  // Struct name as local variable - should work
-} 

+ 16 - 24
glslang/MachineIndependent/glslang.y

@@ -1199,45 +1199,21 @@ single_declaration
         $$.intermNode = 0;
         parseContext.declareVariable($2.loc, *$2.string, $1);
     }
-    | fully_specified_type TYPE_NAME {
-        $$.type = $1;
-        $$.intermNode = 0;
-        parseContext.declareVariable($2.loc, *$2.string, $1);
-    }
-
     | fully_specified_type IDENTIFIER array_specifier {
         $$.type = $1;
         $$.intermNode = 0;
         parseContext.declareVariable($2.loc, *$2.string, $1, $3.arraySizes);
     }
-    | fully_specified_type TYPE_NAME array_specifier {
-        $$.type = $1;
-        $$.intermNode = 0;
-        parseContext.declareVariable($2.loc, *$2.string, $1, $3.arraySizes);
-    }
-
     | fully_specified_type IDENTIFIER array_specifier EQUAL initializer {
         $$.type = $1;
         TIntermNode* initNode = parseContext.declareVariable($2.loc, *$2.string, $1, $3.arraySizes, $5);
         $$.intermNode = parseContext.intermediate.growAggregate(0, initNode, $4.loc);
     }
-    | fully_specified_type TYPE_NAME array_specifier EQUAL initializer {
-        $$.type = $1;
-        TIntermNode* initNode = parseContext.declareVariable($2.loc, *$2.string, $1, $3.arraySizes, $5);
-        $$.intermNode = parseContext.intermediate.growAggregate(0, initNode, $4.loc);
-    }
-
     | fully_specified_type IDENTIFIER EQUAL initializer {
         $$.type = $1;
         TIntermNode* initNode = parseContext.declareVariable($2.loc, *$2.string, $1, 0, $4);
         $$.intermNode = parseContext.intermediate.growAggregate(0, initNode, $3.loc);
     }
-    | fully_specified_type TYPE_NAME EQUAL initializer {
-        $$.type = $1;
-        TIntermNode* initNode = parseContext.declareVariable($2.loc, *$2.string, $1, 0, $4);
-        $$.intermNode = parseContext.intermediate.growAggregate(0, initNode, $3.loc);
-    }
-
 
 // Grammar Note:  No 'enum', or 'typedef'.
 
@@ -3835,6 +3811,22 @@ struct_declarator
         $$.type->setFieldName(*$1.string);
         $$.type->transferArraySizes($2.arraySizes);
     }
+    | TYPE_NAME {
+        // Allow struct names as struct member names (GLSL name hiding)
+        // This fixes the original GitHub issue #3931
+        $$.type = new TType(EbtVoid);
+        $$.loc = $1.loc;
+        $$.type->setFieldName(*$1.string);
+    }
+    | TYPE_NAME array_specifier {
+        // Allow struct names as struct member array names (GLSL name hiding)
+        parseContext.arrayOfArrayVersionCheck($1.loc, $2.arraySizes);
+
+        $$.type = new TType(EbtVoid);
+        $$.loc = $1.loc;
+        $$.type->setFieldName(*$1.string);
+        $$.type->transferArraySizes($2.arraySizes);
+    }
     ;
 
 initializer

Diferenças do arquivo suprimidas por serem muito extensas
+ 592 - 1168
glslang/MachineIndependent/glslang_tab.cpp


+ 1 - 1
gtests/CMakeLists.txt

@@ -56,7 +56,7 @@ if(GLSLANG_TESTS)
             ${CMAKE_CURRENT_SOURCE_DIR}/LiveTraverser.FromFile.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/Pp.FromFile.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/Spv.FromFile.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/StructName.FromFile.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/StructName.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/VkRelaxed.FromFile.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/GlslMapIO.FromFile.cpp)
 

+ 0 - 322
gtests/StructName.FromFile.cpp

@@ -1,322 +0,0 @@
-// Copyright (C) 2025 NVIDIA Corporation
-//
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-//    Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//
-//    Redistributions in binary form must reproduce the above
-//    copyright notice, this list of conditions and the following
-//    disclaimer in the documentation and/or other materials provided
-//    with the distribution.
-//
-//    Neither the name of The Khronos Group Inc. nor the names of its
-//    contributors may be used to endorse or promote products derived
-//    from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-
-#include "TestFixture.h"
-
-namespace glslangtest {
-namespace {
-
-using StructNameTest = GlslangTest<::testing::Test>;
-
-// Test that struct names can be used as variable names in declarations (should NOT have syntax errors)
-TEST_F(StructNameTest, StructNameInDeclaration)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_in_declaration.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_in_declaration.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    
-    // Should parse successfully (no syntax errors)
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used as single variable names (should parse successfully, no redefinition error)
-TEST_F(StructNameTest, StructNameAsVariable)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_as_variable.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_as_variable.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    // Should parse successfully (no syntax errors)
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used as variable names with initializers (should parse successfully, no redefinition error)
-TEST_F(StructNameTest, StructNameAsVariableWithInitializer)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_as_variable_with_initializer.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_as_variable_with_initializer.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    // Should parse successfully (no syntax errors)
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used as variable names with arrays (should parse successfully, no redefinition error)
-TEST_F(StructNameTest, StructNameAsVariableWithArray)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_as_variable_with_array.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_as_variable_with_array.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    // Should parse successfully (no syntax errors)
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used as variable names with array initializers (should parse successfully, no redefinition error)
-TEST_F(StructNameTest, StructNameAsVariableWithArrayInitializer)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_as_variable_with_array_initializer.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_as_variable_with_array_initializer.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    // Should parse successfully (no syntax errors)
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used as struct member names (should parse successfully)
-TEST_F(StructNameTest, StructNameAsStructMember)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_as_struct_member.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_as_struct_member.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    
-    // Should parse successfully
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used as struct member names with arrays (should parse successfully)
-TEST_F(StructNameTest, StructNameAsStructMemberWithArray)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_as_struct_member_with_array.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_as_struct_member_with_array.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    
-    // Should parse successfully
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that multiple struct names can be used in the same declaration (should parse successfully, no redefinition error)
-TEST_F(StructNameTest, MultipleStructNames)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/multiple_struct_names.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("multiple_struct_names.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    // Should parse successfully (no syntax errors)
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used in function parameters (should parse successfully)
-TEST_F(StructNameTest, StructNameInFunctionParams)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_in_function_params.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_in_function_params.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    
-    // Should parse successfully
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used in function parameters with arrays (should parse successfully)
-TEST_F(StructNameTest, StructNameInFunctionParamsWithArray)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_in_function_params_with_array.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_in_function_params_with_array.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    
-    // Should parse successfully
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used in vertex shaders (should parse successfully)
-TEST_F(StructNameTest, StructNameInVertexShader)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_in_vertex_shader.vert";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_in_vertex_shader.vert", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    
-    // Should parse successfully
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used in compute shaders (should parse successfully)
-TEST_F(StructNameTest, StructNameInComputeShader)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_in_compute_shader.comp";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_in_compute_shader.comp", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    
-    // Should parse successfully
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used with qualifiers (should parse successfully)
-TEST_F(StructNameTest, StructNameWithQualifiers)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_with_qualifiers.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_with_qualifiers.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    
-    // Should parse successfully
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test edge cases with struct names (should parse successfully)
-TEST_F(StructNameTest, StructNameEdgeCases)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_edge_cases.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_edge_cases.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    
-    // Should parse successfully
-    EXPECT_TRUE(result.linkingError.empty() || 
-                result.linkingError.find("syntax error") == std::string::npos);
-}
-
-// Test that struct names can be used in the middle of variable declarations (should parse successfully)
-TEST_F(StructNameTest, StructNameInMiddle)
-{
-    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_in_middle.frag";
-    std::string input;
-    tryLoadFile(inputFname, "input", &input);
-    
-    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
-    GlslangResult result = compileAndLink("struct_name_in_middle.frag", input, "", controls,
-                                         glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
-    
-    // Should NOT have the original syntax error
-    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
-    // Should NOT have any syntax errors
-    EXPECT_EQ(result.linkingError.find("syntax error"), std::string::npos);
-    // Should NOT have redefinition errors (these are different variables)
-    EXPECT_EQ(result.linkingError.find("redefinition"), std::string::npos);
-}
-
-}  // anonymous namespace
-}  // namespace glslangtest 

+ 80 - 0
gtests/StructName.cpp

@@ -0,0 +1,80 @@
+// Copyright (C) 2025 NVIDIA Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+//    Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+//
+//    Redistributions in binary form must reproduce the above
+//    copyright notice, this list of conditions and the following
+//    disclaimer in the documentation and/or other materials provided
+//    with the distribution.
+//
+//    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
+//    contributors may be used to endorse or promote products derived
+//    from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+
+#include <gtest/gtest.h>
+
+#include "TestFixture.h"
+
+namespace glslangtest {
+namespace {
+
+using StructNameTest = GlslangTest<::testing::Test>;
+
+// Test the original bug report case from issue #3931.
+TEST_F(StructNameTest, OriginalBugReportStructMember)
+{
+    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_as_struct_member.frag";
+    std::string input;
+    tryLoadFile(inputFname, "input", &input);
+
+    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
+    GlslangResult result = compileAndLink("struct_name_as_struct_member.frag", input, "", controls,
+                                          glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
+
+    // Should NOT have the original syntax error that was reported in the GitHub issue.
+    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
+
+    // Should compile successfully.
+    EXPECT_EQ(result.shaderResults[0].output.find("compilation errors"), std::string::npos);
+}
+
+// Test struct names used as array member names.
+TEST_F(StructNameTest, StructNameAsArrayMember)
+{
+    const std::string inputFname = GlobalTestSettings.testRoot + "/struct_name_as_array_member.frag";
+    std::string input;
+    tryLoadFile(inputFname, "input", &input);
+
+    EShMessages controls = DeriveOptions(Source::GLSL, Semantics::OpenGL, Target::AST);
+    GlslangResult result = compileAndLink("struct_name_as_array_member.frag", input, "", controls,
+                                          glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0);
+
+    // Should NOT have the original syntax error that was reported in the GitHub issue.
+    EXPECT_EQ(result.linkingError.find("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER"), std::string::npos);
+
+    // Should compile successfully.
+    EXPECT_EQ(result.shaderResults[0].output.find("compilation errors"), std::string::npos);
+}
+
+} // anonymous namespace
+} // namespace glslangtest

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff