ext_inst.debuginfo_test.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. // Copyright (c) 2017 Google Inc.
  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. #include <string>
  15. #include <vector>
  16. #include "DebugInfo.h"
  17. #include "gmock/gmock.h"
  18. #include "test/test_fixture.h"
  19. #include "test/unit_spirv.h"
  20. // This file tests the correctness of encoding and decoding of instructions
  21. // involving the DebugInfo extended instruction set.
  22. // Semantic correctness should be the responsibility of validator.
  23. //
  24. // See https://www.khronos.org/registry/spir-v/specs/1.0/DebugInfo.html
  25. namespace spvtools {
  26. namespace {
  27. using spvtest::Concatenate;
  28. using spvtest::MakeInstruction;
  29. using spvtest::MakeVector;
  30. using testing::Eq;
  31. struct InstructionCase {
  32. uint32_t opcode;
  33. std::string name;
  34. std::string operands;
  35. std::vector<uint32_t> expected_operands;
  36. };
  37. using ExtInstDebugInfoRoundTripTest =
  38. spvtest::TextToBinaryTestBase<::testing::TestWithParam<InstructionCase>>;
  39. using ExtInstDebugInfoRoundTripTestExplicit = spvtest::TextToBinaryTest;
  40. TEST_P(ExtInstDebugInfoRoundTripTest, ParameterizedExtInst) {
  41. const std::string input =
  42. "%1 = OpExtInstImport \"DebugInfo\"\n"
  43. "%3 = OpExtInst %2 %1 " +
  44. GetParam().name + GetParam().operands + "\n";
  45. // First make sure it assembles correctly.
  46. EXPECT_THAT(
  47. CompiledInstructions(input),
  48. Eq(Concatenate(
  49. {MakeInstruction(SpvOpExtInstImport, {1}, MakeVector("DebugInfo")),
  50. MakeInstruction(SpvOpExtInst, {2, 3, 1, GetParam().opcode},
  51. GetParam().expected_operands)})))
  52. << input;
  53. // Now check the round trip through the disassembler.
  54. EXPECT_THAT(EncodeAndDecodeSuccessfully(input), input) << input;
  55. }
  56. #define CASE_0(Enum) \
  57. { \
  58. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, "", {} \
  59. }
  60. #define CASE_ILL(Enum, L0, L1) \
  61. { \
  62. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 " #L0 " " #L1, { \
  63. 4, L0, L1 \
  64. } \
  65. }
  66. #define CASE_IL(Enum, L0) \
  67. { \
  68. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 " #L0, { 4, L0 } \
  69. }
  70. #define CASE_I(Enum) \
  71. { \
  72. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4", { 4 } \
  73. }
  74. #define CASE_II(Enum) \
  75. { \
  76. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 %5", { 4, 5 } \
  77. }
  78. #define CASE_III(Enum) \
  79. { \
  80. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 %5 %6", { 4, 5, 6 } \
  81. }
  82. #define CASE_IIII(Enum) \
  83. { \
  84. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 %5 %6 %7", { \
  85. 4, 5, 6, 7 \
  86. } \
  87. }
  88. #define CASE_IIIII(Enum) \
  89. { \
  90. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 %5 %6 %7 %8", { \
  91. 4, 5, 6, 7, 8 \
  92. } \
  93. }
  94. #define CASE_IIIIII(Enum) \
  95. { \
  96. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 %5 %6 %7 %8 %9", { \
  97. 4, 5, 6, 7, 8, 9 \
  98. } \
  99. }
  100. #define CASE_IIIIIII(Enum) \
  101. { \
  102. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 %5 %6 %7 %8 %9 %10", { \
  103. 4, 5, 6, 7, 8, 9, 10 \
  104. } \
  105. }
  106. #define CASE_IIILLI(Enum, L0, L1) \
  107. { \
  108. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  109. " %4 %5 %6 " #L0 " " #L1 " %7", { \
  110. 4, 5, 6, L0, L1, 7 \
  111. } \
  112. }
  113. #define CASE_IIILLIL(Enum, L0, L1, L2) \
  114. { \
  115. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  116. " %4 %5 %6 " #L0 " " #L1 " %7 " #L2, { \
  117. 4, 5, 6, L0, L1, 7, L2 \
  118. } \
  119. }
  120. #define CASE_IE(Enum, E0) \
  121. { \
  122. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 " #E0, { \
  123. 4, uint32_t(DebugInfo##E0) \
  124. } \
  125. }
  126. #define CASE_IIE(Enum, E0) \
  127. { \
  128. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 %5 " #E0, { \
  129. 4, 5, uint32_t(DebugInfo##E0) \
  130. } \
  131. }
  132. #define CASE_ISF(Enum, S0, Fstr, Fnum) \
  133. { \
  134. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 " #S0 " " Fstr, { \
  135. 4, uint32_t(SpvStorageClass##S0), Fnum \
  136. } \
  137. }
  138. #define CASE_LII(Enum, L0) \
  139. { \
  140. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " " #L0 " %4 %5", { \
  141. L0, 4, 5 \
  142. } \
  143. }
  144. #define CASE_ILI(Enum, L0) \
  145. { \
  146. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 " #L0 " %5", { \
  147. 4, L0, 5 \
  148. } \
  149. }
  150. #define CASE_ILII(Enum, L0) \
  151. { \
  152. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 " #L0 " %5 %6", { \
  153. 4, L0, 5, 6 \
  154. } \
  155. }
  156. #define CASE_ILLII(Enum, L0, L1) \
  157. { \
  158. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  159. " %4 " #L0 " " #L1 " %5 %6", { \
  160. 4, L0, L1, 5, 6 \
  161. } \
  162. }
  163. #define CASE_IIILLIIF(Enum, L0, L1, Fstr, Fnum) \
  164. { \
  165. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  166. " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr, { \
  167. 4, 5, 6, L0, L1, 7, 8, Fnum \
  168. } \
  169. }
  170. #define CASE_IIILLIIFII(Enum, L0, L1, Fstr, Fnum) \
  171. { \
  172. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  173. " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr " %9 %10", { \
  174. 4, 5, 6, L0, L1, 7, 8, Fnum, 9, 10 \
  175. } \
  176. }
  177. #define CASE_IIILLIIFIIII(Enum, L0, L1, Fstr, Fnum) \
  178. { \
  179. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  180. " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr " %9 %10 %11 %12", { \
  181. 4, 5, 6, L0, L1, 7, 8, Fnum, 9, 10, 11, 12 \
  182. } \
  183. }
  184. #define CASE_IIILLIIFIIIIII(Enum, L0, L1, Fstr, Fnum) \
  185. { \
  186. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  187. " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr " %9 %10 %11 %12 %13 %14", { \
  188. 4, 5, 6, L0, L1, 7, 8, Fnum, 9, 10, 11, 12, 13, 14 \
  189. } \
  190. }
  191. #define CASE_IEILLIIF(Enum, E0, L0, L1, Fstr, Fnum) \
  192. { \
  193. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  194. " %4 " #E0 " %5 " #L0 " " #L1 " %6 %7 " Fstr, { \
  195. 4, uint32_t(DebugInfo##E0), 5, L0, L1, 6, 7, Fnum \
  196. } \
  197. }
  198. #define CASE_IEILLIIFI(Enum, E0, L0, L1, Fstr, Fnum) \
  199. { \
  200. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  201. " %4 " #E0 " %5 " #L0 " " #L1 " %6 %7 " Fstr " %8", { \
  202. 4, uint32_t(DebugInfo##E0), 5, L0, L1, 6, 7, Fnum, 8 \
  203. } \
  204. }
  205. #define CASE_IEILLIIFII(Enum, E0, L0, L1, Fstr, Fnum) \
  206. { \
  207. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  208. " %4 " #E0 " %5 " #L0 " " #L1 " %6 %7 " Fstr " %8 %9", { \
  209. 4, uint32_t(DebugInfo##E0), 5, L0, L1, 6, 7, Fnum, 8, 9 \
  210. } \
  211. }
  212. #define CASE_IEILLIIFIII(Enum, E0, L0, L1, Fstr, Fnum) \
  213. { \
  214. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  215. " %4 " #E0 " %5 " #L0 " " #L1 " %6 %7 " Fstr " %8 %9 %10", { \
  216. 4, uint32_t(DebugInfo##E0), 5, L0, L1, 6, 7, Fnum, 8, 9, 10 \
  217. } \
  218. }
  219. #define CASE_IEILLIIFIIII(Enum, E0, L0, L1, Fstr, Fnum) \
  220. { \
  221. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  222. " %4 " #E0 " %5 " #L0 " " #L1 " %6 %7 " Fstr " %8 %9 %10 %11", { \
  223. 4, uint32_t(DebugInfo##E0), 5, L0, L1, 6, 7, Fnum, 8, 9, 10, 11 \
  224. } \
  225. }
  226. #define CASE_IIILLIIIF(Enum, L0, L1, Fstr, Fnum) \
  227. { \
  228. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  229. " %4 %5 %6 " #L0 " " #L1 " %7 %8 %9 " Fstr, { \
  230. 4, 5, 6, L0, L1, 7, 8, 9, Fnum \
  231. } \
  232. }
  233. #define CASE_IIILLIIIFI(Enum, L0, L1, Fstr, Fnum) \
  234. { \
  235. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  236. " %4 %5 %6 " #L0 " " #L1 " %7 %8 %9 " Fstr " %10", { \
  237. 4, 5, 6, L0, L1, 7, 8, 9, Fnum, 10 \
  238. } \
  239. }
  240. #define CASE_IIIIF(Enum, Fstr, Fnum) \
  241. { \
  242. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 %5 %6 %7 " Fstr, { \
  243. 4, 5, 6, 7, Fnum \
  244. } \
  245. }
  246. #define CASE_IIILL(Enum, L0, L1) \
  247. { \
  248. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " %4 %5 %6 " #L0 " " #L1, { \
  249. 4, 5, 6, L0, L1 \
  250. } \
  251. }
  252. #define CASE_IIIILL(Enum, L0, L1) \
  253. { \
  254. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  255. " %4 %5 %6 %7 " #L0 " " #L1, { \
  256. 4, 5, 6, 7, L0, L1 \
  257. } \
  258. }
  259. #define CASE_IILLI(Enum, L0, L1) \
  260. { \
  261. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  262. " %4 %5 " #L0 " " #L1 " %6", { \
  263. 4, 5, L0, L1, 6 \
  264. } \
  265. }
  266. #define CASE_IILLII(Enum, L0, L1) \
  267. { \
  268. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  269. " %4 %5 " #L0 " " #L1 " %6 %7", { \
  270. 4, 5, L0, L1, 6, 7 \
  271. } \
  272. }
  273. #define CASE_IILLIII(Enum, L0, L1) \
  274. { \
  275. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  276. " %4 %5 " #L0 " " #L1 " %6 %7 %8", { \
  277. 4, 5, L0, L1, 6, 7, 8 \
  278. } \
  279. }
  280. #define CASE_IILLIIII(Enum, L0, L1) \
  281. { \
  282. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  283. " %4 %5 " #L0 " " #L1 " %6 %7 %8 %9", { \
  284. 4, 5, L0, L1, 6, 7, 8, 9 \
  285. } \
  286. }
  287. #define CASE_IIILLIIFLI(Enum, L0, L1, Fstr, Fnum, L2) \
  288. { \
  289. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  290. " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr " " #L2 " %9", { \
  291. 4, 5, 6, L0, L1, 7, 8, Fnum, L2, 9 \
  292. } \
  293. }
  294. #define CASE_IIILLIIFLII(Enum, L0, L1, Fstr, Fnum, L2) \
  295. { \
  296. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, \
  297. " %4 %5 %6 " #L0 " " #L1 " %7 %8 " Fstr " " #L2 " %9 %10", { \
  298. 4, 5, 6, L0, L1, 7, 8, Fnum, L2, 9, 10 \
  299. } \
  300. }
  301. #define CASE_E(Enum, E0) \
  302. { \
  303. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " " #E0, { \
  304. uint32_t(DebugInfo##E0) \
  305. } \
  306. }
  307. #define CASE_EL(Enum, E0, L0) \
  308. { \
  309. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " " #E0 " " #L0, { \
  310. uint32_t(DebugInfo##E0), L0 \
  311. } \
  312. }
  313. #define CASE_ELL(Enum, E0, L0, L1) \
  314. { \
  315. uint32_t(DebugInfoDebug##Enum), "Debug" #Enum, " " #E0 " " #L0 " " #L1, { \
  316. uint32_t(DebugInfo##E0), L0, L1 \
  317. } \
  318. }
  319. // DebugInfo 4.1 Absent Debugging Information
  320. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugInfoNone, ExtInstDebugInfoRoundTripTest,
  321. ::testing::ValuesIn(std::vector<InstructionCase>({
  322. CASE_0(InfoNone), // enum value 0
  323. })));
  324. // DebugInfo 4.2 Compilation Unit
  325. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugCompilationUnit,
  326. ExtInstDebugInfoRoundTripTest,
  327. ::testing::ValuesIn(std::vector<InstructionCase>({
  328. CASE_ILL(CompilationUnit, 100, 42),
  329. })));
  330. // DebugInfo 4.3 Type instructions
  331. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeBasic, ExtInstDebugInfoRoundTripTest,
  332. ::testing::ValuesIn(std::vector<InstructionCase>({
  333. CASE_IIE(TypeBasic, Unspecified),
  334. CASE_IIE(TypeBasic, Address),
  335. CASE_IIE(TypeBasic, Boolean),
  336. CASE_IIE(TypeBasic, Float),
  337. CASE_IIE(TypeBasic, Signed),
  338. CASE_IIE(TypeBasic, SignedChar),
  339. CASE_IIE(TypeBasic, Unsigned),
  340. CASE_IIE(TypeBasic, UnsignedChar),
  341. })));
  342. // The FlagIsPublic is value is (1 << 0) | (1 << 2) which is the same
  343. // as the bitwise-OR of FlagIsProtected and FlagIsPrivate.
  344. // The disassembler will emit the compound expression instead.
  345. // There is no simple fix for this. This enum is not really a mask
  346. // for the bottom two bits.
  347. TEST_F(ExtInstDebugInfoRoundTripTestExplicit, FlagIsPublic) {
  348. const std::string prefix =
  349. "%1 = OpExtInstImport \"DebugInfo\"\n"
  350. "%3 = OpExtInst %2 %1 DebugTypePointer %4 Private ";
  351. const std::string input = prefix + "FlagIsPublic\n";
  352. const std::string expected = prefix + "FlagIsProtected|FlagIsPrivate\n";
  353. // First make sure it assembles correctly.
  354. EXPECT_THAT(
  355. CompiledInstructions(input),
  356. Eq(Concatenate(
  357. {MakeInstruction(SpvOpExtInstImport, {1}, MakeVector("DebugInfo")),
  358. MakeInstruction(SpvOpExtInst, {2, 3, 1, DebugInfoDebugTypePointer, 4,
  359. uint32_t(SpvStorageClassPrivate),
  360. DebugInfoFlagIsPublic})})))
  361. << input;
  362. // Now check the round trip through the disassembler.
  363. EXPECT_THAT(EncodeAndDecodeSuccessfully(input), Eq(expected)) << input;
  364. }
  365. INSTANTIATE_TEST_SUITE_P(
  366. DebugInfoDebugTypePointer, ExtInstDebugInfoRoundTripTest,
  367. ::testing::ValuesIn(std::vector<InstructionCase>({
  368. //// Use each flag independently.
  369. CASE_ISF(TypePointer, Private, "FlagIsProtected",
  370. uint32_t(DebugInfoFlagIsProtected)),
  371. CASE_ISF(TypePointer, Private, "FlagIsPrivate",
  372. uint32_t(DebugInfoFlagIsPrivate)),
  373. // FlagIsPublic is tested above.
  374. CASE_ISF(TypePointer, Private, "FlagIsLocal",
  375. uint32_t(DebugInfoFlagIsLocal)),
  376. CASE_ISF(TypePointer, Private, "FlagIsDefinition",
  377. uint32_t(DebugInfoFlagIsDefinition)),
  378. CASE_ISF(TypePointer, Private, "FlagFwdDecl",
  379. uint32_t(DebugInfoFlagFwdDecl)),
  380. CASE_ISF(TypePointer, Private, "FlagArtificial",
  381. uint32_t(DebugInfoFlagArtificial)),
  382. CASE_ISF(TypePointer, Private, "FlagExplicit",
  383. uint32_t(DebugInfoFlagExplicit)),
  384. CASE_ISF(TypePointer, Private, "FlagPrototyped",
  385. uint32_t(DebugInfoFlagPrototyped)),
  386. CASE_ISF(TypePointer, Private, "FlagObjectPointer",
  387. uint32_t(DebugInfoFlagObjectPointer)),
  388. CASE_ISF(TypePointer, Private, "FlagStaticMember",
  389. uint32_t(DebugInfoFlagStaticMember)),
  390. CASE_ISF(TypePointer, Private, "FlagIndirectVariable",
  391. uint32_t(DebugInfoFlagIndirectVariable)),
  392. CASE_ISF(TypePointer, Private, "FlagLValueReference",
  393. uint32_t(DebugInfoFlagLValueReference)),
  394. CASE_ISF(TypePointer, Private, "FlagIsOptimized",
  395. uint32_t(DebugInfoFlagIsOptimized)),
  396. //// Use flags in combination, and try different storage classes.
  397. CASE_ISF(TypePointer, Function, "FlagIsProtected|FlagIsPrivate",
  398. uint32_t(DebugInfoFlagIsProtected) |
  399. uint32_t(DebugInfoFlagIsPrivate)),
  400. CASE_ISF(
  401. TypePointer, Workgroup,
  402. "FlagIsPrivate|FlagFwdDecl|FlagIndirectVariable|FlagIsOptimized",
  403. uint32_t(DebugInfoFlagIsPrivate) | uint32_t(DebugInfoFlagFwdDecl) |
  404. uint32_t(DebugInfoFlagIndirectVariable) |
  405. uint32_t(DebugInfoFlagIsOptimized)),
  406. })));
  407. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeQualifier,
  408. ExtInstDebugInfoRoundTripTest,
  409. ::testing::ValuesIn(std::vector<InstructionCase>({
  410. CASE_IE(TypeQualifier, ConstType),
  411. CASE_IE(TypeQualifier, VolatileType),
  412. CASE_IE(TypeQualifier, RestrictType),
  413. })));
  414. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeArray, ExtInstDebugInfoRoundTripTest,
  415. ::testing::ValuesIn(std::vector<InstructionCase>({
  416. CASE_II(TypeArray),
  417. CASE_III(TypeArray),
  418. CASE_IIII(TypeArray),
  419. CASE_IIIII(TypeArray),
  420. })));
  421. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeVector,
  422. ExtInstDebugInfoRoundTripTest,
  423. ::testing::ValuesIn(std::vector<InstructionCase>({
  424. CASE_IL(TypeVector, 2),
  425. CASE_IL(TypeVector, 3),
  426. CASE_IL(TypeVector, 4),
  427. CASE_IL(TypeVector, 16),
  428. })));
  429. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypedef, ExtInstDebugInfoRoundTripTest,
  430. ::testing::ValuesIn(std::vector<InstructionCase>({
  431. CASE_IIILLI(Typedef, 12, 13),
  432. CASE_IIILLI(Typedef, 14, 99),
  433. })));
  434. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeFunction,
  435. ExtInstDebugInfoRoundTripTest,
  436. ::testing::ValuesIn(std::vector<InstructionCase>({
  437. CASE_I(TypeFunction),
  438. CASE_II(TypeFunction),
  439. CASE_III(TypeFunction),
  440. CASE_IIII(TypeFunction),
  441. CASE_IIIII(TypeFunction),
  442. })));
  443. INSTANTIATE_TEST_SUITE_P(
  444. DebugInfoDebugTypeEnum, ExtInstDebugInfoRoundTripTest,
  445. ::testing::ValuesIn(std::vector<InstructionCase>({
  446. CASE_IIILLIIFII(
  447. TypeEnum, 12, 13,
  448. "FlagIsPrivate|FlagFwdDecl|FlagIndirectVariable|FlagIsOptimized",
  449. uint32_t(DebugInfoFlagIsPrivate) | uint32_t(DebugInfoFlagFwdDecl) |
  450. uint32_t(DebugInfoFlagIndirectVariable) |
  451. uint32_t(DebugInfoFlagIsOptimized)),
  452. CASE_IIILLIIFIIII(TypeEnum, 17, 18, "FlagStaticMember",
  453. uint32_t(DebugInfoFlagStaticMember)),
  454. CASE_IIILLIIFIIIIII(TypeEnum, 99, 1, "FlagStaticMember",
  455. uint32_t(DebugInfoFlagStaticMember)),
  456. })));
  457. INSTANTIATE_TEST_SUITE_P(
  458. DebugInfoDebugTypeComposite, ExtInstDebugInfoRoundTripTest,
  459. ::testing::ValuesIn(std::vector<InstructionCase>({
  460. CASE_IEILLIIF(
  461. TypeComposite, Class, 12, 13,
  462. "FlagIsPrivate|FlagFwdDecl|FlagIndirectVariable|FlagIsOptimized",
  463. uint32_t(DebugInfoFlagIsPrivate) | uint32_t(DebugInfoFlagFwdDecl) |
  464. uint32_t(DebugInfoFlagIndirectVariable) |
  465. uint32_t(DebugInfoFlagIsOptimized)),
  466. // Cover all tag values: Class, Structure, Union
  467. CASE_IEILLIIF(TypeComposite, Class, 12, 13, "FlagIsPrivate",
  468. uint32_t(DebugInfoFlagIsPrivate)),
  469. CASE_IEILLIIF(TypeComposite, Structure, 12, 13, "FlagIsPrivate",
  470. uint32_t(DebugInfoFlagIsPrivate)),
  471. CASE_IEILLIIF(TypeComposite, Union, 12, 13, "FlagIsPrivate",
  472. uint32_t(DebugInfoFlagIsPrivate)),
  473. // Now add members
  474. CASE_IEILLIIFI(TypeComposite, Class, 9, 10, "FlagIsPrivate",
  475. uint32_t(DebugInfoFlagIsPrivate)),
  476. CASE_IEILLIIFII(TypeComposite, Class, 9, 10, "FlagIsPrivate",
  477. uint32_t(DebugInfoFlagIsPrivate)),
  478. CASE_IEILLIIFIII(TypeComposite, Class, 9, 10, "FlagIsPrivate",
  479. uint32_t(DebugInfoFlagIsPrivate)),
  480. CASE_IEILLIIFIIII(TypeComposite, Class, 9, 10, "FlagIsPrivate",
  481. uint32_t(DebugInfoFlagIsPrivate)),
  482. })));
  483. INSTANTIATE_TEST_SUITE_P(
  484. DebugInfoDebugTypeMember, ExtInstDebugInfoRoundTripTest,
  485. ::testing::ValuesIn(std::vector<InstructionCase>({
  486. CASE_IIILLIIIF(TypeMember, 12, 13, "FlagIsPrivate",
  487. uint32_t(DebugInfoFlagIsPrivate)),
  488. CASE_IIILLIIIF(TypeMember, 99, 100, "FlagIsPrivate|FlagFwdDecl",
  489. uint32_t(DebugInfoFlagIsPrivate) |
  490. uint32_t(DebugInfoFlagFwdDecl)),
  491. // Add the optional Id argument.
  492. CASE_IIILLIIIFI(TypeMember, 12, 13, "FlagIsPrivate",
  493. uint32_t(DebugInfoFlagIsPrivate)),
  494. })));
  495. INSTANTIATE_TEST_SUITE_P(
  496. DebugInfoDebugTypeInheritance, ExtInstDebugInfoRoundTripTest,
  497. ::testing::ValuesIn(std::vector<InstructionCase>({
  498. CASE_IIIIF(TypeInheritance, "FlagIsPrivate",
  499. uint32_t(DebugInfoFlagIsPrivate)),
  500. CASE_IIIIF(TypeInheritance, "FlagIsPrivate|FlagFwdDecl",
  501. uint32_t(DebugInfoFlagIsPrivate) |
  502. uint32_t(DebugInfoFlagFwdDecl)),
  503. })));
  504. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypePtrToMember,
  505. ExtInstDebugInfoRoundTripTest,
  506. ::testing::ValuesIn(std::vector<InstructionCase>({
  507. CASE_II(TypePtrToMember),
  508. })));
  509. // DebugInfo 4.4 Templates
  510. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeTemplate,
  511. ExtInstDebugInfoRoundTripTest,
  512. ::testing::ValuesIn(std::vector<InstructionCase>({
  513. CASE_II(TypeTemplate),
  514. CASE_III(TypeTemplate),
  515. CASE_IIII(TypeTemplate),
  516. CASE_IIIII(TypeTemplate),
  517. })));
  518. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeTemplateParameter,
  519. ExtInstDebugInfoRoundTripTest,
  520. ::testing::ValuesIn(std::vector<InstructionCase>({
  521. CASE_IIIILL(TypeTemplateParameter, 1, 2),
  522. CASE_IIIILL(TypeTemplateParameter, 99, 102),
  523. CASE_IIIILL(TypeTemplateParameter, 10, 7),
  524. })));
  525. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeTemplateTemplateParameter,
  526. ExtInstDebugInfoRoundTripTest,
  527. ::testing::ValuesIn(std::vector<InstructionCase>({
  528. CASE_IIILL(TypeTemplateTemplateParameter, 1, 2),
  529. CASE_IIILL(TypeTemplateTemplateParameter, 99, 102),
  530. CASE_IIILL(TypeTemplateTemplateParameter, 10, 7),
  531. })));
  532. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeTemplateParameterPack,
  533. ExtInstDebugInfoRoundTripTest,
  534. ::testing::ValuesIn(std::vector<InstructionCase>({
  535. CASE_IILLI(TypeTemplateParameterPack, 1, 2),
  536. CASE_IILLII(TypeTemplateParameterPack, 99, 102),
  537. CASE_IILLIII(TypeTemplateParameterPack, 10, 7),
  538. CASE_IILLIIII(TypeTemplateParameterPack, 10, 7),
  539. })));
  540. // DebugInfo 4.5 Global Variables
  541. INSTANTIATE_TEST_SUITE_P(
  542. DebugInfoDebugGlobalVariable, ExtInstDebugInfoRoundTripTest,
  543. ::testing::ValuesIn(std::vector<InstructionCase>({
  544. CASE_IIILLIIIF(GlobalVariable, 1, 2, "FlagIsOptimized",
  545. uint32_t(DebugInfoFlagIsOptimized)),
  546. CASE_IIILLIIIF(GlobalVariable, 42, 43, "FlagIsOptimized",
  547. uint32_t(DebugInfoFlagIsOptimized)),
  548. CASE_IIILLIIIFI(GlobalVariable, 1, 2, "FlagIsOptimized",
  549. uint32_t(DebugInfoFlagIsOptimized)),
  550. CASE_IIILLIIIFI(GlobalVariable, 42, 43, "FlagIsOptimized",
  551. uint32_t(DebugInfoFlagIsOptimized)),
  552. })));
  553. // DebugInfo 4.6 Functions
  554. INSTANTIATE_TEST_SUITE_P(
  555. DebugInfoDebugFunctionDeclaration, ExtInstDebugInfoRoundTripTest,
  556. ::testing::ValuesIn(std::vector<InstructionCase>({
  557. CASE_IIILLIIF(FunctionDeclaration, 1, 2, "FlagIsOptimized",
  558. uint32_t(DebugInfoFlagIsOptimized)),
  559. CASE_IIILLIIF(FunctionDeclaration, 42, 43, "FlagFwdDecl",
  560. uint32_t(DebugInfoFlagFwdDecl)),
  561. })));
  562. INSTANTIATE_TEST_SUITE_P(
  563. DebugInfoDebugFunction, ExtInstDebugInfoRoundTripTest,
  564. ::testing::ValuesIn(std::vector<InstructionCase>({
  565. CASE_IIILLIIFLI(Function, 1, 2, "FlagIsOptimized",
  566. uint32_t(DebugInfoFlagIsOptimized), 3),
  567. CASE_IIILLIIFLI(Function, 42, 43, "FlagFwdDecl",
  568. uint32_t(DebugInfoFlagFwdDecl), 44),
  569. // Add the optional declaration Id.
  570. CASE_IIILLIIFLII(Function, 1, 2, "FlagIsOptimized",
  571. uint32_t(DebugInfoFlagIsOptimized), 3),
  572. CASE_IIILLIIFLII(Function, 42, 43, "FlagFwdDecl",
  573. uint32_t(DebugInfoFlagFwdDecl), 44),
  574. })));
  575. // DebugInfo 4.7 Local Information
  576. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugLexicalBlock,
  577. ExtInstDebugInfoRoundTripTest,
  578. ::testing::ValuesIn(std::vector<InstructionCase>({
  579. CASE_ILLII(LexicalBlock, 1, 2),
  580. CASE_ILLII(LexicalBlock, 42, 43),
  581. })));
  582. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugLexicalBlockDiscriminator,
  583. ExtInstDebugInfoRoundTripTest,
  584. ::testing::ValuesIn(std::vector<InstructionCase>({
  585. CASE_ILI(LexicalBlockDiscriminator, 1),
  586. CASE_ILI(LexicalBlockDiscriminator, 42),
  587. })));
  588. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugScope, ExtInstDebugInfoRoundTripTest,
  589. ::testing::ValuesIn(std::vector<InstructionCase>({
  590. CASE_I(Scope),
  591. CASE_II(Scope),
  592. })));
  593. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugNoScope, ExtInstDebugInfoRoundTripTest,
  594. ::testing::ValuesIn(std::vector<InstructionCase>({
  595. CASE_0(NoScope),
  596. })));
  597. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugInlinedAt, ExtInstDebugInfoRoundTripTest,
  598. ::testing::ValuesIn(std::vector<InstructionCase>({
  599. CASE_LII(InlinedAt, 1),
  600. CASE_LII(InlinedAt, 42),
  601. })));
  602. // DebugInfo 4.8 Local Variables
  603. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugLocalVariable,
  604. ExtInstDebugInfoRoundTripTest,
  605. ::testing::ValuesIn(std::vector<InstructionCase>({
  606. CASE_IIILLI(LocalVariable, 1, 2),
  607. CASE_IIILLI(LocalVariable, 42, 43),
  608. CASE_IIILLIL(LocalVariable, 1, 2, 3),
  609. CASE_IIILLIL(LocalVariable, 42, 43, 44),
  610. })));
  611. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugInlinedVariable,
  612. ExtInstDebugInfoRoundTripTest,
  613. ::testing::ValuesIn(std::vector<InstructionCase>({
  614. CASE_II(InlinedVariable),
  615. })));
  616. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugDebugDeclare,
  617. ExtInstDebugInfoRoundTripTest,
  618. ::testing::ValuesIn(std::vector<InstructionCase>({
  619. CASE_III(Declare),
  620. })));
  621. INSTANTIATE_TEST_SUITE_P(
  622. DebugInfoDebugDebugValue, ExtInstDebugInfoRoundTripTest,
  623. ::testing::ValuesIn(std::vector<InstructionCase>({
  624. CASE_III(Value),
  625. CASE_IIII(Value),
  626. CASE_IIIII(Value),
  627. CASE_IIIIII(Value),
  628. // Test up to 4 id parameters. We can always try more.
  629. CASE_IIIIIII(Value),
  630. })));
  631. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugDebugOperation,
  632. ExtInstDebugInfoRoundTripTest,
  633. ::testing::ValuesIn(std::vector<InstructionCase>({
  634. CASE_E(Operation, Deref),
  635. CASE_E(Operation, Plus),
  636. CASE_E(Operation, Minus),
  637. CASE_EL(Operation, PlusUconst, 1),
  638. CASE_EL(Operation, PlusUconst, 42),
  639. CASE_ELL(Operation, BitPiece, 1, 2),
  640. CASE_ELL(Operation, BitPiece, 4, 5),
  641. CASE_E(Operation, Swap),
  642. CASE_E(Operation, Xderef),
  643. CASE_E(Operation, StackValue),
  644. CASE_EL(Operation, Constu, 1),
  645. CASE_EL(Operation, Constu, 42),
  646. })));
  647. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugDebugExpression,
  648. ExtInstDebugInfoRoundTripTest,
  649. ::testing::ValuesIn(std::vector<InstructionCase>({
  650. CASE_0(Expression),
  651. CASE_I(Expression),
  652. CASE_II(Expression),
  653. CASE_III(Expression),
  654. CASE_IIII(Expression),
  655. CASE_IIIII(Expression),
  656. CASE_IIIIII(Expression),
  657. CASE_IIIIIII(Expression),
  658. })));
  659. // DebugInfo 4.9 Macros
  660. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugMacroDef, ExtInstDebugInfoRoundTripTest,
  661. ::testing::ValuesIn(std::vector<InstructionCase>({
  662. CASE_ILI(MacroDef, 1),
  663. CASE_ILI(MacroDef, 42),
  664. CASE_ILII(MacroDef, 1),
  665. CASE_ILII(MacroDef, 42),
  666. })));
  667. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugMacroUndef,
  668. ExtInstDebugInfoRoundTripTest,
  669. ::testing::ValuesIn(std::vector<InstructionCase>({
  670. CASE_ILI(MacroUndef, 1),
  671. CASE_ILI(MacroUndef, 42),
  672. })));
  673. #undef CASE_0
  674. #undef CASE_ILL
  675. #undef CASE_IL
  676. #undef CASE_I
  677. #undef CASE_II
  678. #undef CASE_III
  679. #undef CASE_IIII
  680. #undef CASE_IIIII
  681. #undef CASE_IIIIII
  682. #undef CASE_IIIIIII
  683. #undef CASE_IIILLI
  684. #undef CASE_IIILLIL
  685. #undef CASE_IE
  686. #undef CASE_IIE
  687. #undef CASE_ISF
  688. #undef CASE_LII
  689. #undef CASE_ILI
  690. #undef CASE_ILII
  691. #undef CASE_ILLII
  692. #undef CASE_IIILLIIF
  693. #undef CASE_IIILLIIFII
  694. #undef CASE_IIILLIIFIIII
  695. #undef CASE_IIILLIIFIIIIII
  696. #undef CASE_IEILLIIF
  697. #undef CASE_IEILLIIFI
  698. #undef CASE_IEILLIIFII
  699. #undef CASE_IEILLIIFIII
  700. #undef CASE_IEILLIIFIIII
  701. #undef CASE_IIILLIIIF
  702. #undef CASE_IIILLIIIFI
  703. #undef CASE_IIIIF
  704. #undef CASE_IIILL
  705. #undef CASE_IIIILL
  706. #undef CASE_IILLI
  707. #undef CASE_IILLII
  708. #undef CASE_IILLIII
  709. #undef CASE_IILLIIII
  710. #undef CASE_IIILLIIFLI
  711. #undef CASE_IIILLIIFLII
  712. #undef CASE_E
  713. #undef CASE_EL
  714. #undef CASE_ELL
  715. } // namespace
  716. } // namespace spvtools