Skip to content

Commit 2fa6376

Browse files
authored
[SYCL] Conditionally enable diagnosing that requires integration header (#5044)
#4945 introduced a new diagnostic that works correctly only if integration header is included. However it is possible that `-fsycl-is-host` flag can be used without integration header, so the diagnostic should be issued only if integration header is included. This patch adds new cc1 option that helps to understand that.
1 parent 2614d4d commit 2fa6376

File tree

10 files changed

+41
-30
lines changed

10 files changed

+41
-30
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ LANGOPT(
273273
"get/operator[], get_id/operator[] and get_global_id/get_global_linear_id "
274274
"in SYCL class id, iterm and nd_iterm")
275275
LANGOPT(SYCLDisableRangeRounding, 1, 0, "Disable parallel for range rounding")
276+
LANGOPT(SYCLEnableIntHeaderDiags, 1, 0, "Enable diagnostics that require the "
277+
"SYCL integration header")
276278

277279
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
278280

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6060,6 +6060,9 @@ def fenable_sycl_dae : Flag<["-"], "fenable-sycl-dae">,
60606060
def fsycl_disable_range_rounding : Flag<["-"], "fsycl-disable-range-rounding">,
60616061
HelpText<"Disable parallel for range rounding.">,
60626062
MarshallingInfoFlag<LangOpts<"SYCLDisableRangeRounding">>;
6063+
def fsycl_enable_int_header_diags: Flag<["-"], "fsycl-enable-int-header-diags">,
6064+
HelpText<"Enable diagnostics that require the SYCL integration header.">,
6065+
MarshallingInfoFlag<LangOpts<"SYCLEnableIntHeaderDiags">>;
60636066

60646067
} // let Flags = [CC1Option, NoDriverOption]
60656068

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4853,6 +4853,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
48534853
// header file.
48544854
CmdArgs.push_back("-dependency-filter");
48554855
CmdArgs.push_back(Args.MakeArgString(Header));
4856+
4857+
// Since this is a host compilation and the integration header is
4858+
// included, enable the integration header based diagnostics.
4859+
CmdArgs.push_back("-fsycl-enable-int-header-diags");
48564860
}
48574861
// Let the FE know we are doing a SYCL offload compilation, but we are
48584862
// doing the host pass.

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,13 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
491491
Diags.Report(diag::err_drv_argument_not_allowed_with) << "-fsycl-is-device"
492492
<< "-fsycl-is-host";
493493

