Commit Graph

298 Commits

Author SHA1 Message Date
David Neto
2732f57ed2 Remove remaining float overflow value tests
Should fix tests on Windows.
2016-02-17 13:02:48 -05:00
David Neto
2889a0c21c Use syntax tables for SPIR-V 1.0 Rev3
- The SPIR-V spec generator has changed how it represents optional
  operands.  Now it tracks a separate boolean flag indicating optionality.
  However, SPIRV-Tools still wants to represent both operand class
  and optionality in the same enums space (SPV_OPERAND_TYPE_*).
  So there's extra work in the patch.

- In the spec generator, OperandImage is now OperandImageOperands.
  This affects enum translation in opcode.cpp.

- In the spec generator, image operands are explicitly followed by
  Id, and VariableIds.  However, SPIRV-Tools uses the bits set
  in the image operand bitmask to control the number and meaning
  of the Ids that follow.  So in writing the opcode.inc syntax
  table, drop all operands after OperandImageOperands.

- Some enums are now more explicitly represented in the generated
  opcode.inc:
    - AccessQualifier (e.g. on OpTypeImage), in both required and
      optional flavours.
    - MemoryAccess (e.g. on loads and stores)

- Add SPV_OPERAND_TYPE_OPTIONAL_ACCESS_QUALIFIER

- Add tests for the optional AccessQualifier operand on OpTypeImage.

- Update the AccessQualifier test for OpTypeImage so it's a round
  trip test through the disassembler as well.
2016-02-16 16:47:04 -05:00
David Neto
dd8a661b70 Update capabilities for 1.0 Rev3 2016-02-16 16:44:45 -05:00
David Neto
0c0a07f0aa Don't promise particular values when float parsing fails.
This should address problems on Windows:
https://github.com/KhronosGroup/SPIRV-Tools/issues/104
2016-02-16 12:13:51 -05:00
David Neto
c7a9a909a8 Parse overflow for fp16 like for 32- and 64-bit
In that case, set the stream fail bit, and set the maximum normal
value or lowest normal value, depending on the sign of the original
value.
2016-02-15 09:31:10 -05:00
David Neto
6bad02c320 Float literal parsing fixes
- For 32- and 64-bit floats, overflow is a parse error

  This works around a difference between Xcode's istringstream
  and other platforms.  Xcode's runtime library will happlily
  "round up" overflow values to infinity.  We want to make it fail.

- When parsing a float fails due to bad syntax, follow C++11
  behaviour for operator>> and set the value to zero.

- When parsing a 32-bit or 64-bit float overflows, follow C++11
  behaviour for operator>> and set the value to the nearest
  normal value: either max or lowest finite value for the type.

- Add FloatProxy<T>::max() and ::lowest()

- Make 16-bit overflow behaviour more consistent: we always get a
  16-bit infinity of the right sign, whether the original string
  is a normal value for 32-bit or an overflow value for 32-bit.
  That matches our earlier intent.
  Added TODO's to make 16-bit overflow always an error, just like
  for 32-bit and 64-bit.

- Simplify normal parsing of Float16 values by delegating to
  normal parsing of 32-bit floats.
2016-02-12 16:01:42 -05:00
David Neto
000cad9cc6 Reject float literals with two leading signs
E.g. --1 should be rejected.
2016-02-11 14:11:16 -05:00
David Neto
feda995c84 More parsing tests for literals with leading minus
Also checks some hex literal cases.

This addresses part of
https://github.com/KhronosGroup/SPIRV-Tools/issues/45
by removing the parseNumber case for "-0" on unsigned
integers.  We don't care about that platform difference
at the level of std::istringstream, since we reject it
at a higher parsing level.
2016-02-08 16:56:41 -05:00
Dejan Mircevski
7ef6da7b7f Make IsTypeNullable a transitive check. 2016-02-04 15:34:47 -05:00
Dejan Mircevski
4038195d81 Eliminate parameter-order check from ID-validation. 2016-02-03 12:34:52 -05:00
Dejan Mircevski
10fa696af7 Allow Op[No]Line between OpFunctionParameters.
Also ensure we don't get thrown off by too many parameters.
2016-02-03 10:26:59 -05:00
David Neto
b5267569d1 Add spvOperandIsConcreteMask 2016-02-02 12:05:34 -05:00
Dejan Mircevski
0c8bdfe163 Use AssemblyGrammar for capability validation.
Also:
- ForEach() for spv_capability_mask_t.
- Add capability min/max constants.
- Move max definition from validate_types.cpp to spirv_definition.h.
2016-02-02 11:40:05 -05:00
Dejan Mircevski
5f99fc33cd Forbid Generic variables. 2016-01-29 17:08:41 -05:00
Dejan Mircevski
8177fbea06 Fix in-function storage class validation.
Move tests into a fixture that properly turns on the relevant passes.
2016-01-29 16:30:23 -05:00
Dejan Mircevski
8db38e547b Initialize vector<string>s on first use, not statically. 2016-01-28 13:18:00 -05:00
Dejan Mircevski
1e157bc2e8 Fix validation of return value. 2016-01-28 10:58:03 -05:00
Dejan Mircevski
a4342f3f44 Remove spvOpcodeIsObject().
Also
- Add type_id to spv_id_info_t.
- Use spv_id_info_t::type_id instead of words[1].
  Triggered some asserts on tests, where the code incorrectly assumed
  words[1] had a type.  Remove the asserts and handle gracefully.
