Commit Graph

160 Commits

Author SHA1 Message Date
Steven Perron
482b1744ca
Validate all type ids. (#1868)
* Validate all type ids.

The validator does not check if the type of an instruction is actually
a type unless the OpCode has a specific requirement.  For example,
OpFAdd is checked, but OpUndef is not.

The commit add a generic check that if there is a type id then the id
defines a type.

http://crbug.com/876694

* Merge other checks for type into new one.

There are a couple check that the type id is a type for specific
opcodes.  Those have been mereged into 1.

Small changes to other test cases to make them valid enough for the
purpose of the test.
2018-08-27 23:45:32 -04:00
Steven Perron
06b42949b6
Validate uses of OpTypeFunction. (#1867)
In the specification of `OpTypeFunction`, it says

> OpFunction is the only valid use of OpTypeFunction.

This commit add a check in the validator for this rule.

A test started to fail because the new check happens before the check
the test case is testing.  Updated the test case to still fail the
check it was suppose to fail originally.

http://crbug.com/874571
2018-08-27 11:41:25 -04:00
alan-baker
d94a2077d6
Remove idUsage
* Moved remaining validation out of idUsage and deleted it
* Deleted unused functions
2018-08-27 11:06:09 -04:00
Alan Baker
6d27a8350f Fixing instances of iteration over unordered containers
* There were several instances found in the validator
 * validate_id.cpp
 * validate_decorations.cpp
 * validate_interfaces.cpp
2018-08-23 14:49:10 -04:00
Alan Baker
c5b38062ec Moving constant opcode validation into a new file
* Split constant opcode validation out of idUsage and into
validate_constants.cpp
 * minor style fixes
 * reduced duplication
 * fixed an issue with array sizing
2018-08-21 17:30:26 -04:00
Alan Baker
197b4597a0 Fix EvalInt32IfConst to fail on type instructions.
Fixes https://crbug.com/875842

* EvalInt32IfConst dereferenced a null pointer if a type instruction was
sent as the id
2018-08-21 11:59:00 -04:00
Steven Perron
36d675a404
Change when instruction is registered in validator. (#1840)
When doing the validator checks, an instruction is currently registered
at the end of IdPass.  This creates an inconsistency.  In IdPass, an
instruction that uses its own result will treat that use as a forward
reference.  Then in the following passes it will not because the
definition can be found.

It seems best to update the state after all of the check have been done
for the current instruction.  This makes it consistent for all of the
passes.

This makes a different when trying to verify OpTypeStruct.

Fixes https://crbug.com/874372.
2018-08-15 13:18:47 -04:00
dan sinclair
ef678672fb
Remove source/message.h (#1838)
The code in source/message was only used in a single set of tests to
format the output results. This CL changes the test to verify the
message instead of all the error values and removes the source/message
code.
2018-08-14 15:41:21 -04:00
Alan Baker
8cb949ad34 Validate correct opcode uses of OpFunction
Fixes https://crbug.com/873457

* Filed Khronos SPIR-V issue 352
* Updated bad tests
* Added new test
2018-08-14 10:13:06 -04:00
alan-baker
ce4547bdc7
Disallow void types in structs (#1832)
Fixes #1831

* Adds validation check that void is not a member of a struct
 * added a test
2018-08-14 08:55:49 -04:00
Alan Baker
e7fdcdba75 Split function opcode validation into new files.
* Moved function opcode validation out of idUsage and into new files
 * minor style changes
 * General opcode checking is in validate_function.cpp
 * Execution limitation checking is in
 validate_execution_limitations.cpp
* Execution limitations was split into a new pass as it requires other
validation to register those limitations first.
2018-08-13 17:04:57 -04:00
Alan Baker
397e02442e Fixing heap overflow in validation.
* Changed entry point validation to check storage class of variable
instead of pointer
 * added a test
* Moved several checks after opcode validation
 * These checks should be able to guarantee individual instructions are
 ok
* Updated tests due to reordered checks
2018-08-13 15:23:30 -04:00
Alan Baker
6cd4441c87 Move cfg opcode validation to another file.
* Moved cfg opcode validation out of idUsage and into validate_cfg.cpp
 * minor style updates
2018-08-13 11:30:08 -04:00
Alan Baker
714bf84e58 Split mode setting opcode validation into new file.
* Moved mode setting opcode validation out of idUsage and into a new
pass
 * minor style updates
2018-08-08 15:45:53 -04:00
Alan Baker
7d4b0464a3 Split annotation opcode validation into new file.
* Moves annotation opcode checks from idUsage into a new pass
 * minor style updates
2018-08-08 15:43:11 -04:00
Alan Baker
ca7278cff7 Split debug opcode validation into new file
* Removes debug opcode validation from idUsage and puts it in a separate
file
 * minor updates
2018-08-08 13:47:09 -04:00
Alan Baker
f2a990022a Move type instruction validation into separate file
* Moved type instruction validation out of validation idUsage into a new
file
* Consolidate type unique pass into new file
* Removed one bad test
* Reworked validation ordering
2018-08-08 12:55:39 -04:00
Alan Baker
3a20879f4d Unify validation of OpCopyMemory*
Fixes #1800

* Refactored duplication of code between OpCopyMemory and
OpCopyMemorySized validation
* Fixed some bugs in OpCopyMemorySized validation
* Replaced asserts with checks
* Added new tests
2018-08-07 19:01:58 -04:00
Alan Baker
2896b8f0e5 Refactor where opcodes are validated
* Replaced uses in opcode validation of current_function()
* Added non-const accessor to function lookup in ValidationState_t
* Updated a couple bad tests due to check reordering
2018-08-07 10:29:30 -04:00
dan sinclair
9991d661f8
Fix readbility/braces warnings (#1804) 2018-08-07 09:09:47 -04:00
dan sinclair
eda2cfbe12
Cleanup includes. (#1795)
This Cl cleans up the include paths to be relative to the top level
directory. Various include-what-you-use fixes have been added.
2018-08-03 15:06:09 -04:00
dan sinclair
58a6876cee
Rewrite include guards (#1793)
This CL rewrites the include guards to make PRESUBMIT.py include guard
check happy.
2018-08-03 08:05:33 -04:00
dan sinclair
d38a0a3b44
Validation within function body when doing a FunctionCall. (#1790)
When validating a FunctionCall we can trigger an assert if we are not
currently within a function body. This CL adds verification that we are
within a function before attempting to add a function call.

Issue 1789.
2018-08-02 16:58:45 -04:00
dan sinclair
6aa8a59415
Simplify validation ProcessInstruction (#1786)
This CL moves most of the logic out of validation ProcessInstruction and
groups it into validate. This places all of the validation logic in the
same place making it clearer what is running.

The Instruction class is changed to allow setting the function and block
after creation.
2018-08-02 15:12:06 -04:00
dan sinclair
1946fb4ddb
Remove ValidateInstructionAndUpdateValidationState (#1784)
This CL changes the stats aggregator to use
ValidateBinaryAndKeepValidationState to process the binary. This means
we can remove ValidateInstructionAndUpdateValidationState which expects
to be able to call ProcessInstruction in the validate anonymous
namespace. This decouples the stats aggregator from how validation
processes the binary.
2018-08-02 12:01:26 -04:00
dan sinclair
53afb3b77b
Combine ordered_instruction loops in validation. (#1782)
There are several validation passes which loop over all ordered
instructions. This CL combines those into a single loop, calling each
pass as needed.
2018-08-02 10:00:52 -04:00
dan sinclair
c9cd73b33a
Remove instruction_counter from ValidationState. (#1781)
The instruction counter is the same as the size of the
ordered_instruction list when we insert a new instruction. This Cl
removes instruction_counter_ and uses that instead.
2018-08-01 16:12:07 -04:00
Alan Baker
d49bedcaa6 Move memory class instructions to new pass
* Refactored the Memory class of instructions in the spec out Id
validation and into a new pass
 * Tests unmodified
 * some minor disassembly changes
 * minor style changes
2018-08-01 16:10:11 -04:00
dan sinclair
a5a5ea0e2d
Remove using std::<foo> statements. (#1756)
Many of the files have using std::<foo> statements in them, but then the
use of <foo> will be inconsistently std::<foo> or <foo> scattered
through the file. This CL removes all of the using statements and
updates the code to have the required std:: prefix.
2018-08-01 14:58:12 -04:00
dan sinclair
ebd6c75a71
Remove diag() overloads. (#1776)
This CL removes the two diag() overloads and leaves only the version
which accepts an Instruction. This is safer as we never use the
implicit location from the validation state.
2018-08-01 14:55:20 -04:00
dan sinclair
aa81e62cbe
Update diag() calls in validate_capability. (#1759)
This CL updates the diag() call in validate_capability to provide the
instruction.
2018-08-01 13:48:16 -04:00
dan sinclair
ab061afc83
Update diag() calls in validate_type_unique. (#1775)
This CL updates the diag() calls in validate_type_unique to pass the
relevant instruction.
2018-08-01 13:13:44 -04:00
dan sinclair
78335c927a
Update diag() calls in validate_primitives. (#1774)
This CL updates the diag() calls in validate_primitives to provide the
relevant instruction.
2018-08-01 13:00:38 -04:00
dan sinclair
6bb9ab48b8
Update diag() calls in validate_non_uniform. (#1773)
This CL upldates diag() calls in validate_non_uniform to provide the
relevant instruction.
2018-08-01 12:49:43 -04:00
dan sinclair
7c9a73fc30
Update diag() calls in validate_logicals. (#1772)
This CL updates the diag() calls in validate_logicals to provide the
Instruction.
2018-08-01 12:41:57 -04:00
dan sinclair
72766d9e88
Update diag() calls in validate_literals. (#1771)
This CL updates the diag() call in validate_literals to provide the
relevant instruction.
2018-08-01 12:41:46 -04:00
dan sinclair
e1e20f1abe
Update diag() calls in validate_layout. (#1770)
This CL updates the diag() calls in validate_layout to pass the relevant
instruction.
2018-08-01 12:01:35 -04:00
dan sinclair
f37e8d74e7
Update diag() call in validate_interface. (#1769)
This CL upldates validate_interface to pass the instruction to the
diag() method.
2018-08-01 11:58:37 -04:00
dan sinclair
d792ccd1ee
Update diag() calls in validate_instruction. (#1768)
This CL updates validate_instruction to pass the Instruction to diag().
2018-08-01 11:37:02 -04:00
dan sinclair
176cb5e593
Update diag() calls in validate_image. (#1767)
This CL updates the diag() calls in validate_image to provide the
relvant instruction.
2018-08-01 11:30:28 -04:00
dan sinclair
c64bad70d9
Update diag() calls in validate_ext_inst. (#1766)
This CL updates the diag() usage in validate_ext_inst to provide the
relevant instruction.
2018-08-01 11:11:23 -04:00
dan sinclair
441c0190eb
Update diag() calls in validate_derivatives. (#1765)
This CL updates diag() in validate_derivatives to provide the
instruction of interest.
2018-08-01 11:04:22 -04:00
dan sinclair
83b7f2b674
Update diag() calls in validate_decorations. (#1764)
Several of the diag() calls in validate_decorations do not provide the
line number, and will output the last line in the file. This CL updates
the diag() calls to provide the instruction of interest.
2018-08-01 10:44:27 -04:00
dan sinclair
a504656dad
Remove std::deque in favour of std::vector. (#1755)
This CL removes the two deque's from ValidationState and converts them
into std::vectors. In order to maintain the stability of instructions we
walk over the binary and counter the instructions and functions in the
ValidationState constructor and reserve the required number of items in
the module_functions_ and ordered_instructions_ vectors.

Issue #1176.
2018-08-01 10:37:36 -04:00
dan sinclair
fae987b470
Update diag() calls in validate_datarules. (#1763)
This CL updates validate_datarules to provide the instruction to diag().
2018-08-01 10:35:19 -04:00
dan sinclair
5a59a06e24
Update diag() calls in validate_conversion. (#1762)
This CL updates validate_conversion to provide the instruction to diag()
calls.
2018-08-01 10:18:06 -04:00
dan sinclair
eb03b152da
Update diag() calls in validate_composites. (#1761)
This CL updates the diag() calls in validate_composites to provide the
instruction directly.
2018-08-01 10:07:53 -04:00
dan sinclair
2c5f1b01d8
Update diag() calls in validate_cfg. (#1760)
This CL updates the diag() calls in validate_cfg to provide the
associated instruction. This fixes a couple places where we output the
last line of the file instead of the instruction as the disassembly.
2018-08-01 09:52:16 -04:00
dan sinclair
3619de9ad5
Update diag() use in validate_builtin. (#1758)
This CL updates the calls to diag() in vlidate_builtings to provide the
instruction.
2018-08-01 09:31:31 -04:00
dan sinclair
12c1f2b603
Update diag() usage in validate_bitwise. (#1757)
This Cl upldates the diag() calls to pass the instruction in
validate_bitwise.
2018-08-01 09:19:37 -04:00