Coverage Report

Created: 2025-12-14 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/shaderc/third_party/spirv-tools/source/val/validate.cpp
Line
Count
Source
1
// Copyright (c) 2015-2016 The Khronos Group 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
15
#include "source/val/validate.h"
16
17
#include <functional>
18
#include <iterator>
19
#include <memory>
20
#include <string>
21
#include <vector>
22
23
#include "source/binary.h"
24
#include "source/diagnostic.h"
25
#include "source/extensions.h"
26
#include "source/opcode.h"
27
#include "source/spirv_constant.h"
28
#include "source/spirv_endian.h"
29
#include "source/spirv_target_env.h"
30
#include "source/table2.h"
31
#include "source/val/construct.h"
32
#include "source/val/instruction.h"
33
#include "source/val/validation_state.h"
34
#include "spirv-tools/libspirv.h"
35
36
namespace {
37
// TODO(issue 1950): The validator only returns a single message anyway, so no
38
// point in generating more than 1 warning.
39
static uint32_t kDefaultMaxNumOfWarnings = 1;
40
}  // namespace
41
42
namespace spvtools {
43
namespace val {
44
namespace {
45
46
// Parses OpExtension instruction and registers extension.
47
void RegisterExtension(ValidationState_t& _,
48
458
                       const spv_parsed_instruction_t* inst) {
49
458
  const std::string extension_str = spvtools::GetExtensionString(inst);
50
458
  Extension extension;
51
458
  if (!GetExtensionFromString(extension_str.c_str(), &extension)) {
52
    // The error will be logged in the ProcessInstruction pass.
53
18
    return;
54
18
  }
55
56
440
  _.RegisterExtension(extension);
57
440
}
58
59
// Parses the beginning of the module searching for OpExtension instructions.
60
// Registers extensions if recognized. Returns SPV_REQUESTED_TERMINATION
61
// once an instruction which is not spv::Op::OpCapability and
62
// spv::Op::OpExtension is encountered. According to the SPIR-V spec extensions
63
// are declared after capabilities and before everything else.
64
spv_result_t ProcessExtensions(void* user_data,
65
3.08k
                               const spv_parsed_instruction_t* inst) {
66
3.08k
  const spv::Op opcode = static_cast<spv::Op>(inst->opcode);
67
3.08k
  if (opcode == spv::Op::OpCapability ||
68
1.37k
      opcode == spv::Op::OpConditionalCapabilityINTEL)
69
1.71k
    return SPV_SUCCESS;
70
71
1.37k
  if (opcode == spv::Op::OpExtension ||
72
914
      opcode == spv::Op::OpConditionalExtensionINTEL) {
73
458
    ValidationState_t& _ = *(reinterpret_cast<ValidationState_t*>(user_data));
74
458
    RegisterExtension(_, inst);
75
458
    return SPV_SUCCESS;
76
458
  }
77
78
  // OpExtension block is finished, requesting termination.
79
914
  return SPV_REQUESTED_TERMINATION;
80
1.37k
}
81
82
spv_result_t ProcessInstruction(void* user_data,
83
183k
                                const spv_parsed_instruction_t* inst) {
84
183k
  ValidationState_t& _ = *(reinterpret_cast<ValidationState_t*>(user_data));
85
86
183k
  auto* instruction = _.AddOrderedInstruction(inst);
87
183k
  _.RegisterDebugInstruction(instruction);
88
89
183k
  return SPV_SUCCESS;
90
183k
}
91
92
880
spv_result_t ValidateForwardDecls(ValidationState_t& _) {
93
880
  if (_.unresolved_forward_id_count() == 0) return SPV_SUCCESS;
94
95
0
  std::stringstream ss;
96
0
  std::vector<uint32_t> ids = _.UnresolvedForwardIds();
97
98
0
  std::transform(
99
0
      std::begin(ids), std::end(ids),
100
0
      std::ostream_iterator<std::string>(ss, " "),
101
0
      bind(&ValidationState_t::getIdName, std::ref(_), std::placeholders::_1));
102
103
0
  auto id_str = ss.str();
104
0
  return _.diag(SPV_ERROR_INVALID_ID, nullptr)
105
0
         << "The following forward referenced IDs have not been defined:\n"
106
0
         << id_str.substr(0, id_str.size() - 1);
107
880
}
108
109
// Entry point validation. Based on 2.16.1 (Universal Validation Rules) of the
110
// SPIRV spec:
111
// * There is at least one OpEntryPoint instruction, unless the Linkage
112
//   capability is being used.
113
// * No function can be targeted by both an OpEntryPoint instruction and an
114
//   OpFunctionCall instruction.
115
//
116
// Additionally enforces that entry points for Vulkan should not have recursion.
117
786
spv_result_t ValidateEntryPoints(ValidationState_t& _) {
118
786
  _.ComputeFunctionToEntryPointMapping();
119
786
  _.ComputeRecursiveEntryPoints();
120
121
786
  if (_.entry_points().empty() && !_.HasCapability(spv::Capability::Linkage) &&
122
0
      !_.HasCapability(spv::Capability::GraphARM)) {
123
0
    return _.diag(SPV_ERROR_INVALID_BINARY, nullptr)
124
0
           << "No OpEntryPoint instruction was found. This is only allowed if "
125
0
              "the Linkage or GraphARM capability is being used.";
126
0
  }
127
128
786
  for (const auto& entry_point : _.entry_points()) {
129
786
    if (_.IsFunctionCallTarget(entry_point)) {
130
0
      return _.diag(SPV_ERROR_INVALID_BINARY, _.FindDef(entry_point))
131
0
             << "A function (" << entry_point
132
0
             << ") may not be targeted by both an OpEntryPoint instruction and "
133
0
                "an OpFunctionCall instruction.";
134
0
    }
135
136
    // For Vulkan, the static function-call graph for an entry point
137
    // must not contain cycles.
138
786
    if (spvIsVulkanEnv(_.context()->target_env)) {
139
786
      if (_.recursive_entry_points().find(entry_point) !=
140
786
          _.recursive_entry_points().end()) {
141
0
        return _.diag(SPV_ERROR_INVALID_BINARY, _.FindDef(entry_point))
142
0
               << _.VkErrorID(4634)
143
0
               << "Entry points may not have a call graph with cycles.";
144
0
      }
145
786
    }
146
786
  }
147
148
786
  if (auto error = ValidateFloatControls2(_)) {
149
0
    return error;
150
0
  }
151
786
  if (auto error = ValidateDuplicateExecutionModes(_)) {
152
0
    return error;
153
0
  }
154
155
786
  return SPV_SUCCESS;
156
786
}
157
158
786
spv_result_t ValidateGraphEntryPoints(ValidationState_t& _) {
159
786
  if (_.graph_entry_points().empty() &&
160
786
      _.HasCapability(spv::Capability::GraphARM)) {
161
0
    return _.diag(SPV_ERROR_INVALID_BINARY, nullptr)
162
0
           << "No OpGraphEntryPointARM instruction was found but the GraphARM "
163
0
              "capability is declared.";
164
0
  }
165
786
  return SPV_SUCCESS;
166
786
}
167
168
spv_result_t ValidateBinaryUsingContextAndValidationState(
169
    const spv_context_t& context, const uint32_t* words, const size_t num_words,
170
914
    spv_diagnostic* pDiagnostic, ValidationState_t* vstate) {
171
914
  auto binary = std::unique_ptr<spv_const_binary_t>(
172
914
      new spv_const_binary_t{words, num_words});
173
174
914
  spv_endianness_t endian;
175
914
  spv_position_t position = {};
176
914
  if (spvBinaryEndianness(binary.get(), &endian)) {
177
0
    return DiagnosticStream(position, context.consumer, "",
178
0
                            SPV_ERROR_INVALID_BINARY)
179
0
           << "Invalid SPIR-V magic number.";
180
0
  }
181
182
914
  spv_header_t header;
183
914
  if (spvBinaryHeaderGet(binary.get(), endian, &header)) {
184
0
    return DiagnosticStream(position, context.consumer, "",
185
0
                            SPV_ERROR_INVALID_BINARY)
186
0
           << "Invalid SPIR-V header.";
187
0
  }
188
189
914
  if (header.version > spvVersionForTargetEnv(context.target_env)) {
190
0
    return DiagnosticStream(position, context.consumer, "",
191
0
                            SPV_ERROR_WRONG_VERSION)
192
0
           << "Invalid SPIR-V binary version "
193
0
           << SPV_SPIRV_VERSION_MAJOR_PART(header.version) << "."
194
0
           << SPV_SPIRV_VERSION_MINOR_PART(header.version)
195
0
           << " for target environment "
196
0
           << spvTargetEnvDescription(context.target_env) << ".";
197
0
  }
198
199
914
  if (header.bound > vstate->options()->universal_limits_.max_id_bound) {
200
0
    return DiagnosticStream(position, context.consumer, "",
201
0
                            SPV_ERROR_INVALID_BINARY)
202
0
           << "Invalid SPIR-V.  The id bound is larger than the max id bound "
203
0
           << vstate->options()->universal_limits_.max_id_bound << ".";
204
0
  }
205
206
  // Look for OpExtension instructions and register extensions.
207
  // This parse should not produce any error messages. Hijack the context and
208
  // replace the message consumer so that we do not pollute any state in input
209
  // consumer.
210
914
  spv_context_t hijacked_context = context;
211
914
  hijacked_context.consumer = [](spv_message_level_t, const char*,
212
914
                                 const spv_position_t&, const char*) {};
213
914
  spvBinaryParse(&hijacked_context, vstate, words, num_words,
214
914
                 /* parsed_header = */ nullptr, ProcessExtensions,
215
914
                 /* diagnostic = */ nullptr);
216
217
  // Parse the module and perform inline validation checks. These checks do
218
  // not require the knowledge of the whole module.
219
914
  if (auto error = spvBinaryParse(&context, vstate, words, num_words,
220
914
                                  /*parsed_header =*/nullptr,
221
914
                                  ProcessInstruction, pDiagnostic)) {
222
8
    return error;
223
8
  }
224
225
906
  bool has_mask_task_nv = false;
226
906
  bool has_mask_task_ext = false;
227
906
  std::vector<Instruction*> visited_entry_points;
228
177k
  for (auto& instruction : vstate->ordered_instructions()) {
229
177k
    {
230
      // In order to do this work outside of Process Instruction we need to be
231
      // able to, briefly, de-const the instruction.
232
177k
      Instruction* inst = const_cast<Instruction*>(&instruction);
233
234
177k
      if ((inst->opcode() == spv::Op::OpEntryPoint) ||
235
176k
          (inst->opcode() == spv::Op::OpConditionalEntryPointINTEL)) {
236
892
        const int i_model = inst->opcode() == spv::Op::OpEntryPoint ? 0 : 1;
237
892
        const int i_point = inst->opcode() == spv::Op::OpEntryPoint ? 1 : 2;
238
892
        const int i_name = inst->opcode() == spv::Op::OpEntryPoint ? 2 : 3;
239
892
        const int min_num_operands =
240
892
            inst->opcode() == spv::Op::OpEntryPoint ? 3 : 4;
241
242
892
        const auto entry_point = inst->GetOperandAs<uint32_t>(i_point);
243
892
        const auto execution_model =
244
892
            inst->GetOperandAs<spv::ExecutionModel>(i_model);
245
892
        const std::string desc_name = inst->GetOperandAs<std::string>(i_name);
246
247
892
        ValidationState_t::EntryPointDescription desc;
248
892
        desc.name = desc_name;
249
250
892
        std::vector<uint32_t> interfaces;
251
1.83k
        for (size_t j = min_num_operands; j < inst->operands().size(); ++j)
252
942
          desc.interfaces.push_back(inst->word(inst->operand(j).offset));
253
254
892
        vstate->RegisterEntryPoint(entry_point, execution_model,
255
892
                                   std::move(desc));
256
257
892
        if (inst->opcode() == spv::Op::OpEntryPoint) {
258
          // conditional entry points are allowed to share the same name and
259
          // exec mode
260
892
          if (visited_entry_points.size() > 0) {
261
0
            for (const Instruction* check_inst : visited_entry_points) {
262
0
              const auto check_execution_model =
263
0
                  check_inst->GetOperandAs<spv::ExecutionModel>(i_model);
264
0
              const std::string check_name =
265
0
                  check_inst->GetOperandAs<std::string>(i_name);
266
267
0
              if (desc_name == check_name &&
268
0
                  execution_model == check_execution_model) {
269
0
                return vstate->diag(SPV_ERROR_INVALID_DATA, inst)
270
0
                       << "2 Entry points cannot share the same name and "
271
0
                          "ExecutionMode.";
272
0
              }
273
0
            }
274
0
          }
275
892
          visited_entry_points.push_back(inst);
276
892
        }
277
278
892
        has_mask_task_nv |= (execution_model == spv::ExecutionModel::TaskNV ||
279
890
                             execution_model == spv::ExecutionModel::MeshNV);
280
892
        has_mask_task_ext |= (execution_model == spv::ExecutionModel::TaskEXT ||
281
892
                              execution_model == spv::ExecutionModel::MeshEXT);
282
892
      }
283
177k
      if (inst->opcode() == spv::Op::OpGraphEntryPointARM) {
284
0
        const auto graph = inst->GetOperandAs<uint32_t>(1);
285
0
        vstate->RegisterGraphEntryPoint(graph);
286
0
      }
287
177k
      if (inst->opcode() == spv::Op::OpFunctionCall) {
288
1.14k
        if (!vstate->in_function_body()) {
289
0
          return vstate->diag(SPV_ERROR_INVALID_LAYOUT, &instruction)
290
0
                 << "A FunctionCall must happen within a function body.";
291
0
        }
292
293
1.14k
        const auto called_id = inst->GetOperandAs<uint32_t>(2);
294
1.14k
        vstate->AddFunctionCallTarget(called_id);
295
1.14k
      }
296
297
177k
      if (vstate->in_function_body()) {
298
107k
        inst->set_function(&(vstate->current_function()));
299
107k
        inst->set_block(vstate->current_function().current_block());
300
301
107k
        if (vstate->in_block() && spvOpcodeIsBlockTerminator(inst->opcode())) {
302
8.49k
          vstate->current_function().current_block()->set_terminator(inst);
303
8.49k
        }
304
107k
      }
305
306
177k
      if (auto error = IdPass(*vstate, inst)) return error;
307
177k
    }
308
309
177k
    if (auto error = CapabilityPass(*vstate, &instruction)) return error;
310
177k
    if (auto error = ModuleLayoutPass(*vstate, &instruction)) return error;
311
177k
    if (auto error = CfgPass(*vstate, &instruction)) return error;
312
177k
    if (auto error = InstructionPass(*vstate, &instruction)) return error;
313
314
    // Now that all of the checks are done, update the state.
315
177k
    {
316
177k
      Instruction* inst = const_cast<Instruction*>(&instruction);
317
177k
      vstate->RegisterInstruction(inst);
318
177k
      if (inst->opcode() == spv::Op::OpTypeForwardPointer) {
319
124
        vstate->RegisterForwardPointer(inst->GetOperandAs<uint32_t>(0));
320
124
      }
321
177k
    }
322
177k
  }
323
324
880
  if (!vstate->has_memory_model_specified())
325
0
    return vstate->diag(SPV_ERROR_INVALID_LAYOUT, nullptr)
326
0
           << "Missing required OpMemoryModel instruction.";
327
328
880
  if (vstate->in_function_body())
329
0
    return vstate->diag(SPV_ERROR_INVALID_LAYOUT, nullptr)
330
0
           << "Missing OpFunctionEnd at end of module.";
331
332
880
  if (vstate->graph_definition_region() != kGraphDefinitionOutside)
333
0
    return vstate->diag(SPV_ERROR_INVALID_LAYOUT, nullptr)
334
0
           << "Missing OpGraphEndARM at end of module.";
335
336
880
  if (vstate->HasCapability(spv::Capability::BindlessTextureNV) &&
337
0
      !vstate->has_samplerimage_variable_address_mode_specified())
338
0
    return vstate->diag(SPV_ERROR_INVALID_LAYOUT, nullptr)
339
0
           << "Missing required OpSamplerImageAddressingModeNV instruction.";
340
341
880
  if (has_mask_task_ext && has_mask_task_nv)
342
0
    return vstate->diag(SPV_ERROR_INVALID_LAYOUT, nullptr)
343
0
           << vstate->VkErrorID(7102)
344
0
           << "Module can't mix MeshEXT/TaskEXT with MeshNV/TaskNV Execution "
345
0
              "Model.";
346
347
  // Catch undefined forward references before performing further checks.
348
880
  if (auto error = ValidateForwardDecls(*vstate)) return error;
349
350
  // Calculate reachability after all the blocks are parsed, but early that it
351
  // can be relied on in subsequent passes.
352
880
  ReachabilityPass(*vstate);
353
354
  // ID usage needs be handled in its own iteration of the instructions,
355
  // between the two others. It depends on the first loop to have been
356
  // finished, so that all instructions have been registered. And the following
357
  // loop depends on all of the usage data being populated. Thus it cannot live
358
  // in either of those iterations.
359
  // It should also live after the forward declaration check, since it will
360
  // have problems with missing forward declarations, but give less useful error
361
  // messages.
362
177k
  for (size_t i = 0; i < vstate->ordered_instructions().size(); ++i) {
363
176k
    auto& instruction = vstate->ordered_instructions()[i];
364
176k
    if (auto error = UpdateIdUse(*vstate, &instruction)) return error;
365
176k
  }
366
367
  // Validate individual opcodes.
368
168k
  for (size_t i = 0; i < vstate->ordered_instructions().size(); ++i) {
369
168k
    auto& instruction = vstate->ordered_instructions()[i];
370
371
    // Keep these passes in the order they appear in the SPIR-V specification
372
    // sections to maintain test consistency.
373
168k
    if (auto error = MiscPass(*vstate, &instruction)) return error;
374
168k
    if (auto error = DebugPass(*vstate, &instruction)) return error;
375
168k
    if (auto error = AnnotationPass(*vstate, &instruction)) return error;
376
167k
    if (auto error = ExtensionPass(*vstate, &instruction)) return error;
377
167k
    if (auto error = ModeSettingPass(*vstate, &instruction)) return error;
378
167k
    if (auto error = TypePass(*vstate, &instruction)) return error;
379
167k
    if (auto error = ConstantPass(*vstate, &instruction)) return error;
380
167k
    if (auto error = MemoryPass(*vstate, &instruction)) return error;
381
167k
    if (auto error = FunctionPass(*vstate, &instruction)) return error;
382
167k
    if (auto error = ImagePass(*vstate, &instruction)) return error;
383
167k
    if (auto error = ConversionPass(*vstate, &instruction)) return error;
384
167k
    if (auto error = CompositesPass(*vstate, &instruction)) return error;
385
167k
    if (auto error = ArithmeticsPass(*vstate, &instruction)) return error;
386
167k
    if (auto error = BitwisePass(*vstate, &instruction)) return error;
387
167k
    if (auto error = LogicalsPass(*vstate, &instruction)) return error;
388
167k
    if (auto error = ControlFlowPass(*vstate, &instruction)) return error;
389
167k
    if (auto error = DerivativesPass(*vstate, &instruction)) return error;
390
167k
    if (auto error = AtomicsPass(*vstate, &instruction)) return error;
391
167k
    if (auto error = PrimitivesPass(*vstate, &instruction)) return error;
392
167k
    if (auto error = BarriersPass(*vstate, &instruction)) return error;
393
    // Group
394
    // Device-Side Enqueue
395
    // Pipe
396
167k
    if (auto error = NonUniformPass(*vstate, &instruction)) return error;
397
398
167k
    if (auto error = LiteralsPass(*vstate, &instruction)) return error;
399
167k
    if (auto error = RayQueryPass(*vstate, &instruction)) return error;
400
167k
    if (auto error = RayTracingPass(*vstate, &instruction)) return error;
401
167k
    if (auto error = RayReorderNVPass(*vstate, &instruction)) return error;
402
167k
    if (auto error = RayReorderEXTPass(*vstate, &instruction)) return error;
403
167k
    if (auto error = MeshShadingPass(*vstate, &instruction)) return error;
404
167k
    if (auto error = TensorLayoutPass(*vstate, &instruction)) return error;
405
167k
    if (auto error = TensorPass(*vstate, &instruction)) return error;
406
167k
    if (auto error = GraphPass(*vstate, &instruction)) return error;
407
167k
    if (auto error = InvalidTypePass(*vstate, &instruction)) return error;
408
167k
  }
409
410
  // Validate the preconditions involving adjacent instructions. e.g.
411
  // spv::Op::OpPhi must only be preceded by spv::Op::OpLabel, spv::Op::OpPhi,
412
  // or spv::Op::OpLine.
413
786
  if (auto error = ValidateAdjacency(*vstate)) return error;
414
415
786
  if (auto error = ValidateEntryPoints(*vstate)) return error;
416
786
  if (auto error = ValidateGraphEntryPoints(*vstate)) return error;
417
  // CFG checks are performed after the binary has been parsed
418
  // and the CFGPass has collected information about the control flow
419
786
  if (auto error = PerformCfgChecks(*vstate)) return error;
420
786
  if (auto error = CheckIdDefinitionDominateUse(*vstate)) return error;
421
786
  if (auto error = ValidateDecorations(*vstate)) return error;
422
786
  if (auto error = ValidateInterfaces(*vstate)) return error;
423
  // TODO(dsinclair): Restructure ValidateBuiltins so we can move into the
424
  // for() above as it loops over all ordered_instructions internally.
425
786
  if (auto error = ValidateBuiltIns(*vstate)) return error;
426
  // These checks must be performed after individual opcode checks because
427
  // those checks register the limitation checked here.
428
166k
  for (const auto& inst : vstate->ordered_instructions()) {
429
166k
    if (auto error = ValidateExecutionLimitations(*vstate, &inst)) return error;
430
166k
    if (auto error = ValidateSmallTypeUses(*vstate, &inst)) return error;
431
166k
    if (auto error = ValidateQCOMImageProcessingTextureUsages(*vstate, &inst))
432
0
      return error;
433
166k
  }
434
786
  if (auto error = ValidateLogicalPointers(*vstate)) return error;
435
436
786
  return SPV_SUCCESS;
437
786
}
438
439
}  // namespace
440
441
spv_result_t ValidateBinaryAndKeepValidationState(
442
    const spv_const_context context, spv_const_validator_options options,
443
    const uint32_t* words, const size_t num_words, spv_diagnostic* pDiagnostic,
444
0
    std::unique_ptr<ValidationState_t>* vstate) {
445
0
  spv_context_t hijack_context = *context;
446
0
  if (pDiagnostic) {
447
0
    *pDiagnostic = nullptr;
448
0
    UseDiagnosticAsMessageConsumer(&hijack_context, pDiagnostic);
449
0
  }
450
451
0
  vstate->reset(new ValidationState_t(&hijack_context, options, words,
452
0
                                      num_words, kDefaultMaxNumOfWarnings));
453
454
0
  return ValidateBinaryUsingContextAndValidationState(
455
0
      hijack_context, words, num_words, pDiagnostic, vstate->get());
456
0
}
457
458
}  // namespace val
459
}  // namespace spvtools
460
461
spv_result_t spvValidate(const spv_const_context context,
462
                         const spv_const_binary binary,
463
0
                         spv_diagnostic* pDiagnostic) {
464
0
  return spvValidateBinary(context, binary->code, binary->wordCount,
465
0
                           pDiagnostic);
466
0
}
467
468
spv_result_t spvValidateBinary(const spv_const_context context,
469
                               const uint32_t* words, const size_t num_words,
470
0
                               spv_diagnostic* pDiagnostic) {
471
0
  spv_context_t hijack_context = *context;
472
0
  if (pDiagnostic) {
473
0
    *pDiagnostic = nullptr;
474
0
    spvtools::UseDiagnosticAsMessageConsumer(&hijack_context, pDiagnostic);
475
0
  }
476
477
  // This interface is used for default command line options.
478
0
  spv_validator_options default_options = spvValidatorOptionsCreate();
479
480
  // Create the ValidationState using the context and default options.
481
0
  spvtools::val::ValidationState_t vstate(&hijack_context, default_options,
482
0
                                          words, num_words,
483
0
                                          kDefaultMaxNumOfWarnings);
484
485
0
  spv_result_t result =
486
0
      spvtools::val::ValidateBinaryUsingContextAndValidationState(
487
0
          hijack_context, words, num_words, pDiagnostic, &vstate);
488
489
0
  spvValidatorOptionsDestroy(default_options);
490
0
  return result;
491
0
}
492
493
spv_result_t spvValidateWithOptions(const spv_const_context context,
494
                                    spv_const_validator_options options,
495
                                    const spv_const_binary binary,
496
914
                                    spv_diagnostic* pDiagnostic) {
497
914
  spv_context_t hijack_context = *context;
498
914
  if (pDiagnostic) {
499
914
    *pDiagnostic = nullptr;
500
914
    spvtools::UseDiagnosticAsMessageConsumer(&hijack_context, pDiagnostic);
501
914
  }
502
503
  // Create the ValidationState using the context.
504
914
  spvtools::val::ValidationState_t vstate(&hijack_context, options,
505
914
                                          binary->code, binary->wordCount,
506
914
                                          kDefaultMaxNumOfWarnings);
507
508
914
  return spvtools::val::ValidateBinaryUsingContextAndValidationState(
509
914
      hijack_context, binary->code, binary->wordCount, pDiagnostic, &vstate);
510
914
}