Commit 83dd452c by Ben Clayton

Reactor: Assert that array indexing is in bounds

For compile time indices, we can do some basic sanity checking. Change-Id: I9ae4ea5bbf106c4653cbf9bbe6776a5a188b4289 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/33470Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 4901ffd5
......@@ -26,7 +26,7 @@ namespace rr
// Set of variables that do not have a stack location yet.
std::unordered_set<Variable*> Variable::unmaterializedVariables;
Variable::Variable(Type *type, int arraySize) : type(type), arraySize(arraySize)
Variable::Variable(Type *type, int arraySize) : arraySize(arraySize), type(type)
{
#if REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION
materialize();
......
......@@ -132,6 +132,8 @@ namespace rr
~Variable();
const int arraySize;
private:
static void materializeAll();
static void killUnmaterialized();
......@@ -139,7 +141,6 @@ namespace rr
static std::unordered_set<Variable*> unmaterializedVariables;
Type *const type;
const int arraySize;
mutable Value *rvalue = nullptr;
mutable Value *address = nullptr;
};
......@@ -2915,6 +2916,7 @@ namespace rr
template<class T, int S>
Reference<T> Array<T, S>::operator[](int index)
{
assert(index < this->arraySize);
Value *element = LValue<T>::getElementPointer(Nucleus::createConstantInt(index), false);
return Reference<T>(element);
......@@ -2923,6 +2925,7 @@ namespace rr
template<class T, int S>
Reference<T> Array<T, S>::operator[](unsigned int index)
{
assert(index < static_cast<unsigned int>(this->arraySize));
Value *element = LValue<T>::getElementPointer(Nucleus::createConstantInt(index), true);
return Reference<T>(element);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment