Skip to content

Commit dd0caa8

Browse files
authored
[SYCLomatic] Do not migrate __half_raw if it is a user-defined type (#1922)
Signed-off-by: Jiang, Zhiwei <[email protected]>
1 parent 7d8d4f3 commit dd0caa8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/lib/DPCT/ASTTraversal.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,6 +2684,11 @@ void VectorTypeNamespaceRule::runRule(const MatchFinder::MatchResult &Result) {
26842684
}
26852685
// Runrule for __half_raw implicitly convert to half.
26862686
if (auto DRE = getNodeAsType<DeclRefExpr>(Result, "halfRawExpr")) {
2687+
if (const auto *RT =
2688+
DRE->getType().getCanonicalType()->getAs<RecordType>()) {
2689+
if (isUserDefinedDecl(RT->getDecl()))
2690+
return;
2691+
}
26872692
ExprAnalysis EA;
26882693
std::string Replacement;
26892694
llvm::raw_string_ostream OS(Replacement);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: dpct --format-range=none --out-root %T/user_defined_half_raw %s --cuda-include-path="%cuda-path/include"
2+
// RUN: FileCheck %s --match-full-lines --input-file %T/user_defined_half_raw/user_defined_half_raw.dp.cpp
3+
// RUN: %if build_lit %{icpx -c -fsycl %T/user_defined_half_raw/user_defined_half_raw.dp.cpp -o %T/user_defined_half_raw/user_defined_half_raw.dp.o %}
4+
5+
struct __half_raw {
6+
__device__ __half_raw() : _raw(0) {}
7+
explicit __device__ __half_raw(unsigned short raw) : _raw(raw) {}
8+
unsigned short _raw;
9+
};
10+
11+
// CHECK: __half_raw foo(unsigned short x) {
12+
// CHECK-NEXT: __half_raw h;
13+
// CHECK-NEXT: h._raw = x;
14+
// CHECK-NEXT: return h;
15+
// CHECK-NEXT: }
16+
__device__ __half_raw foo(unsigned short x) {
17+
__half_raw h;
18+
h._raw = x;
19+
return h;
20+
}

0 commit comments

Comments
 (0)