| 1 |
// Copyright (c) 2020 Google LLC |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
#include "source/fuzz/transformation_compute_data_synonym_fact_closure.h" |
| 16 |
|
| 17 |
#include "gtest/gtest.h" |
| 18 |
#include "source/fuzz/fuzzer_util.h" |
| 19 |
#include "test/fuzz/fuzz_test_util.h" |
| 20 |
|
| 21 |
namespace spvtools { |
| 22 |
namespace fuzz { |
| 23 |
namespace { |
| 24 |
|
| 25 |
TEST(TransformationComputeDataSynonymFactClosureTest, DataSynonymFacts) { |
| 26 |
// The SPIR-V types and constants come from the following code. The body of |
| 27 |
// the SPIR-V function then constructs a composite that is synonymous with |
| 28 |
// myT. |
| 29 |
// |
| 30 |
// #version 310 es |
| 31 |
// |
| 32 |
// precision highp float; |
| 33 |
// |
| 34 |
// struct S { |
| 35 |
// int a; |
| 36 |
// uvec2 b; |
| 37 |
// }; |
| 38 |
// |
| 39 |
// struct T { |
| 40 |
// bool c[5]; |
| 41 |
// mat4x2 d; |
| 42 |
// S e; |
| 43 |
// }; |
| 44 |
// |
| 45 |
// void main() { |
| 46 |
// T myT = T(bool[5](true, false, true, false, true), |
| 47 |
// mat4x2(vec2(1.0, 2.0), vec2(3.0, 4.0), |
| 48 |
// vec2(5.0, 6.0), vec2(7.0, 8.0)), |
| 49 |
// S(10, uvec2(100u, 200u))); |
| 50 |
// } |
| 51 |
|
| 52 |
std::string shader = R"( |
| 53 |
OpCapability Shader |
| 54 |
%1 = OpExtInstImport "GLSL.std.450" |
| 55 |
OpMemoryModel Logical GLSL450 |
| 56 |
OpEntryPoint Fragment %4 "main" |
| 57 |
OpExecutionMode %4 OriginUpperLeft |
| 58 |
OpSource ESSL 310 |
| 59 |
OpName %4 "main" |
| 60 |
OpName %15 "S" |
| 61 |
OpMemberName %15 0 "a" |
| 62 |
OpMemberName %15 1 "b" |
| 63 |
OpName %16 "T" |
| 64 |
OpMemberName %16 0 "c" |
| 65 |
OpMemberName %16 1 "d" |
| 66 |
OpMemberName %16 2 "e" |
| 67 |
OpName %18 "myT" |
| 68 |
OpMemberDecorate %15 0 RelaxedPrecision |
| 69 |
OpMemberDecorate %15 1 RelaxedPrecision |
| 70 |
%2 = OpTypeVoid |
| 71 |
%3 = OpTypeFunction %2 |
| 72 |
%6 = OpTypeBool |
| 73 |
%7 = OpTypeInt 32 0 |
| 74 |
%8 = OpConstant %7 5 |
| 75 |
%9 = OpTypeArray %6 %8 |
| 76 |
%10 = OpTypeFloat 32 |
| 77 |
%11 = OpTypeVector %10 2 |
| 78 |
%12 = OpTypeMatrix %11 4 |
| 79 |
%13 = OpTypeInt 32 1 |
| 80 |
%14 = OpTypeVector %7 2 |
| 81 |
%15 = OpTypeStruct %13 %14 |
| 82 |
%16 = OpTypeStruct %9 %12 %15 |
| 83 |
%17 = OpTypePointer Function %16 |
| 84 |
%19 = OpConstantTrue %6 |
| 85 |
%20 = OpConstantFalse %6 |
| 86 |
%21 = OpConstantComposite %9 %19 %20 %19 %20 %19 |
| 87 |
%22 = OpConstant %10 1 |
| 88 |
%23 = OpConstant %10 2 |
| 89 |
%24 = OpConstantComposite %11 %22 %23 |
| 90 |
%25 = OpConstant %10 3 |
| 91 |
%26 = OpConstant %10 4 |
| 92 |
%27 = OpConstantComposite %11 %25 %26 |
| 93 |
%28 = OpConstant %10 5 |
| 94 |
%29 = OpConstant %10 6 |
| 95 |
%30 = OpConstantComposite %11 %28 %29 |
| 96 |
%31 = OpConstant %10 7 |
| 97 |
%32 = OpConstant %10 8 |
| 98 |
%33 = OpConstantComposite %11 %31 %32 |
| 99 |
%34 = OpConstantComposite %12 %24 %27 %30 %33 |
| 100 |
%35 = OpConstant %13 10 |
| 101 |
%36 = OpConstant %7 100 |
| 102 |
%37 = OpConstant %7 200 |
| 103 |
%38 = OpConstantComposite %14 %36 %37 |
| 104 |
%39 = OpConstantComposite %15 %35 %38 |
| 105 |
%40 = OpConstantComposite %16 %21 %34 %39 |
| 106 |
%4 = OpFunction %2 None %3 |
| 107 |
%5 = OpLabel |
| 108 |
%18 = OpVariable %17 Function |
| 109 |
OpStore %18 %40 |
| 110 |
%100 = OpCompositeConstruct %9 %19 %20 %19 %20 %19 |
| 111 |
%101 = OpCompositeConstruct %11 %22 %23 |
| 112 |
%102 = OpCompositeConstruct %11 %25 %26 |
| 113 |
%103 = OpCompositeConstruct %11 %28 %29 |
| 114 |
%104 = OpCompositeConstruct %11 %31 %32 |
| 115 |
%105 = OpCompositeConstruct %12 %101 %102 %103 %104 |
| 116 |
%106 = OpCompositeConstruct %14 %36 %37 |
| 117 |
%107 = OpCompositeConstruct %15 %35 %106 |
| 118 |
%108 = OpCompositeConstruct %16 %100 %105 %107 |
| 119 |
OpReturn |
| 120 |
OpFunctionEnd |
| 121 |
)"; |
| 122 |
|
| 123 |
const auto env = SPV_ENV_UNIVERSAL_1_3; |
| 124 |
const auto consumer = nullptr; |
| 125 |
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption); |
| 126 |
spvtools::ValidatorOptions validator_options; |
| 127 |
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options, |
| 128 |
kConsoleMessageConsumer)); |
| 129 |
TransformationContext transformation_context( |
| 130 |
MakeUnique<FactManager>(context.get()), validator_options); |
| 131 |
ASSERT_TRUE(TransformationComputeDataSynonymFactClosure(100).IsApplicable( |
| 132 |
context.get(), transformation_context)); |
| 133 |
|
| 134 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 135 |
MakeDataDescriptor(24, {}), MakeDataDescriptor(101, {}))); |
| 136 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 137 |
MakeDataDescriptor(24, {0}), MakeDataDescriptor(101, {0}))); |
| 138 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 139 |
MakeDataDescriptor(24, {1}), MakeDataDescriptor(101, {1}))); |
| 140 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 141 |
MakeDataDescriptor(24, {0}), MakeDataDescriptor(101, {1}))); |
| 142 |
|
| 143 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 144 |
MakeDataDescriptor(24, {}), MakeDataDescriptor(101, {})); |
| 145 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 146 |
MakeDataDescriptor(24, {}), MakeDataDescriptor(101, {}))); |
| 147 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 148 |
MakeDataDescriptor(24, {0}), MakeDataDescriptor(101, {0}))); |
| 149 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 150 |
MakeDataDescriptor(24, {1}), MakeDataDescriptor(101, {1}))); |
| 151 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 152 |
MakeDataDescriptor(24, {0}), MakeDataDescriptor(101, {1}))); |
| 153 |
|
| 154 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 155 |
MakeDataDescriptor(27, {}), MakeDataDescriptor(102, {}))); |
| 156 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 157 |
MakeDataDescriptor(27, {0}), MakeDataDescriptor(102, {0}))); |
| 158 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 159 |
MakeDataDescriptor(27, {1}), MakeDataDescriptor(102, {1}))); |
| 160 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 161 |
MakeDataDescriptor(27, {0}), MakeDataDescriptor(102, {0})); |
| 162 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 163 |
MakeDataDescriptor(27, {}), MakeDataDescriptor(102, {}))); |
| 164 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 165 |
MakeDataDescriptor(27, {0}), MakeDataDescriptor(102, {0}))); |
| 166 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 167 |
MakeDataDescriptor(27, {1}), MakeDataDescriptor(102, {1}))); |
| 168 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 169 |
MakeDataDescriptor(27, {1}), MakeDataDescriptor(102, {1})); |
| 170 |
|
| 171 |
ApplyAndCheckFreshIds(TransformationComputeDataSynonymFactClosure(100), |
| 172 |
context.get(), &transformation_context); |
| 173 |
|
| 174 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 175 |
MakeDataDescriptor(27, {}), MakeDataDescriptor(102, {}))); |
| 176 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 177 |
MakeDataDescriptor(27, {0}), MakeDataDescriptor(102, {0}))); |
| 178 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 179 |
MakeDataDescriptor(27, {1}), MakeDataDescriptor(102, {1}))); |
| 180 |
|
| 181 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 182 |
MakeDataDescriptor(30, {}), MakeDataDescriptor(103, {}))); |
| 183 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 184 |
MakeDataDescriptor(30, {0}), MakeDataDescriptor(103, {0}))); |
| 185 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 186 |
MakeDataDescriptor(30, {1}), MakeDataDescriptor(103, {1}))); |
| 187 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 188 |
MakeDataDescriptor(33, {}), MakeDataDescriptor(104, {}))); |
| 189 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 190 |
MakeDataDescriptor(33, {0}), MakeDataDescriptor(104, {0}))); |
| 191 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 192 |
MakeDataDescriptor(33, {1}), MakeDataDescriptor(104, {1}))); |
| 193 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 194 |
MakeDataDescriptor(34, {}), MakeDataDescriptor(105, {}))); |
| 195 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 196 |
MakeDataDescriptor(34, {0}), MakeDataDescriptor(105, {0}))); |
| 197 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 198 |
MakeDataDescriptor(34, {1}), MakeDataDescriptor(105, {1}))); |
| 199 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 200 |
MakeDataDescriptor(34, {2}), MakeDataDescriptor(105, {2}))); |
| 201 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 202 |
MakeDataDescriptor(34, {3}), MakeDataDescriptor(105, {3}))); |
| 203 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 204 |
MakeDataDescriptor(30, {}), MakeDataDescriptor(103, {})); |
| 205 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 206 |
MakeDataDescriptor(33, {}), MakeDataDescriptor(104, {})); |
| 207 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 208 |
MakeDataDescriptor(34, {0}), MakeDataDescriptor(105, {0})); |
| 209 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 210 |
MakeDataDescriptor(34, {1}), MakeDataDescriptor(105, {1})); |
| 211 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 212 |
MakeDataDescriptor(34, {2}), MakeDataDescriptor(105, {2})); |
| 213 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 214 |
MakeDataDescriptor(30, {}), MakeDataDescriptor(103, {}))); |
| 215 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 216 |
MakeDataDescriptor(30, {0}), MakeDataDescriptor(103, {0}))); |
| 217 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 218 |
MakeDataDescriptor(30, {1}), MakeDataDescriptor(103, {1}))); |
| 219 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 220 |
MakeDataDescriptor(33, {}), MakeDataDescriptor(104, {}))); |
| 221 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 222 |
MakeDataDescriptor(33, {0}), MakeDataDescriptor(104, {0}))); |
| 223 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 224 |
MakeDataDescriptor(33, {1}), MakeDataDescriptor(104, {1}))); |
| 225 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 226 |
MakeDataDescriptor(34, {}), MakeDataDescriptor(105, {}))); |
| 227 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 228 |
MakeDataDescriptor(34, {0}), MakeDataDescriptor(105, {0}))); |
| 229 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 230 |
MakeDataDescriptor(34, {1}), MakeDataDescriptor(105, {1}))); |
| 231 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 232 |
MakeDataDescriptor(34, {2}), MakeDataDescriptor(105, {2}))); |
| 233 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 234 |
MakeDataDescriptor(34, {3}), MakeDataDescriptor(105, {3}))); |
| 235 |
|
| 236 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 237 |
MakeDataDescriptor(34, {3}), MakeDataDescriptor(105, {3})); |
| 238 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 239 |
MakeDataDescriptor(33, {0}), MakeDataDescriptor(104, {0}))); |
| 240 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 241 |
MakeDataDescriptor(34, {3}), MakeDataDescriptor(105, {3}))); |
| 242 |
|
| 243 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 244 |
MakeDataDescriptor(21, {}), MakeDataDescriptor(100, {}))); |
| 245 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 246 |
MakeDataDescriptor(21, {0}), MakeDataDescriptor(100, {0})); |
| 247 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 248 |
MakeDataDescriptor(21, {1}), MakeDataDescriptor(100, {1})); |
| 249 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 250 |
MakeDataDescriptor(21, {2}), MakeDataDescriptor(100, {2})); |
| 251 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 252 |
MakeDataDescriptor(21, {3}), MakeDataDescriptor(100, {3})); |
| 253 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 254 |
MakeDataDescriptor(21, {4}), MakeDataDescriptor(100, {4})); |
| 255 |
|
| 256 |
ApplyAndCheckFreshIds(TransformationComputeDataSynonymFactClosure(100), |
| 257 |
context.get(), &transformation_context); |
| 258 |
|
| 259 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 260 |
MakeDataDescriptor(21, {}), MakeDataDescriptor(100, {}))); |
| 261 |
|
| 262 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 263 |
MakeDataDescriptor(39, {0}), MakeDataDescriptor(107, {0}))); |
| 264 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 265 |
MakeDataDescriptor(35, {}), MakeDataDescriptor(39, {0}))); |
| 266 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 267 |
MakeDataDescriptor(39, {0}), MakeDataDescriptor(35, {})); |
| 268 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 269 |
MakeDataDescriptor(39, {0}), MakeDataDescriptor(107, {0}))); |
| 270 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 271 |
MakeDataDescriptor(35, {}), MakeDataDescriptor(39, {0}))); |
| 272 |
|
| 273 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 274 |
MakeDataDescriptor(38, {0}), MakeDataDescriptor(36, {}))); |
| 275 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 276 |
MakeDataDescriptor(38, {1}), MakeDataDescriptor(37, {}))); |
| 277 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 278 |
MakeDataDescriptor(106, {0}), MakeDataDescriptor(36, {}))); |
| 279 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 280 |
MakeDataDescriptor(106, {1}), MakeDataDescriptor(37, {}))); |
| 281 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 282 |
MakeDataDescriptor(38, {}), MakeDataDescriptor(106, {}))); |
| 283 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 284 |
MakeDataDescriptor(38, {0}), MakeDataDescriptor(36, {})); |
| 285 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 286 |
MakeDataDescriptor(106, {0}), MakeDataDescriptor(36, {})); |
| 287 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 288 |
MakeDataDescriptor(38, {1}), MakeDataDescriptor(37, {})); |
| 289 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 290 |
MakeDataDescriptor(106, {1}), MakeDataDescriptor(37, {})); |
| 291 |
|
| 292 |
ApplyAndCheckFreshIds(TransformationComputeDataSynonymFactClosure(100), |
| 293 |
context.get(), &transformation_context); |
| 294 |
|
| 295 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 296 |
MakeDataDescriptor(38, {0}), MakeDataDescriptor(36, {}))); |
| 297 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 298 |
MakeDataDescriptor(38, {1}), MakeDataDescriptor(37, {}))); |
| 299 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 300 |
MakeDataDescriptor(106, {0}), MakeDataDescriptor(36, {}))); |
| 301 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 302 |
MakeDataDescriptor(106, {1}), MakeDataDescriptor(37, {}))); |
| 303 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 304 |
MakeDataDescriptor(38, {}), MakeDataDescriptor(106, {}))); |
| 305 |
|
| 306 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 307 |
MakeDataDescriptor(40, {}), MakeDataDescriptor(108, {}))); |
| 308 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 309 |
MakeDataDescriptor(107, {0}), MakeDataDescriptor(35, {})); |
| 310 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 311 |
MakeDataDescriptor(40, {0}), MakeDataDescriptor(108, {0})); |
| 312 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 313 |
MakeDataDescriptor(40, {1}), MakeDataDescriptor(108, {1})); |
| 314 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 315 |
MakeDataDescriptor(40, {2}), MakeDataDescriptor(108, {2})); |
| 316 |
|
| 317 |
ApplyAndCheckFreshIds(TransformationComputeDataSynonymFactClosure(100), |
| 318 |
context.get(), &transformation_context); |
| 319 |
|
| 320 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 321 |
MakeDataDescriptor(40, {}), MakeDataDescriptor(108, {}))); |
| 322 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 323 |
MakeDataDescriptor(40, {0}), MakeDataDescriptor(108, {0}))); |
| 324 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 325 |
MakeDataDescriptor(40, {1}), MakeDataDescriptor(108, {1}))); |
| 326 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 327 |
MakeDataDescriptor(40, {2}), MakeDataDescriptor(108, {2}))); |
| 328 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 329 |
MakeDataDescriptor(40, {0, 0}), MakeDataDescriptor(108, {0, 0}))); |
| 330 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 331 |
MakeDataDescriptor(40, {0, 1}), MakeDataDescriptor(108, {0, 1}))); |
| 332 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 333 |
MakeDataDescriptor(40, {0, 2}), MakeDataDescriptor(108, {0, 2}))); |
| 334 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 335 |
MakeDataDescriptor(40, {0, 3}), MakeDataDescriptor(108, {0, 3}))); |
| 336 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 337 |
MakeDataDescriptor(40, {0, 4}), MakeDataDescriptor(108, {0, 4}))); |
| 338 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 339 |
MakeDataDescriptor(40, {1, 0}), MakeDataDescriptor(108, {1, 0}))); |
| 340 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 341 |
MakeDataDescriptor(40, {1, 1}), MakeDataDescriptor(108, {1, 1}))); |
| 342 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 343 |
MakeDataDescriptor(40, {1, 2}), MakeDataDescriptor(108, {1, 2}))); |
| 344 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 345 |
MakeDataDescriptor(40, {1, 3}), MakeDataDescriptor(108, {1, 3}))); |
| 346 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 347 |
MakeDataDescriptor(40, {1, 0, 0}), MakeDataDescriptor(108, {1, 0, 0}))); |
| 348 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 349 |
MakeDataDescriptor(40, {1, 1, 0}), MakeDataDescriptor(108, {1, 1, 0}))); |
| 350 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 351 |
MakeDataDescriptor(40, {1, 2, 0}), MakeDataDescriptor(108, {1, 2, 0}))); |
| 352 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 353 |
MakeDataDescriptor(40, {1, 3, 0}), MakeDataDescriptor(108, {1, 3, 0}))); |
| 354 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 355 |
MakeDataDescriptor(40, {1, 0, 1}), MakeDataDescriptor(108, {1, 0, 1}))); |
| 356 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 357 |
MakeDataDescriptor(40, {1, 1, 1}), MakeDataDescriptor(108, {1, 1, 1}))); |
| 358 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 359 |
MakeDataDescriptor(40, {1, 2, 1}), MakeDataDescriptor(108, {1, 2, 1}))); |
| 360 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 361 |
MakeDataDescriptor(40, {1, 3, 1}), MakeDataDescriptor(108, {1, 3, 1}))); |
| 362 |
|
| 363 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 364 |
MakeDataDescriptor(40, {2, 0}), MakeDataDescriptor(108, {2, 0}))); |
| 365 |
|
| 366 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 367 |
MakeDataDescriptor(40, {2, 1}), MakeDataDescriptor(108, {2, 1}))); |
| 368 |
|
| 369 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 370 |
MakeDataDescriptor(40, {2, 1, 0}), MakeDataDescriptor(108, {2, 1, 0}))); |
| 371 |
|
| 372 |
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous( |
| 373 |
MakeDataDescriptor(40, {2, 1, 1}), MakeDataDescriptor(108, {2, 1, 1}))); |
| 374 |
} |
| 375 |
|
| 376 |
TEST(TransformationComputeDataSynonymFactClosureTest, |
| 377 |
ComputeClosureWithMissingIds) { |
| 378 |
std::string shader = R"( |
| 379 |
OpCapability Shader |
| 380 |
%1 = OpExtInstImport "GLSL.std.450" |
| 381 |
OpMemoryModel Logical GLSL450 |
| 382 |
OpEntryPoint Fragment %12 "main" |
| 383 |
OpExecutionMode %12 OriginUpperLeft |
| 384 |
OpSource ESSL 310 |
| 385 |
%2 = OpTypeVoid |
| 386 |
%3 = OpTypeFunction %2 |
| 387 |
%6 = OpTypeInt 32 1 |
| 388 |
%7 = OpTypeVector %6 4 |
| 389 |
%15 = OpConstant %6 24 |
| 390 |
%16 = OpConstantComposite %7 %15 %15 %15 %15 |
| 391 |
%17 = OpConstantComposite %7 %15 %15 %15 %15 |
| 392 |
%18 = OpTypeStruct %7 |
| 393 |
%19 = OpConstantComposite %18 %16 |
| 394 |
%30 = OpConstantComposite %18 %17 |
| 395 |
%12 = OpFunction %2 None %3 |
| 396 |
%13 = OpLabel |
| 397 |
%50 = OpCopyObject %7 %16 |
| 398 |
%51 = OpCopyObject %7 %17 |
| 399 |
%20 = OpCopyObject %6 %15 |
| 400 |
%21 = OpCopyObject %6 %15 |
| 401 |
%22 = OpCopyObject %6 %15 |
| 402 |
OpReturn |
| 403 |
OpFunctionEnd |
| 404 |
)"; |
| 405 |
|
| 406 |
const auto env = SPV_ENV_UNIVERSAL_1_3; |
| 407 |
const auto consumer = nullptr; |
| 408 |
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption); |
| 409 |
ValidatorOptions validator_options; |
| 410 |
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options, |
| 411 |
kConsoleMessageConsumer)); |
| 412 |
|
| 413 |
TransformationContext transformation_context( |
| 414 |
MakeUnique<FactManager>(context.get()), validator_options); |
| 415 |
|
| 416 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 417 |
MakeDataDescriptor(20, {}), MakeDataDescriptor(15, {})); |
| 418 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 419 |
MakeDataDescriptor(21, {}), MakeDataDescriptor(15, {})); |
| 420 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 421 |
MakeDataDescriptor(22, {}), MakeDataDescriptor(15, {})); |
| 422 |
|
| 423 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 424 |
MakeDataDescriptor(17, {0}), MakeDataDescriptor(15, {})); |
| 425 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 426 |
MakeDataDescriptor(17, {1}), MakeDataDescriptor(15, {})); |
| 427 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 428 |
MakeDataDescriptor(17, {2}), MakeDataDescriptor(15, {})); |
| 429 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 430 |
MakeDataDescriptor(17, {3}), MakeDataDescriptor(15, {})); |
| 431 |
|
| 432 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 433 |
MakeDataDescriptor(16, {0}), MakeDataDescriptor(20, {})); |
| 434 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 435 |
MakeDataDescriptor(16, {1}), MakeDataDescriptor(21, {})); |
| 436 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 437 |
MakeDataDescriptor(16, {2}), MakeDataDescriptor(22, {})); |
| 438 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 439 |
MakeDataDescriptor(16, {3}), MakeDataDescriptor(15, {})); |
| 440 |
|
| 441 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 442 |
MakeDataDescriptor(51, {0}), MakeDataDescriptor(15, {})); |
| 443 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 444 |
MakeDataDescriptor(51, {1}), MakeDataDescriptor(15, {})); |
| 445 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 446 |
MakeDataDescriptor(51, {2}), MakeDataDescriptor(15, {})); |
| 447 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 448 |
MakeDataDescriptor(51, {3}), MakeDataDescriptor(15, {})); |
| 449 |
|
| 450 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 451 |
MakeDataDescriptor(50, {0}), MakeDataDescriptor(20, {})); |
| 452 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 453 |
MakeDataDescriptor(50, {1}), MakeDataDescriptor(21, {})); |
| 454 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 455 |
MakeDataDescriptor(50, {2}), MakeDataDescriptor(22, {})); |
| 456 |
transformation_context.GetFactManager()->AddFactDataSynonym( |
| 457 |
MakeDataDescriptor(50, {3}), MakeDataDescriptor(15, {})); |
| 458 |
|
| 459 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 460 |
MakeDataDescriptor(19, {}), MakeDataDescriptor(30, {}))); |
| 461 |
|
| 462 |
context->KillDef(20); |
| 463 |
context->KillDef(21); |
| 464 |
context->KillDef(22); |
| 465 |
context->KillDef(50); |
| 466 |
context->KillDef(51); |
| 467 |
context->InvalidateAnalysesExceptFor(opt::IRContext::kAnalysisNone); |
| 468 |
|
| 469 |
ApplyAndCheckFreshIds(TransformationComputeDataSynonymFactClosure(100), |
| 470 |
context.get(), &transformation_context); |
| 471 |
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous( |
| 472 |
MakeDataDescriptor(19, {}), MakeDataDescriptor(30, {}))); |
| 473 |
} |
| 474 |
|
| 475 |
} // namespace |
| 476 |
} // namespace fuzz |
| 477 |
} // namespace spvtools |