Skip to content

Commit a413a8c

Browse files
authored
[SYCL][NATIVECPU] Fix assert in MS name mangler (#11103)
This PR prevents the MS name mangler to assert on the unhandled `CC_OpenCLKernel` calling convention which can end up in the AST when targeting NativeCPU on Windows - see attached test case that triggers the assert. This assert is also triggered on a number of e2e tests on NativeCPU. This patch handles the CC_OpenCLKernel convention currently only for NativeCPU and the usual error is raised for other targets as before.
1 parent 1cdb3c6 commit a413a8c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,6 +2906,17 @@ void MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC) {
29062906
else
29072907
Out << "w";
29082908
break;
2909+
case CC_OpenCLKernel:
2910+
// This can occur on the SYCl NativeCPU device
2911+
// where device code is compiled with the same
2912+
// target triple (eg for Windows) as host code.
2913+
// FIXME: 1.) provide mangling if needed
2914+
// 2.) check if other conventions need to be handled.
2915+
if (!getASTContext().getLangOpts().SYCLIsNativeCPU)
2916+
// Currently we only allow this convention in
2917+
// SYCLNativeCPU and raise the usual error otherwise.
2918+
llvm_unreachable("Unsupported CC for mangling");
2919+
break;
29092920
}
29102921
}
29112922
void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This test ensures the native-cpu device generates the expected kernel names,
2+
// and that the MS mangler doesn't assert on the code below.
3+
4+
// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -aux-triple x86_64-pc-windows-msvc -I %S/Inputs -fsycl-is-device -fsycl-is-native-cpu -emit-llvm -o - -x c++ %s | FileCheck %s
5+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple x86_64-unknown-linux-gnu -I %S/Inputs -fsycl-is-device -fsycl-is-native-cpu -emit-llvm -o - -x c++ %s | FileCheck %s
6+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple x86_64-pc-windows-msvc -I %S/Inputs -fsycl-is-device -fsycl-is-native-cpu -emit-llvm -o - -x c++ %s | FileCheck %s
7+
// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -aux-triple x86_64-unknown-linux-gnu -I %S/Inputs -fsycl-is-device -fsycl-is-native-cpu -emit-llvm -o - -x c++ %s | FileCheck %s
8+
// Todo: check other cpus
9+
10+
#include "sycl.hpp"
11+
12+
struct name1;
13+
14+
void test(sycl::handler &h) {
15+
h.parallel_for_work_group<name1>(sycl::range<1>(2),sycl::range<1>(1), [=](sycl::group<1> G) {});
16+
}
17+
18+
// CHECK: void @_ZTS5name1(

0 commit comments

Comments
 (0)