ext_inst.debuginfo_test.cpp 37 KB

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