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 "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(
  48. CompiledInstructions(input),
  49. Eq(Concatenate(
  50. {MakeInstruction(SpvOpExtInstImport, {1}, MakeVector("DebugInfo")),
  51. MakeInstruction(SpvOpExtInst, {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(SpvStorageClass##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(
  358. {MakeInstruction(SpvOpExtInstImport, {1}, MakeVector("DebugInfo")),
  359. MakeInstruction(SpvOpExtInst, {2, 3, 1, DebugInfoDebugTypePointer, 4,
  360. uint32_t(SpvStorageClassPrivate),
  361. DebugInfoFlagIsPublic})})))
  362. << input;
  363. // Now check the round trip through the disassembler.
  364. EXPECT_THAT(EncodeAndDecodeSuccessfully(input), Eq(expected)) << input;
  365. }
  366. INSTANTIATE_TEST_SUITE_P(
  367. DebugInfoDebugTypePointer, ExtInstDebugInfoRoundTripTest,
  368. ::testing::ValuesIn(std::vector<InstructionCase>({
  369. //// Use each flag independently.
  370. CASE_ISF(TypePointer, Private, "FlagIsProtected",
  371. uint32_t(DebugInfoFlagIsProtected)),
  372. CASE_ISF(TypePointer, Private, "FlagIsPrivate",
  373. uint32_t(DebugInfoFlagIsPrivate)),
  374. // FlagIsPublic is tested above.
  375. CASE_ISF(TypePointer, Private, "FlagIsLocal",
  376. uint32_t(DebugInfoFlagIsLocal)),
  377. CASE_ISF(TypePointer, Private, "FlagIsDefinition",
  378. uint32_t(DebugInfoFlagIsDefinition)),
  379. CASE_ISF(TypePointer, Private, "FlagFwdDecl",
  380. uint32_t(DebugInfoFlagFwdDecl)),
  381. CASE_ISF(TypePointer, Private, "FlagArtificial",
  382. uint32_t(DebugInfoFlagArtificial)),
  383. CASE_ISF(TypePointer, Private, "FlagExplicit",
  384. uint32_t(DebugInfoFlagExplicit)),
  385. CASE_ISF(TypePointer, Private, "FlagPrototyped",
  386. uint32_t(DebugInfoFlagPrototyped)),
  387. CASE_ISF(TypePointer, Private, "FlagObjectPointer",
  388. uint32_t(DebugInfoFlagObjectPointer)),
  389. CASE_ISF(TypePointer, Private, "FlagStaticMember",
  390. uint32_t(DebugInfoFlagStaticMember)),
  391. CASE_ISF(TypePointer, Private, "FlagIndirectVariable",
  392. uint32_t(DebugInfoFlagIndirectVariable)),
  393. CASE_ISF(TypePointer, Private, "FlagLValueReference",
  394. uint32_t(DebugInfoFlagLValueReference)),
  395. CASE_ISF(TypePointer, Private, "FlagIsOptimized",
  396. uint32_t(DebugInfoFlagIsOptimized)),
  397. //// Use flags in combination, and try different storage classes.
  398. CASE_ISF(TypePointer, Function, "FlagIsProtected|FlagIsPrivate",
  399. uint32_t(DebugInfoFlagIsProtected) |
  400. uint32_t(DebugInfoFlagIsPrivate)),
  401. CASE_ISF(
  402. TypePointer, Workgroup,
  403. "FlagIsPrivate|FlagFwdDecl|FlagIndirectVariable|FlagIsOptimized",
  404. uint32_t(DebugInfoFlagIsPrivate) | uint32_t(DebugInfoFlagFwdDecl) |
  405. uint32_t(DebugInfoFlagIndirectVariable) |
  406. uint32_t(DebugInfoFlagIsOptimized)),
  407. })));
  408. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeQualifier,
  409. ExtInstDebugInfoRoundTripTest,
  410. ::testing::ValuesIn(std::vector<InstructionCase>({
  411. CASE_IE(TypeQualifier, ConstType),
  412. CASE_IE(TypeQualifier, VolatileType),
  413. CASE_IE(TypeQualifier, RestrictType),
  414. })));
  415. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeArray, ExtInstDebugInfoRoundTripTest,
  416. ::testing::ValuesIn(std::vector<InstructionCase>({
  417. CASE_II(TypeArray),
  418. CASE_III(TypeArray),
  419. CASE_IIII(TypeArray),
  420. CASE_IIIII(TypeArray),
  421. })));
  422. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeVector,
  423. ExtInstDebugInfoRoundTripTest,
  424. ::testing::ValuesIn(std::vector<InstructionCase>({
  425. CASE_IL(TypeVector, 2),
  426. CASE_IL(TypeVector, 3),
  427. CASE_IL(TypeVector, 4),
  428. CASE_IL(TypeVector, 16),
  429. })));
  430. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypedef, ExtInstDebugInfoRoundTripTest,
  431. ::testing::ValuesIn(std::vector<InstructionCase>({
  432. CASE_IIILLI(Typedef, 12, 13),
  433. CASE_IIILLI(Typedef, 14, 99),
  434. })));
  435. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeFunction,
  436. ExtInstDebugInfoRoundTripTest,
  437. ::testing::ValuesIn(std::vector<InstructionCase>({
  438. CASE_I(TypeFunction),
  439. CASE_II(TypeFunction),
  440. CASE_III(TypeFunction),
  441. CASE_IIII(TypeFunction),
  442. CASE_IIIII(TypeFunction),
  443. })));
  444. INSTANTIATE_TEST_SUITE_P(
  445. DebugInfoDebugTypeEnum, ExtInstDebugInfoRoundTripTest,
  446. ::testing::ValuesIn(std::vector<InstructionCase>({
  447. CASE_IIILLIIFII(
  448. TypeEnum, 12, 13,
  449. "FlagIsPrivate|FlagFwdDecl|FlagIndirectVariable|FlagIsOptimized",
  450. uint32_t(DebugInfoFlagIsPrivate) | uint32_t(DebugInfoFlagFwdDecl) |
  451. uint32_t(DebugInfoFlagIndirectVariable) |
  452. uint32_t(DebugInfoFlagIsOptimized)),
  453. CASE_IIILLIIFIIII(TypeEnum, 17, 18, "FlagStaticMember",
  454. uint32_t(DebugInfoFlagStaticMember)),
  455. CASE_IIILLIIFIIIIII(TypeEnum, 99, 1, "FlagStaticMember",
  456. uint32_t(DebugInfoFlagStaticMember)),
  457. })));
  458. INSTANTIATE_TEST_SUITE_P(
  459. DebugInfoDebugTypeComposite, ExtInstDebugInfoRoundTripTest,
  460. ::testing::ValuesIn(std::vector<InstructionCase>({
  461. CASE_IEILLIIF(
  462. TypeComposite, Class, 12, 13,
  463. "FlagIsPrivate|FlagFwdDecl|FlagIndirectVariable|FlagIsOptimized",
  464. uint32_t(DebugInfoFlagIsPrivate) | uint32_t(DebugInfoFlagFwdDecl) |
  465. uint32_t(DebugInfoFlagIndirectVariable) |
  466. uint32_t(DebugInfoFlagIsOptimized)),
  467. // Cover all tag values: Class, Structure, Union
  468. CASE_IEILLIIF(TypeComposite, Class, 12, 13, "FlagIsPrivate",
  469. uint32_t(DebugInfoFlagIsPrivate)),
  470. CASE_IEILLIIF(TypeComposite, Structure, 12, 13, "FlagIsPrivate",
  471. uint32_t(DebugInfoFlagIsPrivate)),
  472. CASE_IEILLIIF(TypeComposite, Union, 12, 13, "FlagIsPrivate",
  473. uint32_t(DebugInfoFlagIsPrivate)),
  474. // Now add members
  475. CASE_IEILLIIFI(TypeComposite, Class, 9, 10, "FlagIsPrivate",
  476. uint32_t(DebugInfoFlagIsPrivate)),
  477. CASE_IEILLIIFII(TypeComposite, Class, 9, 10, "FlagIsPrivate",
  478. uint32_t(DebugInfoFlagIsPrivate)),
  479. CASE_IEILLIIFIII(TypeComposite, Class, 9, 10, "FlagIsPrivate",
  480. uint32_t(DebugInfoFlagIsPrivate)),
  481. CASE_IEILLIIFIIII(TypeComposite, Class, 9, 10, "FlagIsPrivate",
  482. uint32_t(DebugInfoFlagIsPrivate)),
  483. })));
  484. INSTANTIATE_TEST_SUITE_P(
  485. DebugInfoDebugTypeMember, ExtInstDebugInfoRoundTripTest,
  486. ::testing::ValuesIn(std::vector<InstructionCase>({
  487. CASE_IIILLIIIF(TypeMember, 12, 13, "FlagIsPrivate",
  488. uint32_t(DebugInfoFlagIsPrivate)),
  489. CASE_IIILLIIIF(TypeMember, 99, 100, "FlagIsPrivate|FlagFwdDecl",
  490. uint32_t(DebugInfoFlagIsPrivate) |
  491. uint32_t(DebugInfoFlagFwdDecl)),
  492. // Add the optional Id argument.
  493. CASE_IIILLIIIFI(TypeMember, 12, 13, "FlagIsPrivate",
  494. uint32_t(DebugInfoFlagIsPrivate)),
  495. })));
  496. INSTANTIATE_TEST_SUITE_P(
  497. DebugInfoDebugTypeInheritance, ExtInstDebugInfoRoundTripTest,
  498. ::testing::ValuesIn(std::vector<InstructionCase>({
  499. CASE_IIIIF(TypeInheritance, "FlagIsPrivate",
  500. uint32_t(DebugInfoFlagIsPrivate)),
  501. CASE_IIIIF(TypeInheritance, "FlagIsPrivate|FlagFwdDecl",
  502. uint32_t(DebugInfoFlagIsPrivate) |
  503. uint32_t(DebugInfoFlagFwdDecl)),
  504. })));
  505. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypePtrToMember,
  506. ExtInstDebugInfoRoundTripTest,
  507. ::testing::ValuesIn(std::vector<InstructionCase>({
  508. CASE_II(TypePtrToMember),
  509. })));
  510. // DebugInfo 4.4 Templates
  511. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeTemplate,
  512. ExtInstDebugInfoRoundTripTest,
  513. ::testing::ValuesIn(std::vector<InstructionCase>({
  514. CASE_II(TypeTemplate),
  515. CASE_III(TypeTemplate),
  516. CASE_IIII(TypeTemplate),
  517. CASE_IIIII(TypeTemplate),
  518. })));
  519. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeTemplateParameter,
  520. ExtInstDebugInfoRoundTripTest,
  521. ::testing::ValuesIn(std::vector<InstructionCase>({
  522. CASE_IIIILL(TypeTemplateParameter, 1, 2),
  523. CASE_IIIILL(TypeTemplateParameter, 99, 102),
  524. CASE_IIIILL(TypeTemplateParameter, 10, 7),
  525. })));
  526. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeTemplateTemplateParameter,
  527. ExtInstDebugInfoRoundTripTest,
  528. ::testing::ValuesIn(std::vector<InstructionCase>({
  529. CASE_IIILL(TypeTemplateTemplateParameter, 1, 2),
  530. CASE_IIILL(TypeTemplateTemplateParameter, 99, 102),
  531. CASE_IIILL(TypeTemplateTemplateParameter, 10, 7),
  532. })));
  533. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugTypeTemplateParameterPack,
  534. ExtInstDebugInfoRoundTripTest,
  535. ::testing::ValuesIn(std::vector<InstructionCase>({
  536. CASE_IILLI(TypeTemplateParameterPack, 1, 2),
  537. CASE_IILLII(TypeTemplateParameterPack, 99, 102),
  538. CASE_IILLIII(TypeTemplateParameterPack, 10, 7),
  539. CASE_IILLIIII(TypeTemplateParameterPack, 10, 7),
  540. })));
  541. // DebugInfo 4.5 Global Variables
  542. INSTANTIATE_TEST_SUITE_P(
  543. DebugInfoDebugGlobalVariable, ExtInstDebugInfoRoundTripTest,
  544. ::testing::ValuesIn(std::vector<InstructionCase>({
  545. CASE_IIILLIIIF(GlobalVariable, 1, 2, "FlagIsOptimized",
  546. uint32_t(DebugInfoFlagIsOptimized)),
  547. CASE_IIILLIIIF(GlobalVariable, 42, 43, "FlagIsOptimized",
  548. uint32_t(DebugInfoFlagIsOptimized)),
  549. CASE_IIILLIIIFI(GlobalVariable, 1, 2, "FlagIsOptimized",
  550. uint32_t(DebugInfoFlagIsOptimized)),
  551. CASE_IIILLIIIFI(GlobalVariable, 42, 43, "FlagIsOptimized",
  552. uint32_t(DebugInfoFlagIsOptimized)),
  553. })));
  554. // DebugInfo 4.6 Functions
  555. INSTANTIATE_TEST_SUITE_P(
  556. DebugInfoDebugFunctionDeclaration, ExtInstDebugInfoRoundTripTest,
  557. ::testing::ValuesIn(std::vector<InstructionCase>({
  558. CASE_IIILLIIF(FunctionDeclaration, 1, 2, "FlagIsOptimized",
  559. uint32_t(DebugInfoFlagIsOptimized)),
  560. CASE_IIILLIIF(FunctionDeclaration, 42, 43, "FlagFwdDecl",
  561. uint32_t(DebugInfoFlagFwdDecl)),
  562. })));
  563. INSTANTIATE_TEST_SUITE_P(
  564. DebugInfoDebugFunction, ExtInstDebugInfoRoundTripTest,
  565. ::testing::ValuesIn(std::vector<InstructionCase>({
  566. CASE_IIILLIIFLI(Function, 1, 2, "FlagIsOptimized",
  567. uint32_t(DebugInfoFlagIsOptimized), 3),
  568. CASE_IIILLIIFLI(Function, 42, 43, "FlagFwdDecl",
  569. uint32_t(DebugInfoFlagFwdDecl), 44),
  570. // Add the optional declaration Id.
  571. CASE_IIILLIIFLII(Function, 1, 2, "FlagIsOptimized",
  572. uint32_t(DebugInfoFlagIsOptimized), 3),
  573. CASE_IIILLIIFLII(Function, 42, 43, "FlagFwdDecl",
  574. uint32_t(DebugInfoFlagFwdDecl), 44),
  575. })));
  576. // DebugInfo 4.7 Local Information
  577. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugLexicalBlock,
  578. ExtInstDebugInfoRoundTripTest,
  579. ::testing::ValuesIn(std::vector<InstructionCase>({
  580. CASE_ILLII(LexicalBlock, 1, 2),
  581. CASE_ILLII(LexicalBlock, 42, 43),
  582. })));
  583. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugLexicalBlockDiscriminator,
  584. ExtInstDebugInfoRoundTripTest,
  585. ::testing::ValuesIn(std::vector<InstructionCase>({
  586. CASE_ILI(LexicalBlockDiscriminator, 1),
  587. CASE_ILI(LexicalBlockDiscriminator, 42),
  588. })));
  589. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugScope, ExtInstDebugInfoRoundTripTest,
  590. ::testing::ValuesIn(std::vector<InstructionCase>({
  591. CASE_I(Scope),
  592. CASE_II(Scope),
  593. })));
  594. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugNoScope, ExtInstDebugInfoRoundTripTest,
  595. ::testing::ValuesIn(std::vector<InstructionCase>({
  596. CASE_0(NoScope),
  597. })));
  598. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugInlinedAt, ExtInstDebugInfoRoundTripTest,
  599. ::testing::ValuesIn(std::vector<InstructionCase>({
  600. CASE_LII(InlinedAt, 1),
  601. CASE_LII(InlinedAt, 42),
  602. })));
  603. // DebugInfo 4.8 Local Variables
  604. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugLocalVariable,
  605. ExtInstDebugInfoRoundTripTest,
  606. ::testing::ValuesIn(std::vector<InstructionCase>({
  607. CASE_IIILLI(LocalVariable, 1, 2),
  608. CASE_IIILLI(LocalVariable, 42, 43),
  609. CASE_IIILLIL(LocalVariable, 1, 2, 3),
  610. CASE_IIILLIL(LocalVariable, 42, 43, 44),
  611. })));
  612. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugInlinedVariable,
  613. ExtInstDebugInfoRoundTripTest,
  614. ::testing::ValuesIn(std::vector<InstructionCase>({
  615. CASE_II(InlinedVariable),
  616. })));
  617. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugDebugDeclare,
  618. ExtInstDebugInfoRoundTripTest,
  619. ::testing::ValuesIn(std::vector<InstructionCase>({
  620. CASE_III(Declare),
  621. })));
  622. INSTANTIATE_TEST_SUITE_P(
  623. DebugInfoDebugDebugValue, ExtInstDebugInfoRoundTripTest,
  624. ::testing::ValuesIn(std::vector<InstructionCase>({
  625. CASE_III(Value),
  626. CASE_IIII(Value),
  627. CASE_IIIII(Value),
  628. CASE_IIIIII(Value),
  629. // Test up to 4 id parameters. We can always try more.
  630. CASE_IIIIIII(Value),
  631. })));
  632. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugDebugOperation,
  633. ExtInstDebugInfoRoundTripTest,
  634. ::testing::ValuesIn(std::vector<InstructionCase>({
  635. CASE_E(Operation, Deref),
  636. CASE_E(Operation, Plus),
  637. CASE_E(Operation, Minus),
  638. CASE_EL(Operation, PlusUconst, 1),
  639. CASE_EL(Operation, PlusUconst, 42),
  640. CASE_ELL(Operation, BitPiece, 1, 2),
  641. CASE_ELL(Operation, BitPiece, 4, 5),
  642. CASE_E(Operation, Swap),
  643. CASE_E(Operation, Xderef),
  644. CASE_E(Operation, StackValue),
  645. CASE_EL(Operation, Constu, 1),
  646. CASE_EL(Operation, Constu, 42),
  647. })));
  648. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugDebugExpression,
  649. ExtInstDebugInfoRoundTripTest,
  650. ::testing::ValuesIn(std::vector<InstructionCase>({
  651. CASE_0(Expression),
  652. CASE_I(Expression),
  653. CASE_II(Expression),
  654. CASE_III(Expression),
  655. CASE_IIII(Expression),
  656. CASE_IIIII(Expression),
  657. CASE_IIIIII(Expression),
  658. CASE_IIIIIII(Expression),
  659. })));
  660. // DebugInfo 4.9 Macros
  661. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugMacroDef, ExtInstDebugInfoRoundTripTest,
  662. ::testing::ValuesIn(std::vector<InstructionCase>({
  663. CASE_ILI(MacroDef, 1),
  664. CASE_ILI(MacroDef, 42),
  665. CASE_ILII(MacroDef, 1),
  666. CASE_ILII(MacroDef, 42),
  667. })));
  668. INSTANTIATE_TEST_SUITE_P(DebugInfoDebugMacroUndef,
  669. ExtInstDebugInfoRoundTripTest,
  670. ::testing::ValuesIn(std::vector<InstructionCase>({
  671. CASE_ILI(MacroUndef, 1),
  672. CASE_ILI(MacroUndef, 42),
  673. })));
  674. #undef CASE_0
  675. #undef CASE_ILL
  676. #undef CASE_IL
  677. #undef CASE_I
  678. #undef CASE_II
  679. #undef CASE_III
  680. #undef CASE_IIII
  681. #undef CASE_IIIII
  682. #undef CASE_IIIIII
  683. #undef CASE_IIIIIII
  684. #undef CASE_IIILLI
  685. #undef CASE_IIILLIL
  686. #undef CASE_IE
  687. #undef CASE_IIE
  688. #undef CASE_ISF
  689. #undef CASE_LII
  690. #undef CASE_ILI
  691. #undef CASE_ILII
  692. #undef CASE_ILLII
  693. #undef CASE_IIILLIIF
  694. #undef CASE_IIILLIIFII
  695. #undef CASE_IIILLIIFIIII
  696. #undef CASE_IIILLIIFIIIIII
  697. #undef CASE_IEILLIIF
  698. #undef CASE_IEILLIIFI
  699. #undef CASE_IEILLIIFII
  700. #undef CASE_IEILLIIFIII
  701. #undef CASE_IEILLIIFIIII
  702. #undef CASE_IIILLIIIF
  703. #undef CASE_IIILLIIIFI
  704. #undef CASE_IIIIF
  705. #undef CASE_IIILL
  706. #undef CASE_IIIILL
  707. #undef CASE_IILLI
  708. #undef CASE_IILLII
  709. #undef CASE_IILLIII
  710. #undef CASE_IILLIIII
  711. #undef CASE_IIILLIIFLI
  712. #undef CASE_IIILLIIFLII
  713. #undef CASE_E
  714. #undef CASE_EL
  715. #undef CASE_ELL
  716. } // namespace
  717. } // namespace spvtools