Skip to content

Commit 65c4307

Browse files
authored
[SYCLomatic] Fix the issue that SYCL_EXTERNAL not inserted into right position in macro scenario(#2734)
Signed-off-by: intwanghao <[email protected]>
1 parent 6e4b531 commit 65c4307

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

clang/lib/DPCT/AnalysisInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4823,6 +4823,8 @@ DeviceFunctionDecl::DeviceFunctionDecl(
48234823
FuncInfo(getFuncInfo(FD)) {
48244824
if (FD->isFunctionTemplateSpecialization()) {
48254825
SourceRange ReturnTypeRange = FD->getReturnTypeSourceRange();
4826+
ReturnTypeRange = clang::dpct::getDefinitionRange(
4827+
ReturnTypeRange.getBegin(), ReturnTypeRange.getEnd());
48264828
OffsetForAttr =
48274829
DpctGlobalInfo::getLocInfo(ReturnTypeRange.getBegin()).second;
48284830
}
@@ -4859,6 +4861,11 @@ DeviceFunctionDecl::DeviceFunctionDecl(
48594861
FuncInfo(getFuncInfo(Specialization)) {
48604862
IsDefFilePathNeeded = false;
48614863

4864+
auto ReturnLoc = FTL.getReturnLoc();
4865+
auto ReturnRange = clang::dpct::getDefinitionRange(ReturnLoc.getBeginLoc(),
4866+
ReturnLoc.getEndLoc());
4867+
OffsetForAttr = DpctGlobalInfo::getLocInfo(ReturnRange.getBegin()).second;
4868+
48624869
buildReplaceLocInfo(FTL, Attrs);
48634870
buildTextureObjectParamsInfo(FTL.getParams());
48644871
if (Specialization->hasAttr<CUDAGlobalAttr>()) {

clang/test/dpct/mf-kernel.cu

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ __global__ void Reset_kernel_parameters(void)
1010
g_mutex=0;
1111
}
1212

13+
// CHECK: template <typename T> SYCL_EXTERNAL void template_test(T v) {};
14+
// CHECK: #define FUNC(T) template SYCL_EXTERNAL void template_test<T>(T v);
15+
// CHECK: FUNC(int)
16+
template <typename T> __global__ void template_test(T v) {};
17+
18+
#define FUNC(T) template __global__ void template_test<T>(T v);
19+
20+
FUNC(int)
21+
1322
// CHECK: SYCL_EXTERNAL void kernel_extern(const sycl::nd_item<3> &item_ct1, int *a) {
1423
__global__ void kernel_extern() {
1524
__shared__ int a[360];

clang/test/dpct/mf-kernel.cuh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// CHECK: SYCL_EXTERNAL void Reset_kernel_parameters(volatile int &g_mutex);
66
__global__ void Reset_kernel_parameters(void);
77

8+
// CHECK: template <typename T> SYCL_EXTERNAL void template_test(T v);
9+
template <typename T> __global__ void template_test(T v);
10+
811
// CHECK: SYCL_EXTERNAL void test_foo();
912
__device__ void test_foo(void);
1013

clang/test/dpct/mf-test.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ void test() {
7777
// CHECK-NEXT: });
7878
// CHECK-NEXT: }
7979
test_fp<<<1, 1>>>();
80+
81+
template_test<int><<<1, 1>>>(0);
82+
8083
}
8184

8285

0 commit comments

Comments
 (0)