@@ -1119,6 +1119,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11191119 const InputInfoList &Inputs) const {
11201120 const bool IsIAMCU = getToolChain ().getTriple ().isOSIAMCU ();
11211121 const bool IsIntelFPGA = Args.hasArg (options::OPT_fintelfpga);
1122+ bool SYCLDeviceCompilation = JA.isOffloading (Action::OFK_SYCL) &&
1123+ JA.isDeviceOffloading (Action::OFK_SYCL);
11221124
11231125 CheckPreprocessingOptions (D, Args);
11241126
@@ -1335,9 +1337,14 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
13351337 options::OPT_fno_pch_instantiate_templates, true ))
13361338 CmdArgs.push_back (Args.MakeArgString (" -fpch-instantiate-templates" ));
13371339 }
1340+
13381341 if (YcArg || YuArg) {
13391342 StringRef ThroughHeader = YcArg ? YcArg->getValue () : YuArg->getValue ();
1340- if (!isa<PrecompileJobAction>(JA)) {
1343+ // If PCH file is available, include it while performing
1344+ // host compilation (-fsycl-is-host) in SYCL mode (-fsycl).
1345+ // as well as in non-sycl mode.
1346+
1347+ if (!isa<PrecompileJobAction>(JA) && !SYCLDeviceCompilation) {
13411348 CmdArgs.push_back (" -include-pch" );
13421349 CmdArgs.push_back (Args.MakeArgString (D.GetClPchPath (
13431350 C, !ThroughHeader.empty ()
@@ -1356,9 +1363,12 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
13561363 }
13571364
13581365 bool RenderedImplicitInclude = false ;
1366+
13591367 for (const Arg *A : Args.filtered (options::OPT_clang_i_Group)) {
1360- if (A->getOption ().matches (options::OPT_include) &&
1361- D.getProbePrecompiled ()) {
1368+ if ((A->getOption ().matches (options::OPT_include) &&
1369+ D.getProbePrecompiled ()) ||
1370+ A->getOption ().matches (options::OPT_include_pch)) {
1371+
13621372 // Handling of gcc-style gch precompiled headers.
13631373 bool IsFirstImplicitInclude = !RenderedImplicitInclude;
13641374 RenderedImplicitInclude = true ;
@@ -1378,8 +1388,11 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
13781388 FoundPCH = true ;
13791389 }
13801390 }
1391+ // If PCH file is available, include it while performing
1392+ // host compilation (-fsycl-is-host) in SYCL mode (-fsycl).
1393+ // as well as in non-sycl mode.
13811394
1382- if (FoundPCH) {
1395+ if (FoundPCH && !SYCLDeviceCompilation ) {
13831396 if (IsFirstImplicitInclude) {
13841397 A->claim ();
13851398 CmdArgs.push_back (" -include-pch" );
@@ -1391,6 +1404,13 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
13911404 << A->getAsString (Args);
13921405 }
13931406 }
1407+ // No PCH file, but we still want to include the header file
1408+ // (-include dummy.h) in device compilation mode.
1409+ else if (JA.isDeviceOffloading (Action::OFK_SYCL) &&
1410+ A->getOption ().matches (options::OPT_include_pch)) {
1411+ continue ;
1412+ }
1413+
13941414 } else if (A->getOption ().matches (options::OPT_isystem_after)) {
13951415 // Handling of paths which must come late. These entries are handled by
13961416 // the toolchain itself after the resource dir is inserted in the right
0 commit comments