transformation_add_parameter_test.cpp 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. // Copyright (c) 2020 Vasyl Teliman
  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 "source/fuzz/transformation_add_parameter.h"
  15. #include "gtest/gtest.h"
  16. #include "source/fuzz/fuzzer_util.h"
  17. #include "test/fuzz/fuzz_test_util.h"
  18. namespace spvtools {
  19. namespace fuzz {
  20. namespace {
  21. TEST(TransformationAddParameterTest, NonPointerBasicTest) {
  22. std::string shader = R"(
  23. OpCapability Shader
  24. %1 = OpExtInstImport "GLSL.std.450"
  25. OpMemoryModel Logical GLSL450
  26. OpEntryPoint Fragment %4 "main"
  27. OpExecutionMode %4 OriginUpperLeft
  28. OpSource ESSL 310
  29. OpName %4 "main"
  30. %2 = OpTypeVoid
  31. %7 = OpTypeBool
  32. %11 = OpTypeInt 32 1
  33. %16 = OpTypeFloat 32
  34. %51 = OpConstant %11 2
  35. %52 = OpTypeArray %16 %51
  36. %53 = OpConstant %16 7
  37. %54 = OpConstantComposite %52 %53 %53
  38. %3 = OpTypeFunction %2
  39. %6 = OpTypeFunction %7 %7
  40. %8 = OpConstant %11 23
  41. %12 = OpConstantTrue %7
  42. %15 = OpTypeFunction %2 %16
  43. %24 = OpTypeFunction %2 %16 %7
  44. %31 = OpTypeStruct %7 %11
  45. %32 = OpConstant %16 23
  46. %33 = OpConstantComposite %31 %12 %8
  47. %41 = OpTypeStruct %11 %16
  48. %42 = OpConstantComposite %41 %8 %32
  49. %43 = OpTypeFunction %2 %41
  50. %44 = OpTypeFunction %2 %41 %7
  51. %4 = OpFunction %2 None %3
  52. %5 = OpLabel
  53. %13 = OpFunctionCall %7 %9 %12
  54. OpReturn
  55. OpFunctionEnd
  56. ; adjust type of the function in-place
  57. %9 = OpFunction %7 None %6
  58. %14 = OpFunctionParameter %7
  59. %10 = OpLabel
  60. OpReturnValue %12
  61. OpFunctionEnd
  62. ; reuse an existing function type
  63. %17 = OpFunction %2 None %15
  64. %18 = OpFunctionParameter %16
  65. %19 = OpLabel
  66. OpReturn
  67. OpFunctionEnd
  68. %20 = OpFunction %2 None %15
  69. %21 = OpFunctionParameter %16
  70. %22 = OpLabel
  71. OpReturn
  72. OpFunctionEnd
  73. %25 = OpFunction %2 None %24
  74. %26 = OpFunctionParameter %16
  75. %27 = OpFunctionParameter %7
  76. %28 = OpLabel
  77. OpReturn
  78. OpFunctionEnd
  79. ; create a new function type
  80. %29 = OpFunction %2 None %3
  81. %30 = OpLabel
  82. OpReturn
  83. OpFunctionEnd
  84. ; don't adjust the type of the function if it creates a duplicate
  85. %34 = OpFunction %2 None %43
  86. %35 = OpFunctionParameter %41
  87. %36 = OpLabel
  88. OpReturn
  89. OpFunctionEnd
  90. %37 = OpFunction %2 None %44
  91. %38 = OpFunctionParameter %41
  92. %39 = OpFunctionParameter %7
  93. %40 = OpLabel
  94. OpReturn
  95. OpFunctionEnd
  96. )";
  97. const auto env = SPV_ENV_UNIVERSAL_1_3;
  98. const auto consumer = nullptr;
  99. const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
  100. spvtools::ValidatorOptions validator_options;
  101. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  102. kConsoleMessageConsumer));
  103. TransformationContext transformation_context(
  104. MakeUnique<FactManager>(context.get()), validator_options);
  105. // Can't modify entry point function.
  106. ASSERT_FALSE(TransformationAddParameter(4, 60, 7, {{}}, 61)
  107. .IsApplicable(context.get(), transformation_context));
  108. // There is no function with result id 60.
  109. ASSERT_FALSE(TransformationAddParameter(60, 60, 11, {{}}, 61)
  110. .IsApplicable(context.get(), transformation_context));
  111. // Parameter id is not fresh.
  112. ASSERT_FALSE(TransformationAddParameter(9, 14, 11, {{{13, 8}}}, 61)
  113. .IsApplicable(context.get(), transformation_context));
  114. // Function type id is not fresh.
  115. ASSERT_FALSE(TransformationAddParameter(9, 60, 11, {{{13, 8}}}, 14)
  116. .IsApplicable(context.get(), transformation_context));
  117. // Function type id and parameter type id are equal.
  118. ASSERT_FALSE(TransformationAddParameter(9, 60, 11, {{{13, 8}}}, 60)
  119. .IsApplicable(context.get(), transformation_context));
  120. // Parameter's initializer doesn't exist.
  121. ASSERT_FALSE(TransformationAddParameter(9, 60, 11, {{{13, 60}}}, 61)
  122. .IsApplicable(context.get(), transformation_context));
  123. // Correct transformations.
  124. {
  125. TransformationAddParameter correct(9, 60, 11, {{{13, 8}}}, 61);
  126. ASSERT_TRUE(correct.IsApplicable(context.get(), transformation_context));
  127. ApplyAndCheckFreshIds(correct, context.get(), &transformation_context);
  128. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
  129. context.get(), validator_options, kConsoleMessageConsumer));
  130. ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(60));
  131. }
  132. {
  133. TransformationAddParameter correct(9, 68, 52, {{{13, 54}}}, 69);
  134. ASSERT_TRUE(correct.IsApplicable(context.get(), transformation_context));
  135. ApplyAndCheckFreshIds(correct, context.get(), &transformation_context);
  136. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
  137. context.get(), validator_options, kConsoleMessageConsumer));
  138. ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(68));
  139. }
  140. {
  141. TransformationAddParameter correct(17, 62, 7, {{}}, 63);
  142. ASSERT_TRUE(correct.IsApplicable(context.get(), transformation_context));
  143. ApplyAndCheckFreshIds(correct, context.get(), &transformation_context);
  144. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
  145. context.get(), validator_options, kConsoleMessageConsumer));
  146. ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(62));
  147. }
  148. {
  149. TransformationAddParameter correct(29, 64, 31, {{}}, 65);
  150. ASSERT_TRUE(correct.IsApplicable(context.get(), transformation_context));
  151. ApplyAndCheckFreshIds(correct, context.get(), &transformation_context);
  152. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
  153. context.get(), validator_options, kConsoleMessageConsumer));
  154. ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(64));
  155. }
  156. {
  157. TransformationAddParameter correct(34, 66, 7, {{}}, 67);
  158. ASSERT_TRUE(correct.IsApplicable(context.get(), transformation_context));
  159. ApplyAndCheckFreshIds(correct, context.get(), &transformation_context);
  160. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
  161. context.get(), validator_options, kConsoleMessageConsumer));
  162. ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(66));
  163. }
  164. std::string expected_shader = R"(
  165. OpCapability Shader
  166. %1 = OpExtInstImport "GLSL.std.450"
  167. OpMemoryModel Logical GLSL450
  168. OpEntryPoint Fragment %4 "main"
  169. OpExecutionMode %4 OriginUpperLeft
  170. OpSource ESSL 310
  171. OpName %4 "main"
  172. %2 = OpTypeVoid
  173. %7 = OpTypeBool
  174. %11 = OpTypeInt 32 1
  175. %16 = OpTypeFloat 32
  176. %51 = OpConstant %11 2
  177. %52 = OpTypeArray %16 %51
  178. %53 = OpConstant %16 7
  179. %54 = OpConstantComposite %52 %53 %53
  180. %3 = OpTypeFunction %2
  181. %8 = OpConstant %11 23
  182. %12 = OpConstantTrue %7
  183. %15 = OpTypeFunction %2 %16
  184. %24 = OpTypeFunction %2 %16 %7
  185. %31 = OpTypeStruct %7 %11
  186. %32 = OpConstant %16 23
  187. %33 = OpConstantComposite %31 %12 %8
  188. %41 = OpTypeStruct %11 %16
  189. %42 = OpConstantComposite %41 %8 %32
  190. %44 = OpTypeFunction %2 %41 %7
  191. %6 = OpTypeFunction %7 %7 %11 %52
  192. %65 = OpTypeFunction %2 %31
  193. %4 = OpFunction %2 None %3
  194. %5 = OpLabel
  195. %13 = OpFunctionCall %7 %9 %12 %8 %54
  196. OpReturn
  197. OpFunctionEnd
  198. ; adjust type of the function in-place
  199. %9 = OpFunction %7 None %6
  200. %14 = OpFunctionParameter %7
  201. %60 = OpFunctionParameter %11
  202. %68 = OpFunctionParameter %52
  203. %10 = OpLabel
  204. OpReturnValue %12
  205. OpFunctionEnd
  206. ; reuse an existing function type
  207. %17 = OpFunction %2 None %24
  208. %18 = OpFunctionParameter %16
  209. %62 = OpFunctionParameter %7
  210. %19 = OpLabel
  211. OpReturn
  212. OpFunctionEnd
  213. %20 = OpFunction %2 None %15
  214. %21 = OpFunctionParameter %16
  215. %22 = OpLabel
  216. OpReturn
  217. OpFunctionEnd
  218. %25 = OpFunction %2 None %24
  219. %26 = OpFunctionParameter %16
  220. %27 = OpFunctionParameter %7
  221. %28 = OpLabel
  222. OpReturn
  223. OpFunctionEnd
  224. ; create a new function type
  225. %29 = OpFunction %2 None %65
  226. %64 = OpFunctionParameter %31
  227. %30 = OpLabel
  228. OpReturn
  229. OpFunctionEnd
  230. ; don't adjust the type of the function if it creates a duplicate
  231. %34 = OpFunction %2 None %44
  232. %35 = OpFunctionParameter %41
  233. %66 = OpFunctionParameter %7
  234. %36 = OpLabel
  235. OpReturn
  236. OpFunctionEnd
  237. %37 = OpFunction %2 None %44
  238. %38 = OpFunctionParameter %41
  239. %39 = OpFunctionParameter %7
  240. %40 = OpLabel
  241. OpReturn
  242. OpFunctionEnd
  243. )";
  244. ASSERT_TRUE(IsEqual(env, expected_shader, context.get()));
  245. }
  246. TEST(TransformationAddParameterTest, NonPointerNotApplicableTest) {
  247. // This types handles case of adding a new parameter of a non-pointer type
  248. // where the transformation is not applicable.
  249. std::string shader = R"(
  250. OpCapability Shader
  251. %1 = OpExtInstImport "GLSL.std.450"
  252. OpMemoryModel Logical GLSL450
  253. OpEntryPoint Fragment %4 "main"
  254. OpExecutionMode %4 OriginUpperLeft
  255. OpSource ESSL 310
  256. OpName %4 "main"
  257. OpName %6 "fun1("
  258. OpName %12 "fun2(i1;"
  259. OpName %11 "a"
  260. OpName %14 "fun3("
  261. OpName %24 "f1"
  262. OpName %27 "f2"
  263. OpName %30 "i1"
  264. OpName %31 "i2"
  265. OpName %32 "param"
  266. OpName %35 "i3"
  267. OpName %36 "param"
  268. %2 = OpTypeVoid
  269. %3 = OpTypeFunction %2
  270. %8 = OpTypeInt 32 1
  271. %9 = OpTypePointer Function %8
  272. %10 = OpTypeFunction %8 %9
  273. %18 = OpConstant %8 2
  274. %22 = OpTypeFloat 32
  275. %23 = OpTypePointer Private %22
  276. %24 = OpVariable %23 Private
  277. %25 = OpConstant %22 1
  278. %26 = OpTypePointer Function %22
  279. %28 = OpConstant %22 2
  280. %4 = OpFunction %2 None %3
  281. %5 = OpLabel
  282. %27 = OpVariable %26 Function
  283. %30 = OpVariable %9 Function
  284. %31 = OpVariable %9 Function
  285. %32 = OpVariable %9 Function
  286. %35 = OpVariable %9 Function
  287. %36 = OpVariable %9 Function
  288. OpStore %24 %25
  289. OpStore %27 %28
  290. %29 = OpFunctionCall %2 %6
  291. OpStore %30 %18
  292. %33 = OpLoad %8 %30
  293. OpStore %32 %33
  294. %34 = OpFunctionCall %8 %12 %32
  295. OpStore %31 %34
  296. %37 = OpLoad %8 %31
  297. OpStore %36 %37
  298. %38 = OpFunctionCall %8 %12 %36
  299. OpStore %35 %38
  300. ; %39 = OpFunctionCall %2 %14
  301. OpReturn
  302. OpFunctionEnd
  303. %6 = OpFunction %2 None %3
  304. %7 = OpLabel
  305. OpReturn
  306. OpFunctionEnd
  307. %12 = OpFunction %8 None %10
  308. %11 = OpFunctionParameter %9
  309. %13 = OpLabel
  310. %17 = OpLoad %8 %11
  311. %19 = OpIAdd %8 %17 %18
  312. OpReturnValue %19
  313. OpFunctionEnd
  314. %14 = OpFunction %2 None %3
  315. %15 = OpLabel
  316. OpReturn
  317. OpFunctionEnd
  318. )";
  319. const auto env = SPV_ENV_UNIVERSAL_1_3;
  320. const auto consumer = nullptr;
  321. const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
  322. spvtools::ValidatorOptions validator_options;
  323. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  324. kConsoleMessageConsumer));
  325. TransformationContext transformation_context(
  326. MakeUnique<FactManager>(context.get()), validator_options);
  327. // Bad: Id 19 is not available in the caller that has id 34.
  328. TransformationAddParameter transformation_bad_1(12, 50, 8,
  329. {{{34, 19}, {38, 19}}}, 51);
  330. ASSERT_FALSE(
  331. transformation_bad_1.IsApplicable(context.get(), transformation_context));
  332. // Bad: Id 8 does not have a type.
  333. TransformationAddParameter transformation_bad_2(12, 50, 8,
  334. {{{34, 8}, {38, 8}}}, 51);
  335. ASSERT_FALSE(
  336. transformation_bad_2.IsApplicable(context.get(), transformation_context));
  337. // Bad: Types of id 25 and id 18 are different.
  338. TransformationAddParameter transformation_bad_3(12, 50, 22,
  339. {{{34, 25}, {38, 18}}}, 51);
  340. ASSERT_FALSE(
  341. transformation_bad_3.IsApplicable(context.get(), transformation_context));
  342. // Function with id 14 does not have any callers.
  343. // Bad: Id 18 is not a valid type.
  344. TransformationAddParameter transformation_bad_4(14, 50, 18, {{}}, 51);
  345. ASSERT_FALSE(
  346. transformation_bad_4.IsApplicable(context.get(), transformation_context));
  347. // Function with id 14 does not have any callers.
  348. // Bad: Id 3 refers to OpTypeVoid, which is not supported.
  349. TransformationAddParameter transformation_bad_6(14, 50, 3, {{}}, 51);
  350. ASSERT_FALSE(
  351. transformation_bad_6.IsApplicable(context.get(), transformation_context));
  352. }
  353. TEST(TransformationAddParameterTest, PointerFunctionTest) {
  354. // This types handles case of adding a new parameter of a pointer type with
  355. // storage class Function.
  356. std::string shader = R"(
  357. OpCapability Shader
  358. %1 = OpExtInstImport "GLSL.std.450"
  359. OpMemoryModel Logical GLSL450
  360. OpEntryPoint Fragment %4 "main"
  361. OpExecutionMode %4 OriginUpperLeft
  362. OpSource ESSL 310
  363. OpName %4 "main"
  364. OpName %6 "fun1("
  365. OpName %12 "fun2(i1;"
  366. OpName %11 "a"
  367. OpName %14 "fun3("
  368. OpName %17 "s"
  369. OpName %24 "s"
  370. OpName %28 "f1"
  371. OpName %31 "f2"
  372. OpName %34 "i1"
  373. OpName %35 "i2"
  374. OpName %36 "param"
  375. OpName %39 "i3"
  376. OpName %40 "param"
  377. %2 = OpTypeVoid
  378. %3 = OpTypeFunction %2
  379. %8 = OpTypeInt 32 1
  380. %9 = OpTypePointer Function %8
  381. %10 = OpTypeFunction %8 %9
  382. %20 = OpConstant %8 2
  383. %25 = OpConstant %8 0
  384. %26 = OpTypeFloat 32
  385. %27 = OpTypePointer Private %26
  386. %28 = OpVariable %27 Private
  387. %60 = OpTypePointer Output %26
  388. %61 = OpVariable %60 Output
  389. %29 = OpConstant %26 1
  390. %30 = OpTypePointer Function %26
  391. %32 = OpConstant %26 2
  392. %4 = OpFunction %2 None %3
  393. %5 = OpLabel
  394. %31 = OpVariable %30 Function
  395. %34 = OpVariable %9 Function
  396. %35 = OpVariable %9 Function
  397. %36 = OpVariable %9 Function
  398. %39 = OpVariable %9 Function
  399. %40 = OpVariable %9 Function
  400. OpStore %28 %29
  401. OpStore %31 %32
  402. %33 = OpFunctionCall %2 %6
  403. OpStore %34 %20
  404. %37 = OpLoad %8 %34
  405. OpStore %36 %37
  406. %38 = OpFunctionCall %8 %12 %36
  407. OpStore %35 %38
  408. %41 = OpLoad %8 %35
  409. OpStore %40 %41
  410. %42 = OpFunctionCall %8 %12 %40
  411. OpStore %39 %42
  412. %43 = OpFunctionCall %2 %14
  413. OpReturn
  414. OpFunctionEnd
  415. %6 = OpFunction %2 None %3
  416. %7 = OpLabel
  417. OpReturn
  418. OpFunctionEnd
  419. %12 = OpFunction %8 None %10
  420. %11 = OpFunctionParameter %9
  421. %13 = OpLabel
  422. %17 = OpVariable %9 Function
  423. %18 = OpLoad %8 %11
  424. OpStore %17 %18
  425. %19 = OpLoad %8 %17
  426. %21 = OpIAdd %8 %19 %20
  427. OpReturnValue %21
  428. OpFunctionEnd
  429. %14 = OpFunction %2 None %3
  430. %15 = OpLabel
  431. %24 = OpVariable %9 Function
  432. OpStore %24 %25
  433. OpReturn
  434. OpFunctionEnd
  435. )";
  436. const auto env = SPV_ENV_UNIVERSAL_1_3;
  437. const auto consumer = nullptr;
  438. const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
  439. spvtools::ValidatorOptions validator_options;
  440. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  441. kConsoleMessageConsumer));
  442. TransformationContext transformation_context(
  443. MakeUnique<FactManager>(context.get()), validator_options);
  444. // Bad: Pointer of id 61 has storage class Output, which is not supported.
  445. TransformationAddParameter transformation_bad_1(12, 50, 60,
  446. {{{38, 61}, {42, 61}}}, 51);
  447. ASSERT_FALSE(
  448. transformation_bad_1.IsApplicable(context.get(), transformation_context));
  449. // Good: Local variable of id 31 is defined in the caller (main).
  450. TransformationAddParameter transformation_good_1(12, 50, 30,
  451. {{{38, 31}, {42, 31}}}, 51);
  452. ASSERT_TRUE(transformation_good_1.IsApplicable(context.get(),
  453. transformation_context));
  454. ApplyAndCheckFreshIds(transformation_good_1, context.get(),
  455. &transformation_context);
  456. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  457. kConsoleMessageConsumer));
  458. // Good: Local variable of id 34 is defined in the caller (main).
  459. TransformationAddParameter transformation_good_2(14, 52, 9, {{{43, 34}}}, 53);
  460. ASSERT_TRUE(transformation_good_2.IsApplicable(context.get(),
  461. transformation_context));
  462. ApplyAndCheckFreshIds(transformation_good_2, context.get(),
  463. &transformation_context);
  464. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  465. kConsoleMessageConsumer));
  466. // Good: Local variable of id 39 is defined in the caller (main).
  467. TransformationAddParameter transformation_good_3(6, 54, 9, {{{33, 39}}}, 55);
  468. ASSERT_TRUE(transformation_good_3.IsApplicable(context.get(),
  469. transformation_context));
  470. ApplyAndCheckFreshIds(transformation_good_3, context.get(),
  471. &transformation_context);
  472. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  473. kConsoleMessageConsumer));
  474. // Good: This adds another pointer parameter to the function of id 6.
  475. TransformationAddParameter transformation_good_4(6, 56, 30, {{{33, 31}}}, 57);
  476. ASSERT_TRUE(transformation_good_4.IsApplicable(context.get(),
  477. transformation_context));
  478. ApplyAndCheckFreshIds(transformation_good_4, context.get(),
  479. &transformation_context);
  480. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  481. kConsoleMessageConsumer));
  482. std::string expected_shader = R"(
  483. OpCapability Shader
  484. %1 = OpExtInstImport "GLSL.std.450"
  485. OpMemoryModel Logical GLSL450
  486. OpEntryPoint Fragment %4 "main"
  487. OpExecutionMode %4 OriginUpperLeft
  488. OpSource ESSL 310
  489. OpName %4 "main"
  490. OpName %6 "fun1("
  491. OpName %12 "fun2(i1;"
  492. OpName %11 "a"
  493. OpName %14 "fun3("
  494. OpName %17 "s"
  495. OpName %24 "s"
  496. OpName %28 "f1"
  497. OpName %31 "f2"
  498. OpName %34 "i1"
  499. OpName %35 "i2"
  500. OpName %36 "param"
  501. OpName %39 "i3"
  502. OpName %40 "param"
  503. %2 = OpTypeVoid
  504. %3 = OpTypeFunction %2
  505. %8 = OpTypeInt 32 1
  506. %9 = OpTypePointer Function %8
  507. %20 = OpConstant %8 2
  508. %25 = OpConstant %8 0
  509. %26 = OpTypeFloat 32
  510. %27 = OpTypePointer Private %26
  511. %28 = OpVariable %27 Private
  512. %60 = OpTypePointer Output %26
  513. %61 = OpVariable %60 Output
  514. %29 = OpConstant %26 1
  515. %30 = OpTypePointer Function %26
  516. %32 = OpConstant %26 2
  517. %10 = OpTypeFunction %8 %9 %30
  518. %53 = OpTypeFunction %2 %9
  519. %57 = OpTypeFunction %2 %9 %30
  520. %4 = OpFunction %2 None %3
  521. %5 = OpLabel
  522. %31 = OpVariable %30 Function
  523. %34 = OpVariable %9 Function
  524. %35 = OpVariable %9 Function
  525. %36 = OpVariable %9 Function
  526. %39 = OpVariable %9 Function
  527. %40 = OpVariable %9 Function
  528. OpStore %28 %29
  529. OpStore %31 %32
  530. %33 = OpFunctionCall %2 %6 %39 %31
  531. OpStore %34 %20
  532. %37 = OpLoad %8 %34
  533. OpStore %36 %37
  534. %38 = OpFunctionCall %8 %12 %36 %31
  535. OpStore %35 %38
  536. %41 = OpLoad %8 %35
  537. OpStore %40 %41
  538. %42 = OpFunctionCall %8 %12 %40 %31
  539. OpStore %39 %42
  540. %43 = OpFunctionCall %2 %14 %34
  541. OpReturn
  542. OpFunctionEnd
  543. %6 = OpFunction %2 None %57
  544. %54 = OpFunctionParameter %9
  545. %56 = OpFunctionParameter %30
  546. %7 = OpLabel
  547. OpReturn
  548. OpFunctionEnd
  549. %12 = OpFunction %8 None %10
  550. %11 = OpFunctionParameter %9
  551. %50 = OpFunctionParameter %30
  552. %13 = OpLabel
  553. %17 = OpVariable %9 Function
  554. %18 = OpLoad %8 %11
  555. OpStore %17 %18
  556. %19 = OpLoad %8 %17
  557. %21 = OpIAdd %8 %19 %20
  558. OpReturnValue %21
  559. OpFunctionEnd
  560. %14 = OpFunction %2 None %53
  561. %52 = OpFunctionParameter %9
  562. %15 = OpLabel
  563. %24 = OpVariable %9 Function
  564. OpStore %24 %25
  565. OpReturn
  566. OpFunctionEnd
  567. )";
  568. ASSERT_TRUE(IsEqual(env, expected_shader, context.get()));
  569. }
  570. TEST(TransformationAddParameterTest, PointerPrivateWorkgroupTest) {
  571. // This types handles case of adding a new parameter of a pointer type with
  572. // storage class Private or Workgroup.
  573. std::string shader = R"(
  574. OpCapability Shader
  575. %1 = OpExtInstImport "GLSL.std.450"
  576. OpMemoryModel Logical GLSL450
  577. OpEntryPoint Fragment %4 "main"
  578. OpExecutionMode %4 OriginUpperLeft
  579. OpSource ESSL 310
  580. OpName %4 "main"
  581. OpName %6 "fun1("
  582. OpName %12 "fun2(i1;"
  583. OpName %11 "a"
  584. OpName %14 "fun3("
  585. OpName %17 "s"
  586. OpName %24 "s"
  587. OpName %28 "f1"
  588. OpName %31 "f2"
  589. OpName %34 "i1"
  590. OpName %35 "i2"
  591. OpName %36 "param"
  592. OpName %39 "i3"
  593. OpName %40 "param"
  594. %2 = OpTypeVoid
  595. %3 = OpTypeFunction %2
  596. %8 = OpTypeInt 32 1
  597. %9 = OpTypePointer Function %8
  598. %10 = OpTypeFunction %8 %9
  599. %20 = OpConstant %8 2
  600. %25 = OpConstant %8 0
  601. %26 = OpTypeFloat 32
  602. %27 = OpTypePointer Private %26
  603. %28 = OpVariable %27 Private
  604. %60 = OpTypePointer Workgroup %26
  605. %61 = OpVariable %60 Workgroup
  606. %29 = OpConstant %26 1
  607. %30 = OpTypePointer Function %26
  608. %32 = OpConstant %26 2
  609. %4 = OpFunction %2 None %3
  610. %5 = OpLabel
  611. %31 = OpVariable %30 Function
  612. %34 = OpVariable %9 Function
  613. %35 = OpVariable %9 Function
  614. %36 = OpVariable %9 Function
  615. %39 = OpVariable %9 Function
  616. %40 = OpVariable %9 Function
  617. OpStore %28 %29
  618. OpStore %31 %32
  619. %33 = OpFunctionCall %2 %6
  620. OpStore %34 %20
  621. %37 = OpLoad %8 %34
  622. OpStore %36 %37
  623. %38 = OpFunctionCall %8 %12 %36
  624. OpStore %35 %38
  625. %41 = OpLoad %8 %35
  626. OpStore %40 %41
  627. %42 = OpFunctionCall %8 %12 %40
  628. OpStore %39 %42
  629. %43 = OpFunctionCall %2 %14
  630. OpReturn
  631. OpFunctionEnd
  632. %6 = OpFunction %2 None %3
  633. %7 = OpLabel
  634. OpReturn
  635. OpFunctionEnd
  636. %12 = OpFunction %8 None %10
  637. %11 = OpFunctionParameter %9
  638. %13 = OpLabel
  639. %17 = OpVariable %9 Function
  640. %18 = OpLoad %8 %11
  641. OpStore %17 %18
  642. %19 = OpLoad %8 %17
  643. %21 = OpIAdd %8 %19 %20
  644. OpReturnValue %21
  645. OpFunctionEnd
  646. %14 = OpFunction %2 None %3
  647. %15 = OpLabel
  648. %24 = OpVariable %9 Function
  649. OpStore %24 %25
  650. OpReturn
  651. OpFunctionEnd
  652. )";
  653. const auto env = SPV_ENV_UNIVERSAL_1_3;
  654. const auto consumer = nullptr;
  655. const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
  656. spvtools::ValidatorOptions validator_options;
  657. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  658. kConsoleMessageConsumer));
  659. TransformationContext transformation_context(
  660. MakeUnique<FactManager>(context.get()), validator_options);
  661. // Good: Global variable of id 28 (storage class Private) is defined in the
  662. // caller (main).
  663. TransformationAddParameter transformation_good_1(12, 70, 27,
  664. {{{38, 28}, {42, 28}}}, 71);
  665. ASSERT_TRUE(transformation_good_1.IsApplicable(context.get(),
  666. transformation_context));
  667. ApplyAndCheckFreshIds(transformation_good_1, context.get(),
  668. &transformation_context);
  669. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  670. kConsoleMessageConsumer));
  671. // Good: Global variable of id 61 is (storage class Workgroup) is defined in
  672. // the caller (main).
  673. TransformationAddParameter transformation_good_2(12, 72, 27,
  674. {{{38, 28}, {42, 28}}}, 73);
  675. ASSERT_TRUE(transformation_good_2.IsApplicable(context.get(),
  676. transformation_context));
  677. ApplyAndCheckFreshIds(transformation_good_2, context.get(),
  678. &transformation_context);
  679. // Good: Global variable of id 28 (storage class Private) is defined in the
  680. // caller (main).
  681. TransformationAddParameter transformation_good_3(6, 74, 27, {{{33, 28}}}, 75);
  682. ASSERT_TRUE(transformation_good_3.IsApplicable(context.get(),
  683. transformation_context));
  684. ApplyAndCheckFreshIds(transformation_good_3, context.get(),
  685. &transformation_context);
  686. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  687. kConsoleMessageConsumer));
  688. // Good: Global variable of id 61 is (storage class Workgroup) is defined in
  689. // the caller (main).
  690. TransformationAddParameter transformation_good_4(6, 76, 60, {{{33, 61}}}, 77);
  691. ASSERT_TRUE(transformation_good_4.IsApplicable(context.get(),
  692. transformation_context));
  693. ApplyAndCheckFreshIds(transformation_good_4, context.get(),
  694. &transformation_context);
  695. // Good: Global variable of id 28 (storage class Private) is defined in the
  696. // caller (main).
  697. TransformationAddParameter transformation_good_5(14, 78, 27, {{{43, 28}}},
  698. 79);
  699. ASSERT_TRUE(transformation_good_5.IsApplicable(context.get(),
  700. transformation_context));
  701. ApplyAndCheckFreshIds(transformation_good_5, context.get(),
  702. &transformation_context);
  703. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  704. kConsoleMessageConsumer));
  705. // Good: Global variable of id 61 is (storage class Workgroup) is defined in
  706. // the caller (main).
  707. TransformationAddParameter transformation_good_6(14, 80, 60, {{{43, 61}}},
  708. 81);
  709. ASSERT_TRUE(transformation_good_6.IsApplicable(context.get(),
  710. transformation_context));
  711. ApplyAndCheckFreshIds(transformation_good_6, context.get(),
  712. &transformation_context);
  713. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  714. kConsoleMessageConsumer));
  715. std::string expected_shader = R"(
  716. OpCapability Shader
  717. %1 = OpExtInstImport "GLSL.std.450"
  718. OpMemoryModel Logical GLSL450
  719. OpEntryPoint Fragment %4 "main"
  720. OpExecutionMode %4 OriginUpperLeft
  721. OpSource ESSL 310
  722. OpName %4 "main"
  723. OpName %6 "fun1("
  724. OpName %12 "fun2(i1;"
  725. OpName %11 "a"
  726. OpName %14 "fun3("
  727. OpName %17 "s"
  728. OpName %24 "s"
  729. OpName %28 "f1"
  730. OpName %31 "f2"
  731. OpName %34 "i1"
  732. OpName %35 "i2"
  733. OpName %36 "param"
  734. OpName %39 "i3"
  735. OpName %40 "param"
  736. %2 = OpTypeVoid
  737. %3 = OpTypeFunction %2
  738. %8 = OpTypeInt 32 1
  739. %9 = OpTypePointer Function %8
  740. %20 = OpConstant %8 2
  741. %25 = OpConstant %8 0
  742. %26 = OpTypeFloat 32
  743. %27 = OpTypePointer Private %26
  744. %28 = OpVariable %27 Private
  745. %60 = OpTypePointer Workgroup %26
  746. %61 = OpVariable %60 Workgroup
  747. %29 = OpConstant %26 1
  748. %30 = OpTypePointer Function %26
  749. %32 = OpConstant %26 2
  750. %10 = OpTypeFunction %8 %9 %27 %27
  751. %75 = OpTypeFunction %2 %27 %60
  752. %4 = OpFunction %2 None %3
  753. %5 = OpLabel
  754. %31 = OpVariable %30 Function
  755. %34 = OpVariable %9 Function
  756. %35 = OpVariable %9 Function
  757. %36 = OpVariable %9 Function
  758. %39 = OpVariable %9 Function
  759. %40 = OpVariable %9 Function
  760. OpStore %28 %29
  761. OpStore %31 %32
  762. %33 = OpFunctionCall %2 %6 %28 %61
  763. OpStore %34 %20
  764. %37 = OpLoad %8 %34
  765. OpStore %36 %37
  766. %38 = OpFunctionCall %8 %12 %36 %28 %28
  767. OpStore %35 %38
  768. %41 = OpLoad %8 %35
  769. OpStore %40 %41
  770. %42 = OpFunctionCall %8 %12 %40 %28 %28
  771. OpStore %39 %42
  772. %43 = OpFunctionCall %2 %14 %28 %61
  773. OpReturn
  774. OpFunctionEnd
  775. %6 = OpFunction %2 None %75
  776. %74 = OpFunctionParameter %27
  777. %76 = OpFunctionParameter %60
  778. %7 = OpLabel
  779. OpReturn
  780. OpFunctionEnd
  781. %12 = OpFunction %8 None %10
  782. %11 = OpFunctionParameter %9
  783. %70 = OpFunctionParameter %27
  784. %72 = OpFunctionParameter %27
  785. %13 = OpLabel
  786. %17 = OpVariable %9 Function
  787. %18 = OpLoad %8 %11
  788. OpStore %17 %18
  789. %19 = OpLoad %8 %17
  790. %21 = OpIAdd %8 %19 %20
  791. OpReturnValue %21
  792. OpFunctionEnd
  793. %14 = OpFunction %2 None %75
  794. %78 = OpFunctionParameter %27
  795. %80 = OpFunctionParameter %60
  796. %15 = OpLabel
  797. %24 = OpVariable %9 Function
  798. OpStore %24 %25
  799. OpReturn
  800. OpFunctionEnd
  801. )";
  802. ASSERT_TRUE(IsEqual(env, expected_shader, context.get()));
  803. }
  804. TEST(TransformationAddParameterTest, PointerMoreEntriesInMapTest) {
  805. // This types handles case where call_parameter_id has an entry for at least
  806. // every caller (there are more entries than it is necessary).
  807. std::string shader = R"(
  808. OpCapability Shader
  809. %1 = OpExtInstImport "GLSL.std.450"
  810. OpMemoryModel Logical GLSL450
  811. OpEntryPoint Fragment %4 "main"
  812. OpExecutionMode %4 OriginUpperLeft
  813. OpSource ESSL 310
  814. OpName %4 "main"
  815. OpName %10 "fun(i1;"
  816. OpName %9 "a"
  817. OpName %12 "s"
  818. OpName %19 "i1"
  819. OpName %21 "i2"
  820. OpName %22 "i3"
  821. OpName %24 "i4"
  822. OpName %25 "param"
  823. OpName %28 "i5"
  824. OpName %29 "param"
  825. %2 = OpTypeVoid
  826. %3 = OpTypeFunction %2
  827. %6 = OpTypeInt 32 1
  828. %7 = OpTypePointer Function %6
  829. %8 = OpTypeFunction %6 %7
  830. %15 = OpConstant %6 2
  831. %20 = OpConstant %6 1
  832. %23 = OpConstant %6 3
  833. %4 = OpFunction %2 None %3
  834. %5 = OpLabel
  835. %19 = OpVariable %7 Function
  836. %21 = OpVariable %7 Function
  837. %22 = OpVariable %7 Function
  838. %24 = OpVariable %7 Function
  839. %25 = OpVariable %7 Function
  840. %28 = OpVariable %7 Function
  841. %29 = OpVariable %7 Function
  842. OpStore %19 %20
  843. OpStore %21 %15
  844. OpStore %22 %23
  845. %26 = OpLoad %6 %19
  846. OpStore %25 %26
  847. %27 = OpFunctionCall %6 %10 %25
  848. OpStore %24 %27
  849. %30 = OpLoad %6 %21
  850. OpStore %29 %30
  851. %31 = OpFunctionCall %6 %10 %29
  852. OpStore %28 %31
  853. OpReturn
  854. OpFunctionEnd
  855. %10 = OpFunction %6 None %8
  856. %9 = OpFunctionParameter %7
  857. %11 = OpLabel
  858. %12 = OpVariable %7 Function
  859. %13 = OpLoad %6 %9
  860. OpStore %12 %13
  861. %14 = OpLoad %6 %12
  862. %16 = OpIAdd %6 %14 %15
  863. OpReturnValue %16
  864. OpFunctionEnd
  865. )";
  866. const auto env = SPV_ENV_UNIVERSAL_1_3;
  867. const auto consumer = nullptr;
  868. const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
  869. spvtools::ValidatorOptions validator_options;
  870. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  871. kConsoleMessageConsumer));
  872. TransformationContext transformation_context(
  873. MakeUnique<FactManager>(context.get()), validator_options);
  874. // Good: Local variable of id 21 is defined in every caller (id 27 and id 31).
  875. TransformationAddParameter transformation_good_1(
  876. 10, 70, 7, {{{27, 21}, {31, 21}, {30, 21}}}, 71);
  877. ASSERT_TRUE(transformation_good_1.IsApplicable(context.get(),
  878. transformation_context));
  879. ApplyAndCheckFreshIds(transformation_good_1, context.get(),
  880. &transformation_context);
  881. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  882. kConsoleMessageConsumer));
  883. // Good: Local variable of id 28 is defined in every caller (id 27 and id 31).
  884. TransformationAddParameter transformation_good_2(
  885. 10, 72, 7, {{{27, 28}, {31, 28}, {14, 21}, {16, 14}}}, 73);
  886. ASSERT_TRUE(transformation_good_2.IsApplicable(context.get(),
  887. transformation_context));
  888. ApplyAndCheckFreshIds(transformation_good_2, context.get(),
  889. &transformation_context);
  890. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  891. kConsoleMessageConsumer));
  892. std::string expected_shader = R"(
  893. OpCapability Shader
  894. %1 = OpExtInstImport "GLSL.std.450"
  895. OpMemoryModel Logical GLSL450
  896. OpEntryPoint Fragment %4 "main"
  897. OpExecutionMode %4 OriginUpperLeft
  898. OpSource ESSL 310
  899. OpName %4 "main"
  900. OpName %10 "fun(i1;"
  901. OpName %9 "a"
  902. OpName %12 "s"
  903. OpName %19 "i1"
  904. OpName %21 "i2"
  905. OpName %22 "i3"
  906. OpName %24 "i4"
  907. OpName %25 "param"
  908. OpName %28 "i5"
  909. OpName %29 "param"
  910. %2 = OpTypeVoid
  911. %3 = OpTypeFunction %2
  912. %6 = OpTypeInt 32 1
  913. %7 = OpTypePointer Function %6
  914. %15 = OpConstant %6 2
  915. %20 = OpConstant %6 1
  916. %23 = OpConstant %6 3
  917. %8 = OpTypeFunction %6 %7 %7 %7
  918. %4 = OpFunction %2 None %3
  919. %5 = OpLabel
  920. %19 = OpVariable %7 Function
  921. %21 = OpVariable %7 Function
  922. %22 = OpVariable %7 Function
  923. %24 = OpVariable %7 Function
  924. %25 = OpVariable %7 Function
  925. %28 = OpVariable %7 Function
  926. %29 = OpVariable %7 Function
  927. OpStore %19 %20
  928. OpStore %21 %15
  929. OpStore %22 %23
  930. %26 = OpLoad %6 %19
  931. OpStore %25 %26
  932. %27 = OpFunctionCall %6 %10 %25 %21 %28
  933. OpStore %24 %27
  934. %30 = OpLoad %6 %21
  935. OpStore %29 %30
  936. %31 = OpFunctionCall %6 %10 %29 %21 %28
  937. OpStore %28 %31
  938. OpReturn
  939. OpFunctionEnd
  940. %10 = OpFunction %6 None %8
  941. %9 = OpFunctionParameter %7
  942. %70 = OpFunctionParameter %7
  943. %72 = OpFunctionParameter %7
  944. %11 = OpLabel
  945. %12 = OpVariable %7 Function
  946. %13 = OpLoad %6 %9
  947. OpStore %12 %13
  948. %14 = OpLoad %6 %12
  949. %16 = OpIAdd %6 %14 %15
  950. OpReturnValue %16
  951. OpFunctionEnd
  952. )";
  953. ASSERT_TRUE(IsEqual(env, expected_shader, context.get()));
  954. }
  955. TEST(TransformationAddParameterTest, PointeeValueIsIrrelevantTest) {
  956. // This test checks if the transformation has correctly applied the
  957. // PointeeValueIsIrrelevant fact for new pointer parameters.
  958. std::string shader = R"(
  959. OpCapability Shader
  960. %1 = OpExtInstImport "GLSL.std.450"
  961. OpMemoryModel Logical GLSL450
  962. OpEntryPoint Fragment %4 "main"
  963. OpExecutionMode %4 OriginUpperLeft
  964. OpSource ESSL 310
  965. OpName %4 "main"
  966. OpName %10 "fun(i1;"
  967. OpName %9 "a"
  968. OpName %12 "s"
  969. OpName %20 "b"
  970. OpName %22 "i1"
  971. OpName %24 "i2"
  972. OpName %25 "i3"
  973. OpName %26 "param"
  974. OpName %29 "i4"
  975. OpName %30 "param"
  976. %2 = OpTypeVoid
  977. %3 = OpTypeFunction %2
  978. %6 = OpTypeInt 32 1
  979. %7 = OpTypePointer Function %6
  980. %50 = OpTypePointer Workgroup %6
  981. %51 = OpVariable %50 Workgroup
  982. %8 = OpTypeFunction %6 %7
  983. %15 = OpConstant %6 2
  984. %19 = OpTypePointer Private %6
  985. %20 = OpVariable %19 Private
  986. %21 = OpConstant %6 0
  987. %23 = OpConstant %6 1
  988. %4 = OpFunction %2 None %3
  989. %5 = OpLabel
  990. %22 = OpVariable %7 Function
  991. %24 = OpVariable %7 Function
  992. %25 = OpVariable %7 Function
  993. %26 = OpVariable %7 Function
  994. %29 = OpVariable %7 Function
  995. %30 = OpVariable %7 Function
  996. OpStore %20 %21
  997. OpStore %22 %23
  998. OpStore %24 %15
  999. %27 = OpLoad %6 %22
  1000. OpStore %26 %27
  1001. %28 = OpFunctionCall %6 %10 %26
  1002. OpStore %25 %28
  1003. %31 = OpLoad %6 %24
  1004. OpStore %30 %31
  1005. %32 = OpFunctionCall %6 %10 %30
  1006. OpStore %29 %32
  1007. OpReturn
  1008. OpFunctionEnd
  1009. %10 = OpFunction %6 None %8
  1010. %9 = OpFunctionParameter %7
  1011. %11 = OpLabel
  1012. %12 = OpVariable %7 Function
  1013. %13 = OpLoad %6 %9
  1014. OpStore %12 %13
  1015. %14 = OpLoad %6 %12
  1016. %16 = OpIAdd %6 %14 %15
  1017. OpReturnValue %16
  1018. OpFunctionEnd
  1019. )";
  1020. const auto env = SPV_ENV_UNIVERSAL_1_3;
  1021. const auto consumer = nullptr;
  1022. const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
  1023. spvtools::ValidatorOptions validator_options;
  1024. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  1025. kConsoleMessageConsumer));
  1026. TransformationContext transformation_context(
  1027. MakeUnique<FactManager>(context.get()), validator_options);
  1028. TransformationAddParameter transformation_good_1(10, 70, 7,
  1029. {{{28, 22}, {32, 22}}}, 71);
  1030. ASSERT_TRUE(transformation_good_1.IsApplicable(context.get(),
  1031. transformation_context));
  1032. ApplyAndCheckFreshIds(transformation_good_1, context.get(),
  1033. &transformation_context);
  1034. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  1035. kConsoleMessageConsumer));
  1036. // Check if the fact PointeeValueIsIrrelevant is set for the new parameter
  1037. // (storage class Function).
  1038. ASSERT_TRUE(
  1039. transformation_context.GetFactManager()->PointeeValueIsIrrelevant(70));
  1040. TransformationAddParameter transformation_good_2(10, 72, 19,
  1041. {{{28, 20}, {32, 20}}}, 73);
  1042. ASSERT_TRUE(transformation_good_2.IsApplicable(context.get(),
  1043. transformation_context));
  1044. ApplyAndCheckFreshIds(transformation_good_2, context.get(),
  1045. &transformation_context);
  1046. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  1047. kConsoleMessageConsumer));
  1048. // Check if the fact PointeeValueIsIrrelevant is set for the new parameter
  1049. // (storage class Private).
  1050. ASSERT_TRUE(
  1051. transformation_context.GetFactManager()->PointeeValueIsIrrelevant(72));
  1052. TransformationAddParameter transformation_good_3(10, 74, 50,
  1053. {{{28, 51}, {32, 51}}}, 75);
  1054. ASSERT_TRUE(transformation_good_3.IsApplicable(context.get(),
  1055. transformation_context));
  1056. ApplyAndCheckFreshIds(transformation_good_3, context.get(),
  1057. &transformation_context);
  1058. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  1059. kConsoleMessageConsumer));
  1060. // Check if the fact PointeeValueIsIrrelevant is set for the new parameter
  1061. // (storage class Workgroup).
  1062. ASSERT_TRUE(
  1063. transformation_context.GetFactManager()->PointeeValueIsIrrelevant(74));
  1064. }
  1065. } // namespace
  1066. } // namespace fuzz
  1067. } // namespace spvtools