494+
// SYCLEnableIntHeader implies SYCLIsHost. Error if
495+
// -fsycl-enable-int-header-diags is passed without -fsycl-is-host.
496+
if (LangOpts.SYCLEnableIntHeaderDiags && !LangOpts.SYCLIsHost)
497+
Diags.Report(diag::err_opt_not_valid_without_opt)
498+
<< "-fsycl-enable-int-header-diags"
499+
<< "-fsycl-is-host";
500+
494501
if (Args.hasArg(OPT_fgnu89_inline) && LangOpts.CPlusPlus)
495502
Diags.Report(diag::err_drv_argument_not_allowed_with)
496503
<< "-fgnu89-inline" << GetInputKindName(IK);

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3515,7 +3515,8 @@ class SYCLKernelNameTypeVisitor
35153515
// case will resolve to ::main::KernelName1 (instead of
35163516
// ::KernelName1). Since this is not visible to runtime code that
35173517
// submits kernels, this is invalid.
3518-
if (Tag->isCompleteDefinition() || S.getLangOpts().SYCLIsHost) {
3518+
if (Tag->isCompleteDefinition() ||
3519+
S.getLangOpts().SYCLEnableIntHeaderDiags) {
35193520
S.Diag(KernelInvocationFuncLoc,
35203521
diag::err_sycl_kernel_incorrectly_named)
35213522
<< /* kernel name should be forward declarable at namespace

clang/test/CodeGenSYCL/loop_fusion_host.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ __attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
55
kernelFunc();
66
}
77

8-
// This test uses SYCL host only mode without integration header, so
9-
// forward declare used kernel name class, otherwise it will be diagnosed by
10-
// the diagnostic implemented in https://github.com/intel/llvm/pull/4945.
11-
// The error happens because in host mode it is assumed that all kernel names
12-
// are forward declared at global or namespace scope because of integration
13-
// header.
14-
class kernel_name_1;
15-
168
template <int SIZE>
179
class KernelFunctor5 {
1810
public:

clang/test/CodeGenSYCL/stall_enable_host.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
// Tests for IR of Intel FPGA [[intel::use_stall_enable_clusters]] function attribute on Host (no-op in IR-CodeGen for host-mode).
44

5-
// This test uses SYCL host only mode without integration header, so
6-
// forward declare used kernel name class, otherwise it will be diagnosed by
7-
// the diagnostic implemented in https://github.com/intel/llvm/pull/4945.
8-
// The error happens because in host mode it is assumed that all kernel names
9-
// are forward declared at global or namespace scope because of integration
10-
// header.
11-
class kernel_name_1;
12-
135
[[intel::use_stall_enable_clusters]] void test() {}
146

157
void test1() {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Test that we disallow -fsycl-enable-int-header-diags without -fsycl-is-host.
2+
3+
// RUN: not %clang_cc1 -fsycl-enable-int-header-diags %s 2>&1 | FileCheck --check-prefix=ERROR %s
4+
// RUN: not %clang_cc1 -fsycl-is-device -fsycl-enable-int-header-diags %s 2>&1 | FileCheck --check-prefix=ERROR %s
5+
6+
// ERROR: error: option '-fsycl-enable-int-header-diags' cannot be specified without '-fsycl-is-host'

clang/test/SemaSYCL/non-fwd-declarable-kernel-name.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -fno-sycl-unnamed-lambda -fsyntax-only -sycl-std=2020 -fsycl-int-header=%t.h %s
2-
// RUN: %clang_cc1 -fsycl-is-host -internal-isystem %S/Inputs -fno-sycl-unnamed-lambda -fsyntax-only -verify -include %t.h %s
2+
// RUN: %clang_cc1 -fsycl-is-host -DHEADER_FLAG -fsycl-enable-int-header-diags -internal-isystem %S/Inputs -fno-sycl-unnamed-lambda -fsyntax-only -verify -include %t.h %s
3+
// RUN: %clang_cc1 -fsycl-is-host -DNO_HEADER_FLAG -internal-isystem %S/Inputs -fno-sycl-unnamed-lambda -fsyntax-only -verify -include %t.h %s
34

4-
// This test verifies that incorrect kernel names are diagnosed correctly.
5+
// This test verifies that incorrect kernel names are diagnosed correctly if
6+
// integration header is included.
7+
8+
#ifdef NO_HEADER_FLAG
9+
// expected-no-diagnostics
10+
#endif // NO_HEADER_FLAG
511

612
#include "sycl.hpp"
713

@@ -29,18 +35,24 @@ int main() {
2935
});
3036

3137
class NotOk;
38+
#ifdef HEADER_FLAG
3239
// expected-error@#KernelSingleTask {{'NotOk' is invalid; kernel name should be forward declarable at namespace scope}}
33-
// expected-note@+2 {{in instantiation of function template specialization}}
40+
// expected-note@+3 {{in instantiation of function template specialization}}
41+
#endif // HEADER_FLAG
3442
q.submit([&](handler &h) {
3543
h.single_task<class NotOk>([]() { function(); });
3644
});
45+
#ifdef HEADER_FLAG
3746
// expected-error@#KernelSingleTask {{'myWrapper::insideStruct' is invalid; kernel name should be forward declarable at namespace scope}}
38-
// expected-note@+2 {{in instantiation of function template specialization}}
47+
// expected-note@+3 {{in instantiation of function template specialization}}
48+
#endif // HEADER_FLAG
3949
q.submit([&](handler &h) {
4050
h.single_task<class myWrapper::insideStruct>([]() { function(); });
4151
});
52+
#ifdef HEADER_FLAG
4253
// expected-error@#KernelSingleTask {{'RandomTemplate<NotOk>' is invalid; kernel name should be forward declarable at namespace scope}}
43-
// expected-note@+2 {{in instantiation of function template specialization}}
54+
// expected-note@+3 {{in instantiation of function template specialization}}
55+
#endif // HEADER_FLAG
4456
q.submit([&](handler &h) {
4557
h.single_task<RandomTemplate<NotOk>>([]() { function(); });
4658
});

sycl/test/warnings/sycl_2020_deprecations.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@
66
#include <CL/sycl.hpp>
77
#include <sycl/ext/intel/online_compiler.hpp>
88

9-
// This test uses SYCL host only mode without integration header, so
10-
// forward declare used kernel name class, otherwise it will be diagnosed by
11-
// the diagnostic implemented in https://github.com/intel/llvm/pull/4945.
12-
// The error happens because in host mode it is assumed that all kernel names
13-
// are forward declared at global or namespace scope because of integration
14-
// header.
15-
class Test;
16-
179
int main() {
1810
cl_context ClCtx;
1911
// expected-error@+1 {{no matching constructor for initialization of 'sycl::context'}}

0 commit comments

Comments
 (0)