- Add tests for OpStore of a label, a void, and a function.
2016-01-27 16:20:10 -05:00
Umar Arshad
61a627586b Initial capability implementation and unit tests
* Register capabilility and checks
* Add validate storage class capabilities checks and tests
* Instruction pass refactor
  - More generic form of capability checking by checking operands
    instead of instructions
* Execution Model capabilities checks
* Decorate BuiltIn capability checks
* Addressing Model capability checks
* Memory Model capability checks
* Execution Mode capability checks
* Dim capability checks
* SamplerAddressingMode capability checks
2016-01-27 08:37:23 -05:00
Dejan Mircevski
276a724b25 Fix spvOpcodeIsScalarType() to include Boolean.
Remove redundant validations of OpConstant and OpConstantComposite.
Binary parser already performs these checks, so the validations can
never be triggered.

Enable bad-constant tests.
2016-01-22 16:40:27 -05:00
Dejan Mircevski
58852aa012 Fix OpLoad pointee type validation. 2016-01-21 14:07:19 -05:00
David Neto
c62f41e281 Add disassembler option to show byte offset
The option is disabled by default.

The offset is printed in hex, as a comment after each instruction.
2016-01-20 17:07:30 -05:00
Dejan Mircevski
961f5dc544 Track uses and defs during parsing.
Replace two other, imperfect mechanisms for use-def tracking.

Use ValidationState_t::entry_points to track entry points.

Concentrate undefined-ID diagnostics in a single place.

Move validate_types.h content into validate.h due to increased
inter-dependency.

Track uses of all IDs: TYPE_ID, SCOPE_ID, ...

Also update some blurbs.

Fix entry-point accumulation and move it outside ProcessIds().

Remove validate_types.h from CMakeLists.txt.

Blurb for spvIsIdType.

Remove redundant diagnostics for undefined IDs.

Join "can not" and reformat.
2016-01-20 17:00:58 -05:00
Umar Arshad
2a790fbc6d Fix missing OpNoLine layout checks 2016-01-18 13:44:42 -05:00
Umar Arshad
1ddeb246eb Validation refactor
* Organize passes into seperate files
* Remove module layout logic from Cfg pass
* Remove module layout logic from Functions class
* Refactor ModuleLayoutPass for readability
* Adapt consistent naming of layout sections (Stage/Section -> Section)
2016-01-14 21:59:28 -05:00
Umar Arshad
fa3b878119 Add missing branch instructions in SSA tests 2016-01-14 09:48:29 -05:00
Umar Arshad
c741385976 Function and block layout checks. very basic CFG.
This adds function and block layout checks to the validator. Very
basic CFG code has been added to make sure labels and branches
are correctly ordered.

Also:
* MemoryModel and Variable instruction checks/tests
* Use spvCheckReturn instead of CHECK_RESULT
* Fix invalid SSA tests
* Created libspirv::spvResultToString in diagnostic.h
* Documented various functions and classes
* Fixed error messages
* Fixed using declaration for FunctionDecl enum class
2016-01-13 10:06:58 -05:00
Andrew Woloszyn
ca50510ad4 Fixed use-after-free in isStartOfNewInst() tests. 2016-01-12 14:47:24 -05:00
David Neto
5d30edb36d spvDiagnosticDestroy is safe to call on nullptr
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/62
2016-01-11 14:26:46 -05:00
Andrew Woloszyn
3b69d05086 Fix endian-ness conversion in the binary parser.
When we were swapping endian-ness in the binary parser, we would
write outside of the bounds of our vector.
2016-01-11 13:54:30 -05:00
Andrew Woloszyn
7a35473573 Made compilation with gcc and clang more strict.
Added additional compilation flags to gcc and clang builds.
Adds -Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
-WNo-sign-conversion and -Wno-missing-field-initializers
where appropriate.

Does not add -Wundef to tests, because GTEST tests undefined
macros all over the place.
2016-01-11 10:54:20 -05:00
Andrew Woloszyn
43401d2ed0 Support 16-bit float in assembler and disassembler
This adds half-precision constants to spirv-tools.
16-bit floats are always disassembled into hex-float format,
but can be assembled from floating point or hex-float inputs.
2016-01-08 10:48:39 -05:00
Dejan Mircevski
b6fe02fc39 Extend copyright to 2016. 2016-01-07 13:44:22 -05:00
David Neto
969ce4b323 Fix list of opcodes allowed for OpSpecConstantOp
Was missing BitcastXor, GenericCastToPtr.
Remove duplicate of SLessThanEqual
2016-01-05 18:22:22 -05:00
David Neto
d0de196439 operator<< on FloatProxy preserves float and fill
Fixes formatting of disassembler output after printing
a hex float, e.g. for a NaN or subnormal.
2016-01-05 12:49:55 -05:00
David Neto
3664bd5670 Fix parser assert failure for a bad OpSwitch
Emit a diagnostic if the OpSwitch selector refers to an ID that
is valid but has no type.

