Skip to content

Commit

Permalink
[SYCLomatic] Add parens for array subscribe expr when needed. (#1535)
Browse files Browse the repository at this point in the history
Signed-off-by: Tang, Jiajun [email protected]
  • Loading branch information
tangjj11 authored Dec 19, 2023
1 parent d02b608 commit b6849e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion clang/lib/DPCT/CallExprRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,11 @@ void printWithParens(StreamT &Stream,
printWithParens(Stream, AA, P);
}

template <class StreamT, class T>
void printWithParens(StreamT &Stream, const T &Val) {
print(Stream, Val);
}

template <class StreamT> void printMemberOp(StreamT &Stream, bool IsArrow) {
if (IsArrow)
Stream << "->";
Expand Down Expand Up @@ -1001,7 +1006,7 @@ template <class BaseT, class ArgValueT> class ArraySubscriptExprPrinter {
ArraySubscriptExprPrinter(const BaseT &base, ArgValueT &&Arg)
: Base(base), ArgValue(std::forward<ArgValueT>(Arg)) {}
template <class StreamT> void print(StreamT &Stream) const {
dpct::print(Stream, Base);
printWithParens(Stream, Base);
Stream << "[";
dpct::print(Stream, ArgValue);
Stream << "]";
Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/math/half/half.cu
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ __global__ void kernelFuncHalfConversion() {
h = __ll2half_rz(ll);
// CHECK: f = h2[0];
f = __low2float(h2);
// CHECK: f = *(&h2)[0];
// CHECK: f = (*(&h2))[0];
f = __low2float(*(&h2));
// CHECK: h = h2[0];
h = __low2half(h2);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/math/half/half_ext.cu
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ __global__ void kernelFuncHalfConversion() {
h = __ll2half_rz(ll);
// CHECK: f = h2[0];
f = __low2float(h2);
// CHECK: f = *(&h2)[0];
// CHECK: f = (*(&h2))[0];
f = __low2float(*(&h2));
// CHECK: h = h2[0];
h = __low2half(h2);
Expand Down

0 comments on commit b6849e5

Please sign in to comment.