Commit 990e4b24 by Nicolas Capens Committed by Nicolas Capens

Prevent changing Reference<> address

Reactor's Reference<> class represents a C++-like reference. It can be constructed from another reference, which creates a shallow copy, or it can be assigned another reference, which is a deep copy, but it cannot be assigned a new address. To enforce this, the address field was made constant. Also the default copy constructor outside the class definition, which is considered a user-provided copy constructor, was replaced with an in class defaulted default copy constructor. This makes it easier to understand that the copy constructor does default copying of the member fields when only looking at the class definition, takes fewer lines of code, and may enable some optimizations. Bug: b/191417833 Change-Id: Ied4ba3c7957b36efc06c19ce49f4e26309fb0c66 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/55029 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 8f075627
......@@ -213,7 +213,7 @@ public:
using reference_underlying_type = T;
explicit Reference(Value *pointer, int alignment = 1);
Reference(const Reference<T> &ref);
Reference(const Reference<T> &ref) = default;
RValue<T> operator=(RValue<T> rhs) const;
RValue<T> operator=(const Reference<T> &ref) const;
......@@ -227,7 +227,7 @@ public:
int getAlignment() const;
private:
Value *address;
Value *const address;
const int alignment;
};
......@@ -2697,15 +2697,12 @@ RValue<Pointer<T>> LValue<T>::operator&()
template<class T>
Reference<T>::Reference(Value *pointer, int alignment)
: alignment(alignment)
: address(pointer)
, alignment(alignment)
{
address = pointer;
}
template<class T>
Reference<T>::Reference(const Reference<T> &ref) = default;
template<class T>
RValue<T> Reference<T>::operator=(RValue<T> rhs) const
{
Nucleus::createStore(rhs.value(), address, T::type(), false, alignment);
......
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