Skip to content

Commit

Permalink
[SYCL][Driver] Emit an error when PCH is triggered in SYCL mode. (int…
Browse files Browse the repository at this point in the history
…el#9689)

Emit an error if PCH(Pre-Compiled Header) file generation is forced in
-fsycl mode.

---------

Co-authored-by: premanandrao <premanand.m.rao@intel.com>
  • Loading branch information
srividya-sundaram and premanandrao authored Jun 15, 2023
1 parent c9219ce commit 0624465
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
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'

0 comments on commit 0624465

Please sign in to comment.