yum-mirror/glslang

git clone https://git.yummers.dev/yum-mirror/glslang

Saddamfix signed overflow reading the #version number in scanVersionef01d8b8

main
11.3 KiB364 linesraw
1//
2// Copyright (C) 2016 Google, Inc.
3// Copyright (C) 2022-2024 Arm Limited.
4//
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11//    Redistributions of source code must retain the above copyright
12//    notice, this list of conditions and the following disclaimer.
13//
14//    Redistributions in binary form must reproduce the above
15//    copyright notice, this list of conditions and the following
16//    disclaimer in the documentation and/or other materials provided
17//    with the distribution.
18//
19//    Neither the name of Google Inc. nor the names of its
20//    contributors may be used to endorse or promote products derived
21//    from this software without specific prior written permission.
22//
23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34// POSSIBILITY OF SUCH DAMAGE.
35
36#include <gtest/gtest.h>
37
38#include "TestFixture.h"
39
40namespace glslangtest {
41namespace {
42
43using CompileToAstTest = GlslangTest<::testing::TestWithParam<std::string>>;
44
45using CompileToAstTestNV = GlslangTest<::testing::TestWithParam<std::string>>;
46
47TEST_P(CompileToAstTest, FromFile)
48{
49    loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
50                            Source::GLSL, Semantics::OpenGL, glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0,
51                            Target::AST);
52}
53
54// Compiling GLSL to SPIR-V under OpenGL semantics (NV extensions enabled).
55TEST_P(CompileToAstTestNV, FromFile)
56{
57    loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
58                            Source::GLSL, Semantics::OpenGL, glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0,
59                            Target::AST);
60}
61
62// clang-format off
63INSTANTIATE_TEST_SUITE_P(
64    Glsl, CompileToAstTest,
65    ::testing::ValuesIn(std::vector<std::string>({
66        "sample.frag",
67        "sample.vert",
68        "decls.frag",
69        "specExamples.frag",
70        "specExamples.vert",
71        "versionsClean.frag",
72        "versionsClean.vert",
73        "versionsErrors.frag",
74        "versionsErrors.vert",
75        "versionTooBig.vert",
76        "100.frag",
77        "100samplerExternal.frag",
78        "120.vert",
79        "120.frag",
80        "130.vert",
81        "130.frag",
82        "140.vert",
83        "140.frag",
84        "150.vert",
85        "150.geom",
86        "150.frag",
87        "precision.frag",
88        "precision.vert",
89        "nonSquare.vert",
90        "matrixError.vert",
91        "cppSimple.vert",
92        "cppIndent.vert",
93        "cppIntMinOverNegativeOne.frag",
94        "cppMerge.frag",
95        "cppNest.vert",
96        "cppBad.vert",
97        "cppBad2.vert",
98        "cppBad3.vert",
99        "cppBad4.vert",
100        "cppBad5.vert",
101        "cppComplexExpr.vert",
102        "cppDeepNest.frag",
103        "cppPassMacroName.frag",
104        "cppRelaxSkipTokensErrors.vert",
105        "badChars.frag",
106        "pointCoord.frag",
107        "array.frag",
108        "array100.frag",
109        "comment.frag",
110        "300.vert",
111        "300.frag",
112        "300BuiltIns.frag",
113        "300layout.vert",
114        "300layout.frag",
115        "300operations.frag",
116        "300block.frag",
117        "300samplerExternal.frag",
118        "300samplerExternalYUV.frag",
119        "310.comp",
120        "310.vert",
121        "310.geom",
122        "310.frag",
123        "310.tesc",
124        "310.tese",
125        "310implicitSizeArrayError.vert",
126        "310.inheritMemory.frag",
127        "310AofA.vert",
128        "310runtimeArray.vert",
129        "320.comp",
130        "320.vert",
131        "320.geom",
132        "320.frag",
133        "320.tesc",
134        "320.tese",
135        "330.frag",
136        "330comp.frag",
137        "constErrors.frag",
138        "constFold.frag",
139        "constFoldBitCast64.frag",
140        "constFoldIntMin.frag",
141        "errors.frag",
142        "forwardRef.frag",
143        "uint.frag",
144        "switch.frag",
145        "tokenLength.vert",
146        "100Limits.vert",
147        "100scope.vert",
148        "110scope.vert",
149        "300scope.vert",
150        "400.frag",
151        "400.vert",
152        "410.vert",
153        "420.comp",
154        "420.frag",
155        "420.vert",
156        "420.geom",
157        "420_size_gl_in.geom",
158        "430scope.vert",
159        "lineContinuation100.vert",
160        "lineContinuation.vert",
161        "numeral.frag",
162        "400.geom",
163        "400.tesc",
164        "400.tese",
165        "410.tesc",
166        "420.tesc",
167        "420.tese",
168        "410.geom",
169        "430.vert",
170        "430.comp",
171        "430AofA.frag",
172        "435.vert",
173        "440.vert",
174        "440.frag",
175        "450.vert",
176        "450.geom",
177        "450.tesc",
178        "450.tese",
179        "450.frag",
180        "450.comp",
181        "460.frag",
182        "460.vert",
183        "dce.frag",
184        "atomic_uint.frag",
185        "implicitInnerAtomicUint.frag",
186        "aggOps.frag",
187        "always-discard.frag",
188        "always-discard2.frag",
189        "boolinput.error.frag",
190        "booloutput.error.vert",
191        "conditionalDiscard.frag",
192        "conservativeDepth.frag",
193        "conversion.frag",
194        "dataOut.frag",
195        "dataOutIndirect.frag",
196        "deepRvalue.frag",
197        "defaultArgs.comp",
198        "depthOut.frag",
199        "discard-dce.frag",
200        "doWhileLoop.frag",
201        "earlyReturnDiscard.frag",
202        "flowControl.frag",
203        "forLoop.frag",
204        "functionCall.frag",
205        "functionSemantics.frag",
206        "length.frag",
207        "localAggregates.frag",
208        "loops.frag",
209        "loopsArtificial.frag",
210        "matrix.frag",
211        "matrix2.frag",
212        "mixedArrayDecls.frag",
213        "nonuniform.frag",
214        "newTexture.frag",
215        "Operations.frag",
216        "overlongLiteral.frag",
217        "prepost.frag",
218        "runtimeArray.vert",
219        "simpleFunctionCall.frag",
220        "stringToDouble.vert",
221        "stringInvalidOps.frag",
222        "struct.error.frag",
223        "structAssignment.frag",
224        "structDeref.frag",
225        "structure.frag",
226        "swizzle.frag",
227        "invalidSwizzle.vert",
228        "syntaxError.frag",
229        "test.frag",
230        "texture.frag",
231        "tokenPaste.vert",
232        "types.frag",
233        "uniformArray.frag",
234        "variableArrayIndex.frag",
235        "variadic.comp",
236        "varyingArray.frag",
237        "varyingArrayIndirect.frag",
238        "voidFunction.frag",
239        "whileLoop.frag",
240        "nonVulkan.frag",
241        "negativeArraySize.comp",
242        "precise.tesc",
243        "precise_struct_block.vert",
244        "maxClipDistances.vert",
245        "findFunction.frag",
246        "noMatchingFunction.frag",
247        "constantUnaryConversion.comp",
248        "localSizeRepeated.comp",
249        "xfbUnsizedArray.error.vert",
250        "xfbUnsizedArray.error.tese",
251        "xfbArrayStride.error.vert",
252        "glsl.140.layoutOffset.error.vert",
253        "glsl.430.layoutOffset.error.vert",
254        "glsl.450.subgroup.frag",
255        "glsl.450.subgroup.geom",
256        "glsl.450.subgroup.tesc",
257        "glsl.450.subgroup.tese",
258        "glsl.450.subgroup.vert",
259        "glsl.450.subgroupArithmetic.comp",
260        "glsl.450.subgroupBasic.comp",
261        "glsl.450.subgroupBallot.comp",
262        "glsl.450.subgroupBallotNeg.comp",
263        "glsl.450.subgroupClustered.comp",
264        "glsl.450.subgroupClusteredNeg.comp",
265        "glsl.450.subgroupPartitioned.comp",
266        "glsl.450.subgroupRotate.comp",
267        "glsl.450.subgroupShuffle.comp",
268        "glsl.450.subgroupShuffleRelative.comp",
269        "glsl.450.subgroupQuad.comp",
270        "glsl.450.subgroupVote.comp",
271        "glsl.460.subgroup.mesh",
272        "glsl.460.subgroup.task",
273        "glsl.460.subgroup.rahit",
274        "glsl.460.subgroup.rcall",
275        "glsl.460.subgroup.rchit",
276        "glsl.460.subgroup.rgen",
277        "glsl.460.subgroup.rint",
278        "glsl.460.subgroup.rmiss",
279        "glsl.es300.layoutOffset.error.vert",
280        "glsl.es320.subgroup.frag",
281        "glsl.es320.subgroup.geom",
282        "glsl.es320.subgroup.tesc",
283        "glsl.es320.subgroup.tese",
284        "glsl.es320.subgroup.vert",
285        "glsl.es320.subgroupArithmetic.comp",
286        "glsl.es320.subgroupBasic.comp",
287        "glsl.es320.subgroupBallot.comp",
288        "glsl.es320.subgroupBallotNeg.comp",
289        "glsl.es320.subgroupClustered.comp",
290        "glsl.es320.subgroupClusteredNeg.comp",
291        "glsl.es320.subgroupPartitioned.comp",
292        "glsl.es320.subgroupRotate.comp",
293        "glsl.es320.subgroupShuffle.comp",
294        "glsl.es320.subgroupShuffleRelative.comp",
295        "glsl.es320.subgroupQuad.comp",
296        "glsl.es320.subgroupVote.comp",
297        "glsl.es320.extTextureShadowLod.frag",
298        "gl_samplemask_array_size.frag",
299        "glsl.ext.textureShadowLod.frag",
300        "terminate.frag",
301        "terminate.vert",
302        "negativeWorkGroupSize.comp",
303        "textureoffset_sampler2darrayshadow.vert",
304        "atomicAdd.comp",
305        "GL_ARB_gpu_shader5.u2i.vert",
306        "glsl.arbgpushader5.frag",
307        "textureQueryLOD.frag",
308        "atomicCounterARBOps.vert",
309        "GL_EXT_shader_integer_mix.vert",
310        "GL_ARB_draw_instanced.vert",
311        "GL_EXT_clip_cull_distance.300.vert",
312        "GL_EXT_clip_cull_distance.vert",
313        "GL_EXT_clip_cull_distance.geom",
314        "GL_EXT_clip_cull_distance.tesc",
315        "GL_EXT_clip_cull_distance.tese",
316        "GL_EXT_clip_cull_distance.frag",
317        "GL_EXT_clip_cull_distance.error.vert",
318        "GL_EXT_clip_cull_distance.limit.vert",
319        "GL_ARB_cull_distance.130.vert",
320        "GL_ARB_cull_distance.vert",
321        "GL_ARB_cull_distance.frag",
322        "GL_ARB_cull_distance.error.vert",
323        "GL_ARB_fragment_coord_conventions.vert",
324        "GL_ARB_bindless_texture.frag",
325        "GL_ARB_bindless_texture.lvalue.frag",
326        "GL_ARB_texture_multisample.vert",
327        "BestMatchFunction.vert",
328        "EndStreamPrimitive.geom",
329        "redeclareBlockMemberExtension.geom",
330        "floatBitsToInt.vert",
331        "coord_conventions.frag",
332        "gl_FragCoord.frag",
333        "glsl.interpOp.error.frag",
334        "glsl.nullInitializer.error.vert",
335        "location_aliasing.tesc",
336        "location_aliasing1.frag",
337        "GL_EXT_draw_instanced.vert",
338        "overflow_underflow_toinf_0.frag",
339        "GL_EXT_texture_array.frag",
340        "index_outside_sample_mask_range.frag",
341        "positive_infinity.frag",
342        "matrixCompMult.vert",
343        "ps_uint_int.frag",
344        "ps_sample.frag",
345        "tes_patch.tese",
346    })),
347    FileNameAsCustomTestSuffix
348);
349
350INSTANTIATE_TEST_SUITE_P(
351    Glsl, CompileToAstTestNV,
352    ::testing::ValuesIn(std::vector<std::string>({
353        "nvShaderNoperspectiveInterpolation.frag",
354        "glsl.nvgpushader5.frag",
355        "glsl.nvgpushader5.geom",
356        "glsl.nvgpushader5.vert",
357    })),
358    FileNameAsCustomTestSuffix
359);
360
361// clang-format on
362
363}  // anonymous namespace
364}  // namespace glslangtest