Fix UBSAN error:
```
lib/DxilRootSignature/DxilRootSignatureSerializer.cpp:134:5: runtime error: store to misaligned address 0x7fff812daf5f for type 'unsigned int', which requires 4 byte alignment
```
Use memcpy to write to unaligned address.
Fixes 63 of these reported from running check-all.
This change applies clang-format to all of the sources added in DXC that
were not part of the original LLVM/Clang 3.7 release when DXC forked.
This provides consistent code formatting across the codebase.
Fixes#5591.
We don't keep these annotations up to date or rely on them, so to
simplify our platform layering and ease code formatting this change
removes all the SAL annotations from internal APIs. This change also
replaces most `_Analysis_Assme_(...)` annotations with `assert(...)`.
One `_Analysis_Assume_` in ParseDecl.cpp needed to be updated because it
was incorrect. The code was `_Analysis_Assume_(assert(name.size() >
sizeof("space"));`. When converted to an `assert` it fired in our test
suite because the sizeof a string literal includes the null terminator,
but the size of a StringRef does not.
A few of the `_Analysis_Assume_` annotations were removed because they
didn't make sense (like the ones inside the `DXASSERT` implementation,
and a few others were removed to avoid introducing additional header or
linkage dependencies.
This change does not introduce any functional or behavioral changes.
* remove warnings on dxc
* address feedback
* remove removed functions' declarations
* get rid of another unused function
* use maybe_unused instead of if 0 when removing unused functions
* address commenting issues
* Revert "use maybe_unused instead of if 0 when removing unused functions" because c++17 extensions aren't enabled
This reverts commit 3a00d8eb84.
* remove incorrect scope
* Clean up and rework DXIL library depencencies
This change reworks the dependency specifications for the DXIL*
libraries. Many of these libraries had over and under specified
dependencies.
This also collapses the DxilRDATBuidlder into the DxilContainer library
to remove the cyclic dependency between the two libraries.
* Break assert dependency between DXIL and Analysis
In assert builds the DXILModule constructor was creating forced bindings
to debugging methods that are often used from the debugger. This forced
binding is useful, but doesn't need to live in the DXIL library.
To break the dependency I've moved the code into Analysis. I've also
made that code only included when building with MSVC. When using other
compilers `__attribute__((used))` can be applied to the function via the
`LLVM_DUMP_METHOD` annotation to have the same effect.
PIX is unique in that it needs to deserialize, modify and then reserialize root sigs. The focus of this checkin is adding such modifications to PixPassHelpers.cpp. (This closes a gap in PIX support: PIX can now support shaders that use dxil-defined and attribute-style root signatures.)
But this required some work outside of the purely PIX-focused areas. Deserialized root sigs are described by a C-like structure with embedded arrays that are new/delete-ed by routines in DxilRootSignature.cpp. Since modifying these structs requires more new/delete calls, I chose to add a new entry point in DxilRootSignature.cpp to do the bare minimum that PIX needs: extend root params by one descriptor. This approach keeps all those raw new/deletes in one file.
I found a leak in DxilRootSignatureSerialzier.cpp, which I fixed. There appear to be no unit tests that exercise this path. I welcome feedback on adding one.
There were other leaks in class CVersionedRootSignatureDeserializer, but this class is unused so I deleted it.
Oh, and there are bazillions of commits because I was cherry-picking from a recent change (#4845) as it eveolved, since I needed that change and this to test PIX.
* Address some low hanging fruit UBSan failures
Undefined Behavior Sanitizer causes hard failures on runtime conditions that exhibit undefined behavior as defined by C and C++. These issues may not cause immediately identifiable software errors, but the code behavior is dependent on the compiler and runtime implementation. As a result they may become difficult to diagnose or detect errors in the future if the compiler or runtime changes.
This change addresses occurrences of the following undefined behaviors.
* Performing arithmetic operations on null pointers.
* Calling memcpy with a source or destination pointer that is null.
* Calling memset with a destination pointer that is null.
* Assigning an enum a value which is not a valid enum for that enum.
* Reading from unaligned pointers.
After this change, there are 23 remaining undefined behavior failures in the current DXC tests which are less trivial to resolve.
Building DXC with another build system revealed that some includes
were dependent on headers only available by chance. Adding missing
headers.
Signed-off-by: Nathan Gauër <brioche@google.com>
Signed-off-by: Nathan Gauër <brioche@google.com>
* Stop creating binary blobs with UTF-8 encoding
* Strip BOM and fix some related issues
- detect and strip BOM only when interpreting as text:
- DxcCreateBlob: only when encoding is known and not CP_ACP
- DxcGetBlobAsUtf[8|16]: when encoding not known or CP_ACP
- strncmp in BOM detection would misfire (should have been memcmp)
- ambiguous BOM case not handled/noted
- empty blob case fixes (handle null-term empty, don't leak)
Note, there are still problems in the unicode handling:
- No actual support for UTF-32 or big endian input encodings.
- For Linux: "UTF-16" isn't, and bad assumptions around "wide" strings.
* Add defines for CP_UTF*; improve error for unsupported utf conversions
Possibly due to a visual studio update, building with vs2019 started
causing build failures due to using std::hex without the necessary
iostream include. This adds that include to the two files that need it.
* Add mesh shader support to RootSignature parsing/validation
* Fix PSV so MS output topology doesn't overlap SigInputVectors
* fix PSV version code to use latest when validation disabled
DxcCreateBlobOnHeapCopy allocated using the COM allocator and freed using the default thread allocator, leading to crashes.
But more generally, some DxcCreateBlob functions would take ownership of the passed-in buffer without also having the caller explicitly specify what IMalloc to use for deallocation, which is an error-prone pattern, so I reworked these methods a bit.
This also lead me to find some memory leaks and general memory mismanagement in the the rewriter.