Discovered by afl-fuzz.
2016-01-05 11:25:58 -05:00
David Neto
1a3734d265 Avoid relative path in #include
Adds CMAKE_CURRENT_SOURCE_DIR to the include path for UnitSPIRV
2016-01-04 13:07:45 -05:00
David Neto
4c21571728 Rename endian.h to spirv_endian.h
If we later add a source/ as an -I include directory,
then avoid confusing other headers that want to include the
standard "endian.h" from /usr/include.

Also rename source/endian.cpp to source/spirv_endian.cpp
2016-01-04 10:47:27 -05:00
Umar Arshad
a3d0d3c719 Initial logical layout validation
* Validates module level instructions for logical layout
  conformance
* Does not validate:
  1. Function logical layout
  2. Minor cases with OpVariable
  3. Missing MemoryModel instruction in module
  4. Order of function definition and function declaration
* 782 unit tests for logical layout

Addressed feedback
2015-12-17 15:58:09 -05:00
Umar Arshad
6d37e3c5f3 Refactor validation types into another file 2015-12-17 15:56:58 -05:00
Umar Arshad
532af9c09c Fix tests which rely on OpName;Use EXPECT_THAT
All OpName calls should appear before annotation and type
declarations.
2015-12-14 14:33:26 -05:00
Umar Arshad
f76e0f5231 Basic SSA Validation
Most uses of an ID must occur after the definition
of the ID.  Forward references are allowed for
things like OpName, OpDecorate, and various cases
of control-flow instructions such as OpBranch, OpPhi,
and OpFunctionCall.

TODO: Use CFG analysis for SSA checks.  In particular,
an ID defined inside a function body is only usable inside
that function body.  Also, use dominator info to catch
some failing cases.

Also:
* Validator test cases use (standard) assignment form.
* Update style to more closely follow the Google C++ style guide
* Remove color-diagnostics flag.
  This is enabled by default on terminals with color. Prints
  hidden ASCII for terminals that can't handle color(Emacs)
* Pass functors to SSAPass to check if the
  operand can be forward referenced based on its index value
* Return SPV_ERROR_INVALID_ID for ID related errors
  spvBinaryParse returned SPV_ERROR_INVALID_BINARY for all types of
  errors. Since spvBinaryParse does some ID validation, this was
  returning inappropriate error codes for some tests.
* Common fixture for validation tests.
  It only runs certian validation passes.
* Add a SPV_VALIDATE_SSA_BIT for testing purposes
* Fixtures now return error codes
* Add OpName support in diag message and unit tests
* Binary parsing can fail with invalid ID or invalid binary error code

Tests include:
* OpDecorate
* OpName
* OpMemberName
* OpBranchConditional
* OpSelectionMerge
* OpMemberDecorate
* OpGroupDecorate
* OpDeviceEnqueue
* Enable several tests failing in ID validation.
2015-12-09 16:15:00 -05:00
Andrew Woloszyn
4e5bc928c0 Added Float16, and HexFloat conversions 2015-12-08 14:41:57 -05:00
David Neto
4b6a98fe16 Fix namespace on PrintTo 2015-12-02 11:55:35 -05:00
David Neto
590ff131ac PrintTo on WordVector should preserve the fill char 2015-12-01 18:25:03 -05:00
David Neto
5947c40483 Stated word count is several more than expected
These are extra binary parsing cases.
2015-12-01 16:45:46 -05:00
David Neto
66f649d501 Use static_cast instead of constructor for uint32_t 2015-12-01 16:19:44 -05:00
David Neto
39fa148234 OpDecorate should not accept any number of literal operands.
This is a grammar fix.  The Decoration operand of OpDecorate (and
OpMemberDecorate) determines the remaining operands.  Don't just
allow any number of literal numbers as operands.

(The OperandVariableLiterals operand class as the last member
of the OpDecorate and OpMemberDecorate entries in in opcode.inc is
an artifact of how the spec generates the opcode descriptions. It's
not suitable for parsing those instructions.)

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/34
2015-12-01 15:38:32 -05:00
David Neto
36909c05a5 binary parse test: extra words after string literal
Covers the case where the string literal is the
last operand.

TODO: Case where one more operand is expected after
the string literal.  Occurs only for the LinkageAttributes
decoration.  To test that, we need to update the grammar
as well.
2015-12-01 15:38:32 -05:00
Dejan Mircevski
15aebef8a0 Merge PR #32.
Simplify binary parser tests using GoogleMock.
2015-11-30 18:06:33 -05:00