Skip to content

Commit fd9a632

Browse files
authored
[SYCLomatic] Not add namespace of template operator function. (#2233)
Signed-off-by: Tang, Jiajun [email protected]
1 parent f257098 commit fd9a632

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

clang/lib/DPCT/ASTTraversal.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,6 +2844,8 @@ namespace ast_matchers {
28442844
AST_MATCHER(FunctionDecl, overloadedVectorOperator) {
28452845
if (!DpctGlobalInfo::isInAnalysisScope(Node.getBeginLoc()))
28462846
return false;
2847+
if (Node.isTemplateInstantiation())
2848+
return false; // Template operator function need not add namespace.
28472849

28482850
switch (Node.getOverloadedOperator()) {
28492851
default: {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// UNSUPPORTED: cuda-8.0, cuda-9.0, cuda-9.1, cuda-9.2, cuda-10.0, cuda-10.1, cuda-10.2, cuda-11.0
2+
// UNSUPPORTED: v8.0, v9.0, v9.1, v9.2, v10.0, v10.1, v10.2, v11.0
3+
// RUN: dpct -out-root %T/operator_overload/operator_overload_template %s --cuda-include-path="%cuda-path/include"
4+
// RUN: FileCheck --input-file %T/operator_overload/operator_overload_template/operator_overload_template.dp.cpp --match-full-lines %s
5+
// RUN: %if build_lit %{icpx -c -fsycl %T/operator_overload/operator_overload_template/operator_overload_template.dp.cpp -o %T/operator_overload/operator_overload_template/operator_overload_template.dp.o %}
6+
7+
#include "cuda_fp16.h"
8+
9+
// CHECK: template <typename T> struct S {};
10+
// CHECK-NEXT: template <typename T> void operator*(T a, const S<T> &b) {}
11+
template <typename T> struct S {};
12+
template <typename T> void operator*(T a, const S<T> &b) {}
13+
14+
int main() {
15+
S<float> s1;
16+
S<__half> s2;
17+
// CHECK: (float)1 * s1;
18+
(float)1 * s1;
19+
// CHECK: sycl::half(1.0) * s2;
20+
__half(1.0) * s2;
21+
return 0;
22+
}

0 commit comments

Comments
 (0)