• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2017-2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <string>
16 #include <vector>
17 
18 #include "OpenCLDebugInfo100.h"
19 #include "gmock/gmock.h"
20 #include "source/util/string_utils.h"
21 #include "spirv/unified1/spirv.h"
22 #include "test/test_fixture.h"
23 #include "test/unit_spirv.h"
24 
25 // This file tests the correctness of encoding and decoding of instructions
26 // involving the OpenCL.DebugInfo.100 extended instruction set.
27 // Validation is not checked here.
28 
29 namespace spvtools {
30 namespace {
31 
32 using spvtest::Concatenate;
33 using spvtest::MakeInstruction;
34 using testing::Eq;
35 using utils::MakeVector;
36 
37 // Test values of enums vs. what is written in the spec.
38 
TEST(ExtInstCLDebugInfo,InstructionValues)39 TEST(ExtInstCLDebugInfo, InstructionValues) {
40   EXPECT_EQ(0, OpenCLDebugInfo100DebugInfoNone);
41   EXPECT_EQ(1, OpenCLDebugInfo100DebugCompilationUnit);
42   EXPECT_EQ(2, OpenCLDebugInfo100DebugTypeBasic);
43   EXPECT_EQ(3, OpenCLDebugInfo100DebugTypePointer);
44   EXPECT_EQ(4, OpenCLDebugInfo100DebugTypeQualifier);
45   EXPECT_EQ(5, OpenCLDebugInfo100DebugTypeArray);
46   EXPECT_EQ(6, OpenCLDebugInfo100DebugTypeVector);
47   EXPECT_EQ(7, OpenCLDebugInfo100DebugTypedef);
48   EXPECT_EQ(8, OpenCLDebugInfo100DebugTypeFunction);
49   EXPECT_EQ(9, OpenCLDebugInfo100DebugTypeEnum);
50   EXPECT_EQ(10, OpenCLDebugInfo100DebugTypeComposite);
51   EXPECT_EQ(11, OpenCLDebugInfo100DebugTypeMember);
52   EXPECT_EQ(12, OpenCLDebugInfo100DebugTypeInheritance);
53   EXPECT_EQ(13, OpenCLDebugInfo100DebugTypePtrToMember);
54   EXPECT_EQ(14, OpenCLDebugInfo100DebugTypeTemplate);
55   EXPECT_EQ(15, OpenCLDebugInfo100DebugTypeTemplateParameter);
56   EXPECT_EQ(16, OpenCLDebugInfo100DebugTypeTemplateTemplateParameter);
57   EXPECT_EQ(17, OpenCLDebugInfo100DebugTypeTemplateParameterPack);
58   EXPECT_EQ(18, OpenCLDebugInfo100DebugGlobalVariable);
59   EXPECT_EQ(19, OpenCLDebugInfo100DebugFunctionDeclaration);
60   EXPECT_EQ(20, OpenCLDebugInfo100DebugFunction);
61   EXPECT_EQ(21, OpenCLDebugInfo100DebugLexicalBlock);
62   EXPECT_EQ(22, OpenCLDebugInfo100DebugLexicalBlockDiscriminator);
63   EXPECT_EQ(23, OpenCLDebugInfo100DebugScope);
64   EXPECT_EQ(24, OpenCLDebugInfo100DebugNoScope);
65   EXPECT_EQ(25, OpenCLDebugInfo100DebugInlinedAt);
66   EXPECT_EQ(26, OpenCLDebugInfo100DebugLocalVariable);
67   EXPECT_EQ(27, OpenCLDebugInfo100DebugInlinedVariable);
68   EXPECT_EQ(28, OpenCLDebugInfo100DebugDeclare);
69   EXPECT_EQ(29, OpenCLDebugInfo100DebugValue);
70   EXPECT_EQ(30, OpenCLDebugInfo100DebugOperation);
71   EXPECT_EQ(31, OpenCLDebugInfo100DebugExpression);
72   EXPECT_EQ(32, OpenCLDebugInfo100DebugMacroDef);
73   EXPECT_EQ(33, OpenCLDebugInfo100DebugMacroUndef);
74   EXPECT_EQ(34, OpenCLDebugInfo100DebugImportedEntity);
75   EXPECT_EQ(35, OpenCLDebugInfo100DebugSource);
76 }
77 
TEST(ExtInstCLDebugInfo,InfoFlagValues)78 TEST(ExtInstCLDebugInfo, InfoFlagValues) {
79   EXPECT_EQ(1 << 0, OpenCLDebugInfo100FlagIsProtected);
80   EXPECT_EQ(1 << 1, OpenCLDebugInfo100FlagIsPrivate);
81   EXPECT_EQ(((1 << 0) | (1 << 1)), OpenCLDebugInfo100FlagIsPublic);
82   EXPECT_EQ(1 << 2, OpenCLDebugInfo100FlagIsLocal);
83   EXPECT_EQ(1 << 3, OpenCLDebugInfo100FlagIsDefinition);
84   EXPECT_EQ(1 << 4, OpenCLDebugInfo100FlagFwdDecl);
85   EXPECT_EQ(1 << 5, OpenCLDebugInfo100FlagArtificial);
86   EXPECT_EQ(1 << 6, OpenCLDebugInfo100FlagExplicit);
87   EXPECT_EQ(1 << 7, OpenCLDebugInfo100FlagPrototyped);
88   EXPECT_EQ(1 << 8, OpenCLDebugInfo100FlagObjectPointer);
89   EXPECT_EQ(1 << 9, OpenCLDebugInfo100FlagStaticMember);
90   EXPECT_EQ(1 << 10, OpenCLDebugInfo100FlagIndirectVariable);
91   EXPECT_EQ(1 << 11, OpenCLDebugInfo100FlagLValueReference);
92   EXPECT_EQ(1 << 12, OpenCLDebugInfo100FlagRValueReference);
93   EXPECT_EQ(1 << 13, OpenCLDebugInfo100FlagIsOptimized);
94   EXPECT_EQ(1 << 14, OpenCLDebugInfo100FlagIsEnumClass);
95   EXPECT_EQ(1 << 15, OpenCLDebugInfo100FlagTypePassByValue);
96   EXPECT_EQ(1 << 16, OpenCLDebugInfo100FlagTypePassByReference);
97 }
98 
TEST(ExtInstCLDebugInfo,BaseTypeAttributeEndodingValues)99 TEST(ExtInstCLDebugInfo, BaseTypeAttributeEndodingValues) {
100   EXPECT_EQ(0, OpenCLDebugInfo100Unspecified);
101   EXPECT_EQ(1, OpenCLDebugInfo100Address);
102   EXPECT_EQ(2, OpenCLDebugInfo100Boolean);
103   EXPECT_EQ(3, OpenCLDebugInfo100Float);
104   EXPECT_EQ(4, OpenCLDebugInfo100Signed);
105   EXPECT_EQ(5, OpenCLDebugInfo100SignedChar);
106   EXPECT_EQ(6, OpenCLDebugInfo100Unsigned);
107   EXPECT_EQ(7, OpenCLDebugInfo100UnsignedChar);
108 }
109 
TEST(ExtInstCLDebugInfo,CompositeTypeValues)110 TEST(ExtInstCLDebugInfo, CompositeTypeValues) {
111   EXPECT_EQ(0, OpenCLDebugInfo100Class);
112   EXPECT_EQ(1, OpenCLDebugInfo100Structure);
113   EXPECT_EQ(2, OpenCLDebugInfo100Union);
114 }
115 
TEST(ExtInstCLDebugInfo,TypeQualifierValues)116 TEST(ExtInstCLDebugInfo, TypeQualifierValues) {
117   EXPECT_EQ(0, OpenCLDebugInfo100ConstType);
118   EXPECT_EQ(1, OpenCLDebugInfo100VolatileType);
119   EXPECT_EQ(2, OpenCLDebugInfo100RestrictType);
120   EXPECT_EQ(3, OpenCLDebugInfo100AtomicType);
121 }
122 
TEST(ExtInstCLDebugInfo,DebugOperationValues)123 TEST(ExtInstCLDebugInfo, DebugOperationValues) {
124   EXPECT_EQ(0, OpenCLDebugInfo100Deref);
125   EXPECT_EQ(1, OpenCLDebugInfo100Plus);
126   EXPECT_EQ(2, OpenCLDebugInfo100Minus);
127   EXPECT_EQ(3, OpenCLDebugInfo100PlusUconst);
128   EXPECT_EQ(4, OpenCLDebugInfo100BitPiece);
129   EXPECT_EQ(5, OpenCLDebugInfo100Swap);
130   EXPECT_EQ(6, OpenCLDebugInfo100Xderef);
131   EXPECT_EQ(7, OpenCLDebugInfo100StackValue);
132   EXPECT_EQ(8, OpenCLDebugInfo100Constu);
133   EXPECT_EQ(9, OpenCLDebugInfo100Fragment);
134 }
135 
TEST(ExtInstCLDebugInfo,ImportedEntityValues)136 TEST(ExtInstCLDebugInfo, ImportedEntityValues) {
137   EXPECT_EQ(0, OpenCLDebugInfo100ImportedModule);
138   EXPECT_EQ(1, OpenCLDebugInfo100ImportedDeclaration);
139 }
140 
141 // Test round trip through assembler and disassembler.
142 
143 struct InstructionCase {
144   uint32_t opcode;
145   std::string name;
146   std::string operands;
147   std::vector<uint32_t> expected_operands;
148 };
149 
150 using ExtInstCLDebugInfo100RoundTripTest =
151     spvtest::TextToBinaryTestBase<::testing::TestWithParam<InstructionCase>>;
152 using ExtInstCLDebugInfo100RoundTripTestExplicit = spvtest::TextToBinaryTest;
153 
TEST_P(ExtInstCLDebugInfo100RoundTripTest,ParameterizedExtInst)154 TEST_P(ExtInstCLDebugInfo100RoundTripTest, ParameterizedExtInst) {
155   const std::string input =
156       "%1 = OpExtInstImport \"OpenCL.DebugInfo.100\"\n"
157       "%3 = OpExtInst %2 %1 " +
158       GetParam().name + GetParam().operands + "\n";
159   // First make sure it assembles correctly.
160   std::cout << input << std::endl;
161   EXPECT_THAT(CompiledInstructions(input),
162               Eq(Concatenate(
163                   {MakeInstruction(SpvOpExtInstImport, {1},
164                                    MakeVector("OpenCL.DebugInfo.100")),
165                    MakeInstruction(SpvOpExtInst, {2, 3, 1, GetParam().opcode},
166                                    GetParam().expected_operands)})))
167       << input;
168   // Now check the round trip through the disassembler.
169   EXPECT_THAT(EncodeAndDecodeSuccessfully(input), input) << input;
170 }
171 
172 #define EPREFIX "Debug"
173 
174 #define CASE_0(Enum)                                               \
175   {                                                                \
176     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, "", {} \
177   }
178 
179 #define CASE_ILL(Enum, L0, L1)                              \
180   {                                                         \
181     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
182         " %4 " #L0 " " #L1, {                               \
183       4, L0, L1                                             \
184     }                                                       \
185   }
186 
187 #define CASE_IL(Enum, L0)                                                 \
188   {                                                                       \
189     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " %4 " #L0, { \
190       4, L0                                                               \
191     }                                                                     \
192   }
193 
194 #define CASE_I(Enum)                                                     \
195   {                                                                      \
196     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " %4", { 4 } \
197   }
198 
199 #define CASE_II(Enum)                                                          \
200   {                                                                            \
201     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " %4 %5", { 4, 5 } \
202   }
203 
204 #define CASE_III(Enum)                                                     \
205   {                                                                        \
206     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " %4 %5 %6", { \
207       4, 5, 6                                                              \
208     }                                                                      \
209   }
210 
211 #define CASE_IIII(Enum)                                                       \
212   {                                                                           \
213     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " %4 %5 %6 %7", { \
214       4, 5, 6, 7                                                              \
215     }                                                                         \
216   }
217 
218 #define CASE_IIIII(Enum)                                                       \
219   {                                                                            \
220     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " %4 %5 %6 %7 %8", \
221     {                                                                          \
222       4, 5, 6, 7, 8                                                            \
223     }                                                                          \
224   }
225 
226 #define CASE_IIIIII(Enum)                                   \
227   {                                                         \
228     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
229         " %4 %5 %6 %7 %8 %9", {                             \
230       4, 5, 6, 7, 8, 9                                      \
231     }                                                       \
232   }
233 
234 #define CASE_IIIIIII(Enum)                                  \
235   {                                                         \
236     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
237         " %4 %5 %6 %7 %8 %9 %10", {                         \
238       4, 5, 6, 7, 8, 9, 10                                  \
239     }                                                       \
240   }
241 
242 #define CASE_IIILLI(Enum, L0, L1)                           \
243   {                                                         \
244     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
245         " %4 %5 %6 " #L0 " " #L1 " %7", {                   \
246       4, 5, 6, L0, L1, 7                                    \
247     }                                                       \
248   }
249 
250 #define CASE_IIILLIF(Enum, L0, L1, Fstr, Fnum)              \
251   {                                                         \
252     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
253         " %4 %5 %6 " #L0 " " #L1 " %7 " Fstr, {             \
254       4, 5, 6, L0, L1, 7, Fnum                              \
255     }                                                       \
256   }
257 
258 #define CASE_IIILLIFL(Enum, L0, L1, Fstr, Fnum, L2)         \
259   {                                                         \
260     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
261         " %4 %5 %6 " #L0 " " #L1 " %7 " Fstr " " #L2, {     \
262       4, 5, 6, L0, L1, 7, Fnum, L2                          \
263     }                                                       \
264   }
265 
266 #define CASE_IIILLIL(Enum, L0, L1, L2)                      \
267   {                                                         \
268     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
269         " %4 %5 %6 " #L0 " " #L1 " %7 " #L2, {              \
270       4, 5, 6, L0, L1, 7, L2                                \
271     }                                                       \
272   }
273 
274 #define CASE_IE(Enum, E0)                                                 \
275   {                                                                       \
276     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " %4 " #E0, { \
277       4, uint32_t(OpenCLDebugInfo100##E0)                                 \
278     }                                                                     \
279   }
280 
281 #define CASE_IEIILLI(Enum, E0, L1, L2)                      \
282   {                                                         \
283     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
284         " %4 " #E0 " %5 %6 " #L1 " " #L2 " %7", {           \
285       4, uint32_t(OpenCLDebugInfo100##E0), 5, 6, L1, L2, 7  \
286     }                                                       \
287   }
288 
289 #define CASE_IIE(Enum, E0)                                                   \
290   {                                                                          \
291     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " %4 %5 " #E0, { \
292       4, 5, uint32_t(OpenCLDebugInfo100##E0)                                 \
293     }                                                                        \
294   }
295 
296 #define CASE_ISF(Enum, S0, Fstr, Fnum)                      \
297   {                                                         \
298     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
299         " %4 " #S0 " " Fstr, {                              \
300       4, uint32_t(SpvStorageClass##S0), Fnum                \
301     }                                                       \
302   }
303 
304 #define CASE_LII(Enum, L0)                                                    \
305   {                                                                           \
306     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " " #L0 " %4 %5", \
307     {                                                                         \
308       L0, 4, 5                                                                \
309     }                                                                         \
310   }
311 
312 #define CASE_LLIe(Enum, L0, L1, RawEnumName, RawEnumValue)  \
313   {                                                         \
314     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
315         " " #L0 " " #L1 " %4 " RawEnumName, {               \
316       L0, L1, 4, RawEnumValue                               \
317     }                                                       \
318   }
319 
320 #define CASE_ILI(Enum, L0)                                                    \
321   {                                                                           \
322     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " %4 " #L0 " %5", \
323     {                                                                         \
324       4, L0, 5                                                                \
325     }                                                                         \
326   }
327 
328 #define CASE_ILII(Enum, L0)                                 \
329   {                                                         \
330     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
331         " %4 " #L0 " %5 %6", {                              \
332       4, L0, 5, 6                                           \
333     }                                                       \
334   }
335 
336 #define CASE_ILLII(Enum, L0, L1)                            \
337   {                                                         \
338     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
339         " %4 " #L0 " " #L1 " %5 %6", {                      \
340       4, L0, L1, 5, 6                                       \
341     }                                                       \
342   }
343 
344 #define CASE_IIILLIIF(Enum, L0, L1, Fstr, Fnum)             \
345   {                                                         \
346     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
347         " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr, {          \
348       4, 5, 6, L0, L1, 7, 8, Fnum                           \
349     }                                                       \
350   }
351 
352 #define CASE_IIILLIIFII(Enum, L0, L1, Fstr, Fnum)            \
353   {                                                          \
354     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,  \
355         " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr " %9 %10", { \
356       4, 5, 6, L0, L1, 7, 8, Fnum, 9, 10                     \
357     }                                                        \
358   }
359 
360 #define CASE_IIILLIIFIIII(Enum, L0, L1, Fstr, Fnum)                  \
361   {                                                                  \
362     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,          \
363         " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr " %9 %10 %11 %12", { \
364       4, 5, 6, L0, L1, 7, 8, Fnum, 9, 10, 11, 12                     \
365     }                                                                \
366   }
367 
368 #define CASE_IIILLIIFIIIIII(Enum, L0, L1, Fstr, Fnum)                        \
369   {                                                                          \
370     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,                  \
371         " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr " %9 %10 %11 %12 %13 %14", { \
372       4, 5, 6, L0, L1, 7, 8, Fnum, 9, 10, 11, 12, 13, 14                     \
373     }                                                                        \
374   }
375 
376 #define CASE_IEILLIIIF(Enum, E0, L0, L1, Fstr, Fnum)                \
377   {                                                                 \
378     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,         \
379         " %4 " #E0 " %5 " #L0 " " #L1 " %6 %7 %8 " Fstr, {          \
380       4, uint32_t(OpenCLDebugInfo100##E0), 5, L0, L1, 6, 7, 8, Fnum \
381     }                                                               \
382   }
383 
384 #define CASE_IEILLIIIFI(Enum, E0, L0, L1, Fstr, Fnum)                  \
385   {                                                                    \
386     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,            \
387         " %4 " #E0 " %5 " #L0 " " #L1 " %6 %7 %8 " Fstr " %9", {       \
388       4, uint32_t(OpenCLDebugInfo100##E0), 5, L0, L1, 6, 7, 8, Fnum, 9 \
389     }                                                                  \
390   }
391 
392 #define CASE_IEILLIIIFII(Enum, E0, L0, L1, Fstr, Fnum)                     \
393   {                                                                        \
394     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,                \
395         " %4 " #E0 " %5 " #L0 " " #L1 " %6 %7 %8 " Fstr " %9 %10", {       \
396       4, uint32_t(OpenCLDebugInfo100##E0), 5, L0, L1, 6, 7, 8, Fnum, 9, 10 \
397     }                                                                      \
398   }
399 
400 #define CASE_IEILLIIIFIII(Enum, E0, L0, L1, Fstr, Fnum)                        \
401   {                                                                            \
402     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,                    \
403         " %4 " #E0 " %5 " #L0 " " #L1 " %6 %7 %8 " Fstr " %9 %10 %11", {       \
404       4, uint32_t(OpenCLDebugInfo100##E0), 5, L0, L1, 6, 7, 8, Fnum, 9, 10, 11 \
405     }                                                                          \
406   }
407 
408 #define CASE_IEILLIIIFIIII(Enum, E0, L0, L1, Fstr, Fnum)                     \
409   {                                                                          \
410     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,                  \
411         " %4 " #E0 " %5 " #L0 " " #L1 " %6 %7 %8 " Fstr " %9 %10 %11 %12", { \
412       4, uint32_t(OpenCLDebugInfo100##E0), 5, L0, L1, 6, 7, 8, Fnum, 9, 10,  \
413           11, 12                                                             \
414     }                                                                        \
415   }
416 
417 #define CASE_IIILLIIIF(Enum, L0, L1, Fstr, Fnum)            \
418   {                                                         \
419     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
420         " %4 %5 %6 " #L0 " " #L1 " %7 %8 %9 " Fstr, {       \
421       4, 5, 6, L0, L1, 7, 8, 9, Fnum                        \
422     }                                                       \
423   }
424 
425 #define CASE_IIILLIIIFI(Enum, L0, L1, Fstr, Fnum)            \
426   {                                                          \
427     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,  \
428         " %4 %5 %6 " #L0 " " #L1 " %7 %8 %9 " Fstr " %10", { \
429       4, 5, 6, L0, L1, 7, 8, 9, Fnum, 10                     \
430     }                                                        \
431   }
432 
433 #define CASE_IIIIF(Enum, Fstr, Fnum)                        \
434   {                                                         \
435     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
436         " %4 %5 %6 %7 " Fstr, {                             \
437       4, 5, 6, 7, Fnum                                      \
438     }                                                       \
439   }
440 
441 #define CASE_IIILL(Enum, L0, L1)                            \
442   {                                                         \
443     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
444         " %4 %5 %6 " #L0 " " #L1, {                         \
445       4, 5, 6, L0, L1                                       \
446     }                                                       \
447   }
448 
449 #define CASE_IIIILL(Enum, L0, L1)                           \
450   {                                                         \
451     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
452         " %4 %5 %6 %7 " #L0 " " #L1, {                      \
453       4, 5, 6, 7, L0, L1                                    \
454     }                                                       \
455   }
456 
457 #define CASE_IILLI(Enum, L0, L1)                            \
458   {                                                         \
459     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
460         " %4 %5 " #L0 " " #L1 " %6", {                      \
461       4, 5, L0, L1, 6                                       \
462     }                                                       \
463   }
464 
465 #define CASE_IILLII(Enum, L0, L1)                           \
466   {                                                         \
467     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
468         " %4 %5 " #L0 " " #L1 " %6 %7", {                   \
469       4, 5, L0, L1, 6, 7                                    \
470     }                                                       \
471   }
472 
473 #define CASE_IILLIII(Enum, L0, L1)                          \
474   {                                                         \
475     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
476         " %4 %5 " #L0 " " #L1 " %6 %7 %8", {                \
477       4, 5, L0, L1, 6, 7, 8                                 \
478     }                                                       \
479   }
480 
481 #define CASE_IILLIIII(Enum, L0, L1)                         \
482   {                                                         \
483     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
484         " %4 %5 " #L0 " " #L1 " %6 %7 %8 %9", {             \
485       4, 5, L0, L1, 6, 7, 8, 9                              \
486     }                                                       \
487   }
488 
489 #define CASE_IIILLIIFLI(Enum, L0, L1, Fstr, Fnum, L2)            \
490   {                                                              \
491     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,      \
492         " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr " " #L2 " %9", { \
493       4, 5, 6, L0, L1, 7, 8, Fnum, L2, 9                         \
494     }                                                            \
495   }
496 
497 #define CASE_IIILLIIFLII(Enum, L0, L1, Fstr, Fnum, L2)               \
498   {                                                                  \
499     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum,          \
500         " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr " " #L2 " %9 %10", { \
501       4, 5, 6, L0, L1, 7, 8, Fnum, L2, 9, 10                         \
502     }                                                                \
503   }
504 
505 #define CASE_E(Enum, E0)                                               \
506   {                                                                    \
507     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " " #E0, { \
508       uint32_t(OpenCLDebugInfo100##E0)                                 \
509     }                                                                  \
510   }
511 
512 #define CASE_EI(Enum, E0)                                                    \
513   {                                                                          \
514     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " " #E0 " %4", { \
515       uint32_t(OpenCLDebugInfo100##E0), 4                                    \
516     }                                                                        \
517   }
518 
519 #define CASE_EII(Enum, E0)                                                    \
520   {                                                                           \
521     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " " #E0 " %4 %5", \
522     {                                                                         \
523       uint32_t(OpenCLDebugInfo100##E0), 4, 5                                  \
524     }                                                                         \
525   }
526 
527 #define CASE_EIII(Enum, E0)                                 \
528   {                                                         \
529     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
530         " " #E0 " %4 %5 %6", {                              \
531       uint32_t(OpenCLDebugInfo100##E0), 4, 5, 6             \
532     }                                                       \
533   }
534 
535 #define CASE_EIIII(Enum, E0)                                \
536   {                                                         \
537     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
538         " " #E0 " %4 %5 %6 %7", {                           \
539       uint32_t(OpenCLDebugInfo100##E0), 4, 5, 6, 7          \
540     }                                                       \
541   }
542 
543 #define CASE_EIIIII(Enum, E0)                               \
544   {                                                         \
545     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
546         " " #E0 " %4 %5 %6 %7 %8", {                        \
547       uint32_t(OpenCLDebugInfo100##E0), 4, 5, 6, 7, 8       \
548     }                                                       \
549   }
550 
551 #define CASE_EL(Enum, E0, L0)                                                  \
552   {                                                                            \
553     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, " " #E0 " " #L0, { \
554       uint32_t(OpenCLDebugInfo100##E0), L0                                     \
555     }                                                                          \
556   }
557 
558 #define CASE_ELL(Enum, E0, L0, L1)                          \
559   {                                                         \
560     uint32_t(OpenCLDebugInfo100Debug##Enum), EPREFIX #Enum, \
561         " " #E0 " " #L0 " " #L1, {                          \
562       uint32_t(OpenCLDebugInfo100##E0), L0, L1              \
563     }                                                       \
564   }
565 
566 // OpenCL.DebugInfo.100 4.1 Missing Debugging Information
567 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugInfoNone,
568                          ExtInstCLDebugInfo100RoundTripTest,
569                          ::testing::ValuesIn(std::vector<InstructionCase>({
570                              CASE_0(InfoNone),  // enum value 0
571                          })));
572 
573 // OpenCL.DebugInfo.100 4.2 Compilation Unit
574 INSTANTIATE_TEST_SUITE_P(
575     OpenCLDebugInfo100DebugCompilationUnit, ExtInstCLDebugInfo100RoundTripTest,
576     ::testing::ValuesIn(std::vector<InstructionCase>({
577         CASE_LLIe(CompilationUnit, 100, 42, "HLSL", SpvSourceLanguageHLSL),
578     })));
579 
580 INSTANTIATE_TEST_SUITE_P(
581     OpenCLDebugInfo100DebugSource, ExtInstCLDebugInfo100RoundTripTest,
582     ::testing::ValuesIn(std::vector<InstructionCase>({
583         // TODO(dneto): Should this be a list of sourc texts,
584         // to accomodate length limits?
585         CASE_I(Source),
586         CASE_II(Source),
587     })));
588 
589 // OpenCL.DebugInfo.100 4.3 Type instructions
590 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypeBasic,
591                          ExtInstCLDebugInfo100RoundTripTest,
592                          ::testing::ValuesIn(std::vector<InstructionCase>({
593                              CASE_IIE(TypeBasic, Unspecified),
594                              CASE_IIE(TypeBasic, Address),
595                              CASE_IIE(TypeBasic, Boolean),
596                              CASE_IIE(TypeBasic, Float),
597                              CASE_IIE(TypeBasic, Signed),
598                              CASE_IIE(TypeBasic, SignedChar),
599                              CASE_IIE(TypeBasic, Unsigned),
600                              CASE_IIE(TypeBasic, UnsignedChar),
601                          })));
602 
603 // The FlagIsPublic is value is (1 << 0) | (1 << 2) which is the same
604 // as the bitwise-OR of FlagIsProtected and FlagIsPrivate.
605 // The disassembler will emit the compound expression instead.
606 // There is no simple fix for this.  This enum is not really a mask
607 // for the bottom two bits.
TEST_F(ExtInstCLDebugInfo100RoundTripTestExplicit,FlagIsPublic)608 TEST_F(ExtInstCLDebugInfo100RoundTripTestExplicit, FlagIsPublic) {
609   const std::string prefix =
610       "%1 = OpExtInstImport \"DebugInfo\"\n"
611       "%3 = OpExtInst %2 %1 DebugTypePointer %4 Private ";
612   const std::string input = prefix + "FlagIsPublic\n";
613   const std::string expected = prefix + "FlagIsProtected|FlagIsPrivate\n";
614   // First make sure it assembles correctly.
615   EXPECT_THAT(
616       CompiledInstructions(input),
617       Eq(Concatenate(
618           {MakeInstruction(SpvOpExtInstImport, {1}, MakeVector("DebugInfo")),
619            MakeInstruction(SpvOpExtInst,
620                            {2, 3, 1, OpenCLDebugInfo100DebugTypePointer, 4,
621                             uint32_t(SpvStorageClassPrivate),
622                             OpenCLDebugInfo100FlagIsPublic})})))
623       << input;
624   // Now check the round trip through the disassembler.
625   EXPECT_THAT(EncodeAndDecodeSuccessfully(input), Eq(expected)) << input;
626 }
627 
628 INSTANTIATE_TEST_SUITE_P(
629     OpenCLDebugInfo100DebugTypePointer, ExtInstCLDebugInfo100RoundTripTest,
630     ::testing::ValuesIn(std::vector<InstructionCase>({
631 
632         //// Use each flag independently.
633         CASE_ISF(TypePointer, Private, "FlagIsProtected",
634                  uint32_t(OpenCLDebugInfo100FlagIsProtected)),
635         CASE_ISF(TypePointer, Private, "FlagIsPrivate",
636                  uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
637 
638         // FlagIsPublic is tested above.
639 
640         CASE_ISF(TypePointer, Private, "FlagIsLocal",
641                  uint32_t(OpenCLDebugInfo100FlagIsLocal)),
642         CASE_ISF(TypePointer, Private, "FlagIsDefinition",
643                  uint32_t(OpenCLDebugInfo100FlagIsDefinition)),
644         CASE_ISF(TypePointer, Private, "FlagFwdDecl",
645                  uint32_t(OpenCLDebugInfo100FlagFwdDecl)),
646         CASE_ISF(TypePointer, Private, "FlagArtificial",
647                  uint32_t(OpenCLDebugInfo100FlagArtificial)),
648         CASE_ISF(TypePointer, Private, "FlagExplicit",
649                  uint32_t(OpenCLDebugInfo100FlagExplicit)),
650         CASE_ISF(TypePointer, Private, "FlagPrototyped",
651                  uint32_t(OpenCLDebugInfo100FlagPrototyped)),
652         CASE_ISF(TypePointer, Private, "FlagObjectPointer",
653                  uint32_t(OpenCLDebugInfo100FlagObjectPointer)),
654         CASE_ISF(TypePointer, Private, "FlagStaticMember",
655                  uint32_t(OpenCLDebugInfo100FlagStaticMember)),
656         CASE_ISF(TypePointer, Private, "FlagIndirectVariable",
657                  uint32_t(OpenCLDebugInfo100FlagIndirectVariable)),
658         CASE_ISF(TypePointer, Private, "FlagLValueReference",
659                  uint32_t(OpenCLDebugInfo100FlagLValueReference)),
660         CASE_ISF(TypePointer, Private, "FlagIsOptimized",
661                  uint32_t(OpenCLDebugInfo100FlagIsOptimized)),
662         CASE_ISF(TypePointer, Private, "FlagIsEnumClass",
663                  uint32_t(OpenCLDebugInfo100FlagIsEnumClass)),
664         CASE_ISF(TypePointer, Private, "FlagTypePassByValue",
665                  uint32_t(OpenCLDebugInfo100FlagTypePassByValue)),
666         CASE_ISF(TypePointer, Private, "FlagTypePassByReference",
667                  uint32_t(OpenCLDebugInfo100FlagTypePassByReference)),
668 
669         //// Use flags in combination, and try different storage classes.
670         CASE_ISF(TypePointer, Function, "FlagIsProtected|FlagIsPrivate",
671                  uint32_t(OpenCLDebugInfo100FlagIsProtected) |
672                      uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
673         CASE_ISF(
674             TypePointer, Workgroup,
675             "FlagIsPrivate|FlagFwdDecl|FlagIndirectVariable|FlagIsOptimized",
676             uint32_t(OpenCLDebugInfo100FlagIsPrivate) |
677                 uint32_t(OpenCLDebugInfo100FlagFwdDecl) |
678                 uint32_t(OpenCLDebugInfo100FlagIndirectVariable) |
679                 uint32_t(OpenCLDebugInfo100FlagIsOptimized)),
680 
681     })));
682 
683 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypeQualifier,
684                          ExtInstCLDebugInfo100RoundTripTest,
685                          ::testing::ValuesIn(std::vector<InstructionCase>({
686                              CASE_IE(TypeQualifier, ConstType),
687                              CASE_IE(TypeQualifier, VolatileType),
688                              CASE_IE(TypeQualifier, RestrictType),
689                              CASE_IE(TypeQualifier, AtomicType),
690                          })));
691 
692 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypeArray,
693                          ExtInstCLDebugInfo100RoundTripTest,
694                          ::testing::ValuesIn(std::vector<InstructionCase>({
695                              CASE_II(TypeArray),
696                              CASE_III(TypeArray),
697                              CASE_IIII(TypeArray),
698                              CASE_IIIII(TypeArray),
699                          })));
700 
701 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypeVector,
702                          ExtInstCLDebugInfo100RoundTripTest,
703                          ::testing::ValuesIn(std::vector<InstructionCase>({
704                              CASE_IL(TypeVector, 2),
705                              CASE_IL(TypeVector, 3),
706                              CASE_IL(TypeVector, 4),
707                              CASE_IL(TypeVector, 16),
708                          })));
709 
710 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypedef,
711                          ExtInstCLDebugInfo100RoundTripTest,
712                          ::testing::ValuesIn(std::vector<InstructionCase>({
713                              CASE_IIILLI(Typedef, 12, 13),
714                              CASE_IIILLI(Typedef, 14, 99),
715                          })));
716 
717 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypeFunction,
718                          ExtInstCLDebugInfo100RoundTripTest,
719                          ::testing::ValuesIn(std::vector<InstructionCase>({
720                              CASE_EI(TypeFunction, FlagIsProtected),
721                              CASE_EII(TypeFunction, FlagIsDefinition),
722                              CASE_EIII(TypeFunction, FlagArtificial),
723                              CASE_EIIII(TypeFunction, FlagExplicit),
724                              CASE_EIIIII(TypeFunction, FlagIsPrivate),
725                          })));
726 
727 INSTANTIATE_TEST_SUITE_P(
728     OpenCLDebugInfo100DebugTypeEnum, ExtInstCLDebugInfo100RoundTripTest,
729     ::testing::ValuesIn(std::vector<InstructionCase>({
730         CASE_IIILLIIFII(
731             TypeEnum, 12, 13,
732             "FlagIsPrivate|FlagFwdDecl|FlagIndirectVariable|FlagIsOptimized",
733             uint32_t(OpenCLDebugInfo100FlagIsPrivate) |
734                 uint32_t(OpenCLDebugInfo100FlagFwdDecl) |
735                 uint32_t(OpenCLDebugInfo100FlagIndirectVariable) |
736                 uint32_t(OpenCLDebugInfo100FlagIsOptimized)),
737         CASE_IIILLIIFIIII(TypeEnum, 17, 18, "FlagStaticMember",
738                           uint32_t(OpenCLDebugInfo100FlagStaticMember)),
739         CASE_IIILLIIFIIIIII(TypeEnum, 99, 1, "FlagStaticMember",
740                             uint32_t(OpenCLDebugInfo100FlagStaticMember)),
741     })));
742 
743 INSTANTIATE_TEST_SUITE_P(
744     OpenCLDebugInfo100DebugTypeComposite, ExtInstCLDebugInfo100RoundTripTest,
745     ::testing::ValuesIn(std::vector<InstructionCase>({
746         CASE_IEILLIIIF(
747             TypeComposite, Class, 12, 13,
748             "FlagIsPrivate|FlagFwdDecl|FlagIndirectVariable|FlagIsOptimized",
749             uint32_t(OpenCLDebugInfo100FlagIsPrivate) |
750                 uint32_t(OpenCLDebugInfo100FlagFwdDecl) |
751                 uint32_t(OpenCLDebugInfo100FlagIndirectVariable) |
752                 uint32_t(OpenCLDebugInfo100FlagIsOptimized)),
753         // Cover all tag values: Class, Structure, Union
754         CASE_IEILLIIIF(TypeComposite, Class, 12, 13, "FlagIsPrivate",
755                        uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
756         CASE_IEILLIIIF(TypeComposite, Structure, 12, 13, "FlagIsPrivate",
757                        uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
758         CASE_IEILLIIIF(TypeComposite, Union, 12, 13, "FlagIsPrivate",
759                        uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
760         // Now add members
761         CASE_IEILLIIIFI(TypeComposite, Class, 9, 10, "FlagIsPrivate",
762                         uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
763         CASE_IEILLIIIFII(TypeComposite, Class, 9, 10, "FlagIsPrivate",
764                          uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
765         CASE_IEILLIIIFIII(TypeComposite, Class, 9, 10, "FlagIsPrivate",
766                           uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
767         CASE_IEILLIIIFIIII(TypeComposite, Class, 9, 10, "FlagIsPrivate",
768                            uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
769     })));
770 
771 INSTANTIATE_TEST_SUITE_P(
772     OpenCLDebugInfo100DebugTypeMember, ExtInstCLDebugInfo100RoundTripTest,
773     ::testing::ValuesIn(std::vector<InstructionCase>({
774         CASE_IIILLIIIF(TypeMember, 12, 13, "FlagIsPrivate",
775                        uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
776         CASE_IIILLIIIF(TypeMember, 99, 100, "FlagIsPrivate|FlagFwdDecl",
777                        uint32_t(OpenCLDebugInfo100FlagIsPrivate) |
778                            uint32_t(OpenCLDebugInfo100FlagFwdDecl)),
779         // Add the optional Id argument.
780         CASE_IIILLIIIFI(TypeMember, 12, 13, "FlagIsPrivate",
781                         uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
782     })));
783 
784 INSTANTIATE_TEST_SUITE_P(
785     OpenCLDebugInfo100DebugTypeInheritance, ExtInstCLDebugInfo100RoundTripTest,
786     ::testing::ValuesIn(std::vector<InstructionCase>({
787         CASE_IIIIF(TypeInheritance, "FlagIsPrivate",
788                    uint32_t(OpenCLDebugInfo100FlagIsPrivate)),
789         CASE_IIIIF(TypeInheritance, "FlagIsPrivate|FlagFwdDecl",
790                    uint32_t(OpenCLDebugInfo100FlagIsPrivate) |
791                        uint32_t(OpenCLDebugInfo100FlagFwdDecl)),
792     })));
793 
794 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypePtrToMember,
795                          ExtInstCLDebugInfo100RoundTripTest,
796                          ::testing::ValuesIn(std::vector<InstructionCase>({
797                              CASE_II(TypePtrToMember),
798                          })));
799 
800 // OpenCL.DebugInfo.100 4.4 Templates
801 
802 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypeTemplate,
803                          ExtInstCLDebugInfo100RoundTripTest,
804                          ::testing::ValuesIn(std::vector<InstructionCase>({
805                              CASE_II(TypeTemplate),
806                              CASE_III(TypeTemplate),
807                              CASE_IIII(TypeTemplate),
808                              CASE_IIIII(TypeTemplate),
809                          })));
810 
811 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypeTemplateParameter,
812                          ExtInstCLDebugInfo100RoundTripTest,
813                          ::testing::ValuesIn(std::vector<InstructionCase>({
814                              CASE_IIIILL(TypeTemplateParameter, 1, 2),
815                              CASE_IIIILL(TypeTemplateParameter, 99, 102),
816                              CASE_IIIILL(TypeTemplateParameter, 10, 7),
817                          })));
818 
819 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypeTemplateTemplateParameter,
820                          ExtInstCLDebugInfo100RoundTripTest,
821                          ::testing::ValuesIn(std::vector<InstructionCase>({
822                              CASE_IIILL(TypeTemplateTemplateParameter, 1, 2),
823                              CASE_IIILL(TypeTemplateTemplateParameter, 99, 102),
824                              CASE_IIILL(TypeTemplateTemplateParameter, 10, 7),
825                          })));
826 
827 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugTypeTemplateParameterPack,
828                          ExtInstCLDebugInfo100RoundTripTest,
829                          ::testing::ValuesIn(std::vector<InstructionCase>({
830                              CASE_IILLI(TypeTemplateParameterPack, 1, 2),
831                              CASE_IILLII(TypeTemplateParameterPack, 99, 102),
832                              CASE_IILLIII(TypeTemplateParameterPack, 10, 7),
833                              CASE_IILLIIII(TypeTemplateParameterPack, 10, 7),
834                          })));
835 
836 // OpenCL.DebugInfo.100 4.5 Global Variables
837 
838 INSTANTIATE_TEST_SUITE_P(
839     OpenCLDebugInfo100DebugGlobalVariable, ExtInstCLDebugInfo100RoundTripTest,
840     ::testing::ValuesIn(std::vector<InstructionCase>({
841         CASE_IIILLIIIF(GlobalVariable, 1, 2, "FlagIsOptimized",
842                        uint32_t(OpenCLDebugInfo100FlagIsOptimized)),
843         CASE_IIILLIIIF(GlobalVariable, 42, 43, "FlagIsOptimized",
844                        uint32_t(OpenCLDebugInfo100FlagIsOptimized)),
845         CASE_IIILLIIIFI(GlobalVariable, 1, 2, "FlagIsOptimized",
846                         uint32_t(OpenCLDebugInfo100FlagIsOptimized)),
847         CASE_IIILLIIIFI(GlobalVariable, 42, 43, "FlagIsOptimized",
848                         uint32_t(OpenCLDebugInfo100FlagIsOptimized)),
849     })));
850 
851 // OpenCL.DebugInfo.100 4.6 Functions
852 
853 INSTANTIATE_TEST_SUITE_P(
854     OpenCLDebugInfo100DebugFunctionDeclaration,
855     ExtInstCLDebugInfo100RoundTripTest,
856     ::testing::ValuesIn(std::vector<InstructionCase>({
857         CASE_IIILLIIF(FunctionDeclaration, 1, 2, "FlagIsOptimized",
858                       uint32_t(OpenCLDebugInfo100FlagIsOptimized)),
859         CASE_IIILLIIF(FunctionDeclaration, 42, 43, "FlagFwdDecl",
860                       uint32_t(OpenCLDebugInfo100FlagFwdDecl)),
861     })));
862 
863 INSTANTIATE_TEST_SUITE_P(
864     OpenCLDebugInfo100DebugFunction, ExtInstCLDebugInfo100RoundTripTest,
865     ::testing::ValuesIn(std::vector<InstructionCase>({
866         CASE_IIILLIIFLI(Function, 1, 2, "FlagIsOptimized",
867                         uint32_t(OpenCLDebugInfo100FlagIsOptimized), 3),
868         CASE_IIILLIIFLI(Function, 42, 43, "FlagFwdDecl",
869                         uint32_t(OpenCLDebugInfo100FlagFwdDecl), 44),
870         // Add the optional declaration Id.
871         CASE_IIILLIIFLII(Function, 1, 2, "FlagIsOptimized",
872                          uint32_t(OpenCLDebugInfo100FlagIsOptimized), 3),
873         CASE_IIILLIIFLII(Function, 42, 43, "FlagFwdDecl",
874                          uint32_t(OpenCLDebugInfo100FlagFwdDecl), 44),
875     })));
876 
877 // OpenCL.DebugInfo.100 4.7 Local Information
878 
879 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugLexicalBlock,
880                          ExtInstCLDebugInfo100RoundTripTest,
881                          ::testing::ValuesIn(std::vector<InstructionCase>({
882                              CASE_ILLII(LexicalBlock, 1, 2),
883                              CASE_ILLII(LexicalBlock, 42, 43),
884                          })));
885 
886 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugLexicalBlockDiscriminator,
887                          ExtInstCLDebugInfo100RoundTripTest,
888                          ::testing::ValuesIn(std::vector<InstructionCase>({
889                              CASE_ILI(LexicalBlockDiscriminator, 1),
890                              CASE_ILI(LexicalBlockDiscriminator, 42),
891                          })));
892 
893 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugScope,
894                          ExtInstCLDebugInfo100RoundTripTest,
895                          ::testing::ValuesIn(std::vector<InstructionCase>({
896                              CASE_I(Scope),
897                              CASE_II(Scope),
898                          })));
899 
900 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugNoScope,
901                          ExtInstCLDebugInfo100RoundTripTest,
902                          ::testing::ValuesIn(std::vector<InstructionCase>({
903                              CASE_0(NoScope),
904                          })));
905 
906 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugInlinedAt,
907                          ExtInstCLDebugInfo100RoundTripTest,
908                          ::testing::ValuesIn(std::vector<InstructionCase>({
909                              CASE_LII(InlinedAt, 1),
910                              CASE_LII(InlinedAt, 42),
911                          })));
912 
913 // OpenCL.DebugInfo.100 4.8 Local Variables
914 
915 INSTANTIATE_TEST_SUITE_P(
916     OpenCLDebugInfo100DebugLocalVariable, ExtInstCLDebugInfo100RoundTripTest,
917     ::testing::ValuesIn(std::vector<InstructionCase>({
918         CASE_IIILLIF(LocalVariable, 1, 2, "FlagIsPrivate",
919                      OpenCLDebugInfo100FlagIsPrivate),
920         CASE_IIILLIF(LocalVariable, 4, 5, "FlagIsProtected",
921                      OpenCLDebugInfo100FlagIsProtected),
922         CASE_IIILLIFL(LocalVariable, 9, 99, "FlagIsProtected",
923                       OpenCLDebugInfo100FlagIsProtected, 195),
924         CASE_IIILLIFL(LocalVariable, 19, 199, "FlagIsPrivate",
925                       OpenCLDebugInfo100FlagIsPrivate, 195),
926     })));
927 
928 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugInlinedVariable,
929                          ExtInstCLDebugInfo100RoundTripTest,
930                          ::testing::ValuesIn(std::vector<InstructionCase>({
931                              CASE_II(InlinedVariable),
932                          })));
933 
934 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugDebugDeclare,
935                          ExtInstCLDebugInfo100RoundTripTest,
936                          ::testing::ValuesIn(std::vector<InstructionCase>({
937                              CASE_III(Declare),
938                          })));
939 
940 INSTANTIATE_TEST_SUITE_P(
941     OpenCLDebugInfo100DebugDebugValue, ExtInstCLDebugInfo100RoundTripTest,
942     ::testing::ValuesIn(std::vector<InstructionCase>({
943         CASE_IIII(Value),
944         CASE_IIIII(Value),
945         CASE_IIIIII(Value),
946         // Test up to 3 id parameters. We can always try more.
947         CASE_IIIIIII(Value),
948     })));
949 
950 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugDebugOperation,
951                          ExtInstCLDebugInfo100RoundTripTest,
952                          ::testing::ValuesIn(std::vector<InstructionCase>({
953                              CASE_E(Operation, Deref),
954                              CASE_E(Operation, Plus),
955                              CASE_E(Operation, Minus),
956                              CASE_EL(Operation, PlusUconst, 1),
957                              CASE_EL(Operation, PlusUconst, 42),
958                              CASE_ELL(Operation, BitPiece, 1, 2),
959                              CASE_ELL(Operation, BitPiece, 4, 5),
960                              CASE_E(Operation, Swap),
961                              CASE_E(Operation, Xderef),
962                              CASE_E(Operation, StackValue),
963                              CASE_EL(Operation, Constu, 1),
964                              CASE_EL(Operation, Constu, 42),
965                              CASE_ELL(Operation, Fragment, 100, 200),
966                              CASE_ELL(Operation, Fragment, 8, 9),
967                          })));
968 
969 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugDebugExpression,
970                          ExtInstCLDebugInfo100RoundTripTest,
971                          ::testing::ValuesIn(std::vector<InstructionCase>({
972                              CASE_0(Expression),
973                              CASE_I(Expression),
974                              CASE_II(Expression),
975                              CASE_III(Expression),
976                              CASE_IIII(Expression),
977                              CASE_IIIII(Expression),
978                              CASE_IIIIII(Expression),
979                              CASE_IIIIIII(Expression),
980                          })));
981 
982 // OpenCL.DebugInfo.100 4.9 Macros
983 
984 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugMacroDef,
985                          ExtInstCLDebugInfo100RoundTripTest,
986                          ::testing::ValuesIn(std::vector<InstructionCase>({
987                              CASE_ILI(MacroDef, 1),
988                              CASE_ILI(MacroDef, 42),
989                              CASE_ILII(MacroDef, 1),
990                              CASE_ILII(MacroDef, 42),
991                          })));
992 
993 INSTANTIATE_TEST_SUITE_P(OpenCLDebugInfo100DebugMacroUndef,
994                          ExtInstCLDebugInfo100RoundTripTest,
995                          ::testing::ValuesIn(std::vector<InstructionCase>({
996                              CASE_ILI(MacroUndef, 1),
997                              CASE_ILI(MacroUndef, 42),
998                          })));
999 
1000 // OpenCL.DebugInfo.100 4.10 Imported Entities
1001 
1002 INSTANTIATE_TEST_SUITE_P(
1003     OpenCLDebugInfo100DebugImportedEntity, ExtInstCLDebugInfo100RoundTripTest,
1004     ::testing::ValuesIn(std::vector<InstructionCase>({
1005         // ID Name
1006         // Literal Tag
1007         // ID Source
1008         // ID Entity
1009         // Literal Number Line
1010         // Literal Number Column
1011         // ID Parent
1012         CASE_IEIILLI(ImportedEntity, ImportedModule, 67, 68),
1013         CASE_IEIILLI(ImportedEntity, ImportedDeclaration, 42, 43),
1014     })));
1015 
1016 #undef EPREFIX
1017 #undef CASE_0
1018 #undef CASE_ILL
1019 #undef CASE_IL
1020 #undef CASE_I
1021 #undef CASE_II
1022 #undef CASE_III
1023 #undef CASE_IIII
1024 #undef CASE_IIIII
1025 #undef CASE_IIIIII
1026 #undef CASE_IIIIIII
1027 #undef CASE_IIILLI
1028 #undef CASE_IIILLIL
1029 #undef CASE_IE
1030 #undef CASE_IEIILLI
1031 #undef CASE_IIE
1032 #undef CASE_ISF
1033 #undef CASE_LII
1034 #undef CASE_LLIe
1035 #undef CASE_ILI
1036 #undef CASE_ILII
1037 #undef CASE_ILLII
1038 #undef CASE_IIILLIF
1039 #undef CASE_IIILLIFL
1040 #undef CASE_IIILLIIF
1041 #undef CASE_IIILLIIFII
1042 #undef CASE_IIILLIIFIIII
1043 #undef CASE_IIILLIIFIIIIII
1044 #undef CASE_IEILLIIIF
1045 #undef CASE_IEILLIIIFI
1046 #undef CASE_IEILLIIIFII
1047 #undef CASE_IEILLIIIFIII
1048 #undef CASE_IEILLIIIFIIII
1049 #undef CASE_IIILLIIIF
1050 #undef CASE_IIILLIIIFI
1051 #undef CASE_IIIIF
1052 #undef CASE_IIILL
1053 #undef CASE_IIIILL
1054 #undef CASE_IILLI
1055 #undef CASE_IILLII
1056 #undef CASE_IILLIII
1057 #undef CASE_IILLIIII
1058 #undef CASE_IIILLIIFLI
1059 #undef CASE_IIILLIIFLII
1060 #undef CASE_E
1061 #undef CASE_EI
1062 #undef CASE_EII
1063 #undef CASE_EIII
1064 #undef CASE_EIIII
1065 #undef CASE_EIIIII
1066 #undef CASE_EL
1067 #undef CASE_ELL
1068 
1069 }  // namespace
1070 }  // namespace spvtools
1071