yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
b4e66d7b
main
1// Copyright (C) 2025 NVIDIA Corporation 2// 3// Permission is hereby granted, free of charge, to any person obtaining a copy 4// of this software and associated documentation files (the "Software"), to deal 5// in the Software without restriction, including without limitation the rights 6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7// copies of the Software, and to permit persons to whom the Software is 8// furnished to do so, subject to the following conditions: 9// 10// The above copyright notice and this permission notice shall be included in all 11// copies or substantial portions of the Software. 12// 13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19// SOFTWARE. 20 21#include <gtest/gtest.h> 22 23#include "TestFixture.h" 24 25namespace glslangtest { 26namespace { 27 28using StructNameTest = GlslangTest < ::testing::Test > ; 29 30// Test the original bug report case from issue #3931. 31TEST_F (StructNameTest ,StructNameAsStructMember ) 32{ 33const std::string inputFname = GlobalTestSettings .testRoot + "/struct_name_as_struct_member.frag" ; 34 std::string input ; 35tryLoadFile (inputFname ,"input" ,& input ); 36 37EShMessages controls = DeriveOptions (Source ::GLSL ,Semantics ::OpenGL ,Target ::AST ); 38GlslangResult result = compileAndLink ("struct_name_as_struct_member.frag" ,input ,"" ,controls , 39 glslang::EShTargetVulkan_1_0 , glslang::EShTargetSpv_1_0 ); 40 41// Should NOT have the original syntax error that was reported in the GitHub issue. 42EXPECT_EQ (result .linkingError .find ("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER" ), std::string::npos ); 43 44// Should compile successfully. 45EXPECT_EQ (result .shaderResults [0 ].output .find ("compilation errors" ), std::string::npos ); 46} 47 48// Test struct parameter after non-struct parameter (minimal regression test). 49TEST_F (StructNameTest ,StructParameterAfterNonStruct ) 50{ 51const std::string inputFname = GlobalTestSettings .testRoot + "/struct_parameter_after_non_struct.frag" ; 52 std::string input ; 53tryLoadFile (inputFname ,"input" ,& input ); 54 55EShMessages controls = DeriveOptions (Source ::GLSL ,Semantics ::OpenGL ,Target ::AST ); 56GlslangResult result = compileAndLink ("struct_parameter_after_non_struct.frag" ,input ,"" ,controls , 57 glslang::EShTargetVulkan_1_0 , glslang::EShTargetSpv_1_0 ); 58 59// Should NOT have syntax errors related to struct types in function parameters. 60EXPECT_EQ (result .linkingError .find ("syntax error, unexpected IDENTIFIER" ), std::string::npos ); 61EXPECT_EQ (result .shaderResults [0 ].output .find ("syntax error, unexpected IDENTIFIER" ), std::string::npos ); 62 63// Should compile successfully. 64EXPECT_EQ (result .shaderResults [0 ].output .find ("compilation errors" ), std::string::npos ); 65} 66 67// Test struct names as member names in declarator lists (original issue #3931) - More comprehensive patterns. 68TEST_F (StructNameTest ,StructMemberDeclaratorLists ) 69{ 70const std::string inputFname = GlobalTestSettings .testRoot + "/struct_member_declarator_lists.frag" ; 71 std::string input ; 72tryLoadFile (inputFname ,"input" ,& input ); 73 74EShMessages controls = DeriveOptions (Source ::GLSL ,Semantics ::OpenGL ,Target ::AST ); 75GlslangResult result = compileAndLink ("struct_member_declarator_lists.frag" ,input ,"" ,controls , 76 glslang::EShTargetVulkan_1_0 , glslang::EShTargetSpv_1_0 ); 77 78// Should NOT have the original syntax error from issue #3931. 79EXPECT_EQ (result .linkingError .find ("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER" ), std::string::npos ); 80EXPECT_EQ (result .shaderResults [0 ].output .find ("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER" ), std::string::npos ); 81 82// Should compile successfully. 83EXPECT_EQ (result .shaderResults [0 ].output .find ("compilation errors" ), std::string::npos ); 84} 85 86// Test function parameters with struct types (regression test for issue #4001). 87TEST_F (StructNameTest ,StructFunctionParameters ) 88{ 89const std::string inputFname = GlobalTestSettings .testRoot + "/struct_function_parameters.frag" ; 90 std::string input ; 91tryLoadFile (inputFname ,"input" ,& input ); 92 93EShMessages controls = DeriveOptions (Source ::GLSL ,Semantics ::OpenGL ,Target ::AST ); 94GlslangResult result = compileAndLink ("struct_function_parameters.frag" ,input ,"" ,controls , 95 glslang::EShTargetVulkan_1_0 , glslang::EShTargetSpv_1_0 ); 96 97// Should NOT have syntax errors related to struct types in function parameters. 98EXPECT_EQ (result .linkingError .find ("syntax error, unexpected IDENTIFIER" ), std::string::npos ); 99EXPECT_EQ (result .shaderResults [0 ].output .find ("syntax error, unexpected IDENTIFIER" ), std::string::npos ); 100 101// Should compile successfully. 102EXPECT_EQ (result .shaderResults [0 ].output .find ("compilation errors" ), std::string::npos ); 103} 104 105// Test struct construction patterns - comprehensive patterns including struct constructors. 106TEST_F (StructNameTest ,StructConstructionPatterns ) 107{ 108const std::string inputFname = GlobalTestSettings .testRoot + "/struct_construction_patterns.frag" ; 109 std::string input ; 110tryLoadFile (inputFname ,"input" ,& input ); 111 112EShMessages controls = DeriveOptions (Source ::GLSL ,Semantics ::OpenGL ,Target ::AST ); 113GlslangResult result = compileAndLink ("struct_construction_patterns.frag" ,input ,"" ,controls , 114 glslang::EShTargetVulkan_1_0 , glslang::EShTargetSpv_1_0 ); 115 116// Should NOT have syntax errors in struct construction patterns. 117EXPECT_EQ (result .linkingError .find ("syntax error, unexpected IDENTIFIER" ), std::string::npos ); 118EXPECT_EQ (result .shaderResults [0 ].output .find ("syntax error, unexpected IDENTIFIER" ), std::string::npos ); 119 120// Should NOT have the original syntax error from issue #3931. 121EXPECT_EQ (result .linkingError .find ("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER" ), std::string::npos ); 122EXPECT_EQ (result .shaderResults [0 ].output .find ("syntax error, unexpected TYPE_NAME, expecting IDENTIFIER" ), std::string::npos ); 123 124// Should compile successfully. 125EXPECT_EQ (result .shaderResults [0 ].output .find ("compilation errors" ), std::string::npos ); 126} 127 128}// anonymous namespace 129}// namespace glslangtest