Skip to content

[SYCL] fix a behavior mismatch in ann_ptr operator #11904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,10 @@ class annotated_ref {
T operator=(const annotated_ref&) const;
// OP is: +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^=
T operatorOP(const T &) const;
T operator++();
T operator++(int);
T operator--();
T operator--(int);
T operator++() const;
T operator++(int) const;
T operator--() const;
T operator--(int) const;
};
} // namespace sycl::ext::oneapi::experimental
```
Expand All @@ -556,7 +556,7 @@ annotations when the object is loaded from memory.
a|
[source,c++]
----
T operator=(const T &);
T operator=(const T &) const;
----
|
Writes an object of type `T` to the location referenced by this wrapper,
Expand All @@ -566,14 +566,14 @@ applying the annotations when the object is stored to memory.
a|
[source,c++]
----
T operator=(const annotated_ref& other);
T operator=(const annotated_ref& other) const;
----
a|
Equivalent to:
```c++
tmp T = other; // Reads from memory
T tmp = other; // Reads from memory
// with annotations
*this = T; // Writes to memory
*this = tmp; // Writes to memory
// with annotations
return T;
```
Expand All @@ -583,18 +583,18 @@ Does not rebind the reference!
a|
[source,c++]
----
T operatorOP(const T &);
T operatorOP(const T &) const;
----
a|
Where [code]#OP# is: [code]#pass:[+=]#, [code]#-=#,[code]#*=#, [code]#/=#, [code]#%=#, [code]#+<<=+#, [code]#>>=#, [code]#&=#, [code]#\|=#, [code]#^=#.

Compound assignment operators. Return result by value.
Available only if the corresponding non-compound operator is available for `T`.
Available only if the corresponding assignment operator OP is available for `T`.
Equivalent to:
```c++
T tmp = *this; // Reads from memory
// with annotations
tmp = tmp OP val;
tmp OP val;
*this = tmp; // Writes to memory
// with annotations
return tmp;
Expand All @@ -603,14 +603,16 @@ return tmp;
a|
[source,c++]
----
T operator++();
T operator++(int);
T operator--();
T operator--(int);
T operator++() const;
T operator++(int) const;
T operator--() const;
T operator--(int) const;
----
|
increment and decrement operator of annotated_ref. The annotations are applied
when the object `T` is loaded and stored to the memory.
Increment and decrement operator of annotated_ref. Increment/Decrement the object `T`
referenced by this wrapper via ``T``'s Increment/Decrement operator.

The annotations are applied when the object `T` is loaded and stored to the memory.
|===

== Issues related to `annotated_ptr`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ namespace experimental {

namespace {
#define PROPAGATE_OP(op) \
T operator op##=(const T &rhs) const { return *this = *this op rhs; }
T operator op##=(const T &rhs) const { \
T t = *this; \
t op## = rhs; \
*this = t; \
return t; \
}

// compare strings on compile time
constexpr bool compareStrs(const char *Str1, const char *Str2) {
Expand Down Expand Up @@ -114,22 +119,36 @@ class annotated_ref<T, detail::properties_t<Props...>> {
PROPAGATE_OP(<<)
PROPAGATE_OP(>>)

T operator++() { return *this += 1; }

T operator++(int) {
const T t = *this;
*this = (t + 1);
T operator++() const {
T t = *this;
++t;
*this = t;
return t;
}

T operator--() { return *this -= 1; }
T operator++(int) const {
T t1 = *this;
T t2 = t1;
t2++;
*this = t2;
return t1;
}

T operator--(int) {
const T t = *this;
*this = (t - 1);
T operator--() const {
T t = *this;
--t;
*this = t;
return t;
}

T operator--(int) const {
T t1 = *this;
T t2 = t1;
t2--;
*this = t2;
return t1;
}

template <class T2, class P2> friend class annotated_ptr;
};

Expand Down