Skip to content

[SYCL][Driver] Emit an error when PCH is triggered in SYCL mode. #9689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 15, 2023
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ def err_drv_expecting_fsycl_with_sycl_opt : Error<
"'%0' must be used in conjunction with '-fsycl' to enable offloading">;
def err_drv_fsycl_with_c_type : Error<
"'%0' must not be used in conjunction with '-fsycl', which expects C++ source">;
def err_drv_fsycl_with_pch : Error<
"Precompiled header generation is not supported with '-fsycl'">;
def err_drv_fsycl_unsupported_with_opt
: Error<"'%0' is not supported with '-fsycl'">;
def err_drv_sycl_missing_amdgpu_arch : Error<
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9252,6 +9252,11 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
}
}

// Emit an error if PCH(Pre-Compiled Header) file generation is forced in
// -fsycl mode.
if (C.getArgs().hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) &&
JA.getType() == types::TY_PCH)
Diag(clang::diag::err_drv_fsycl_with_pch);
// As an annoying special case, PCH generation doesn't strip the pathname.
if (JA.getType() == types::TY_PCH && !IsCLMode()) {
llvm::sys::path::remove_filename(BasePath);
Expand Down
19 changes: 19 additions & 0 deletions clang/test/Driver/pch-fsycl-error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This test checks that an error is emitted when
// PCH(Precompiled Header) file generation is forced in -fsycl mode.

// RUN: touch %t.h

// Linux
// RUN: %clang -c -fsycl -x c++-header %t.h -### %s 2> %t1.txt
// RUN: FileCheck %s -input-file=%t1.txt
// CHECK: Precompiled header generation is not supported with '-fsycl'

// Windows
// RUN: %clang_cl -c -fsycl -x c++-header %t.h -### -- %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-ERROR %s
// CHECK-ERROR: Precompiled header generation is not supported with '-fsycl'

// /Yc
// RUN: %clang_cl -fsycl /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-YC %s
// CHECK-YC: Precompiled header generation is not supported with '-fsycl'