Refactor remaining cases of memset(this, ...)
Use Memset<T> as the first base class of cache key types to ensure they
get initialized before any other base classes or members get
constructed.
Bug: b/134932616
Change-Id: I8f28252696d6e017db11da068180d2425cdf1d57
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/33249
Tested-by: Nicolas Capens <nicolascapens@google.com>
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Device/VertexProcessor.cpp b/src/Device/VertexProcessor.cpp
index 5c66309..2f489bb 100644
--- a/src/Device/VertexProcessor.cpp
+++ b/src/Device/VertexProcessor.cpp
@@ -19,7 +19,7 @@
#include "System/Math.hpp"
#include "Vulkan/VkDebug.hpp"
-#include <string.h>
+#include <cstring>
namespace sw
{
@@ -31,12 +31,12 @@
}
}
- unsigned int VertexProcessor::States::computeHash()
+ uint32_t VertexProcessor::States::computeHash()
{
- unsigned int *state = (unsigned int*)this;
- unsigned int hash = 0;
+ uint32_t *state = reinterpret_cast<uint32_t*>(this);
+ uint32_t hash = 0;
- for(unsigned int i = 0; i < sizeof(States) / 4; i++)
+ for(unsigned int i = 0; i < sizeof(States) / sizeof(uint32_t); i++)
{
hash ^= state[i];
}
@@ -44,11 +44,6 @@
return hash;
}
- VertexProcessor::State::State()
- {
- memset(this, 0, sizeof(State));
- }
-
bool VertexProcessor::State::operator==(const State &state) const
{
if(hash != state.hash)
@@ -56,6 +51,7 @@
return false;
}
+ static_assert(is_memcmparable<State>::value, "Cannot memcmp States");
return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
}