diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 475c1fddb036..00463e7dfac9 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5016,14 +5016,19 @@ class OffloadingActionBuilder final { llvm::zip(SYCLDeviceActions, SYCLTargetInfoList)) { Action *&A = std::get<0>(TargetActionInfo); auto &TargetInfo = std::get<1>(TargetActionInfo); - A = C.getDriver().ConstructPhaseAction(C, Args, CurPhase, A, - AssociatedOffloadKind); - if (SYCLDeviceOnly) + Action *PreprocAction = C.getDriver().ConstructPhaseAction( + C, Args, CurPhase, A, AssociatedOffloadKind); + if (SYCLDeviceOnly) { + A = PreprocAction; continue; + } // Add an additional compile action to generate the integration - // header. + // header. This action compiles the source file instead of the + // generated preprocessed file to allow for control of the + // diagnostics that could come from the system headers. Action *CompileAction = C.MakeAction(A, types::TY_Nothing); + A = PreprocAction; DA.add(*CompileAction, *TargetInfo.TC, TargetInfo.BoundArch, Action::OFK_SYCL); } @@ -7974,8 +7979,15 @@ Action *Driver::BuildOffloadingActions(Compilation &C, if (isa(A)) { PackagerActions.push_back(OA); A->setCannotBeCollapsedWithNextDependentAction(); - Action *CompileAction = - C.MakeAction(A, types::TY_Nothing); + // The input to the compilation job is the preprocessed job. + // Take that input action (it should be one input) which is + // the source file and compile that file to generate the + // integration header/footer. + ActionList PreprocInputs = A->getInputs(); + assert(PreprocInputs.size() == 1 && + "Single input size to preprocess action expected."); + Action *CompileAction = C.MakeAction( + PreprocInputs.front(), types::TY_Nothing); DDeps.add(*CompileAction, *TC, BoundArch, Action::OFK_SYCL); } }); diff --git a/clang/test/Driver/sycl-offload-nvptx.cpp b/clang/test/Driver/sycl-offload-nvptx.cpp index d2dcbada56de..0d69ce94dd95 100644 --- a/clang/test/Driver/sycl-offload-nvptx.cpp +++ b/clang/test/Driver/sycl-offload-nvptx.cpp @@ -106,7 +106,7 @@ // RUN: | FileCheck -check-prefix=CHK-PREPROC %s // CHK-PREPROC: 1: preprocessor, {0}, c++-cpp-output, (device-sycl, sm_[[CUDA_VERSION:[0-9.]+]]) // CHK-PREPROC: 2: offload, "device-sycl (nvptx64-nvidia-cuda:sm_[[CUDA_VERSION]])" {1}, c++-cpp-output -// CHK-PREPROC: 4: compiler, {1}, none, (device-sycl, sm_[[CUDA_VERSION]]) +// CHK-PREPROC: 4: compiler, {0}, none, (device-sycl, sm_[[CUDA_VERSION]]) // // RUN: not %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \ // RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/no/CUDA/path/here \ diff --git a/clang/test/Driver/sycl-preprocess-old-model.cpp b/clang/test/Driver/sycl-preprocess-old-model.cpp index 08c93a154d3e..efe968b7b298 100644 --- a/clang/test/Driver/sycl-preprocess-old-model.cpp +++ b/clang/test/Driver/sycl-preprocess-old-model.cpp @@ -22,7 +22,7 @@ // PREPROC_PHASES: 1: preprocessor, {0}, c++-cpp-output, (device-sycl) // PREPROC_PHASES: 2: offload, "device-sycl (spir64-unknown-unknown)" {1}, c++-cpp-output // PREPROC_PHASES: 3: input, "[[INPUT]]", c++, (host-sycl) -// PREPROC_PHASES: 4: compiler, {1}, none, (device-sycl) +// PREPROC_PHASES: 4: compiler, {0}, none, (device-sycl) // PREPROC_PHASES: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {3}, "device-sycl (spir64-unknown-unknown)" {4}, c++ // PREPROC_PHASES: 6: preprocessor, {5}, c++-cpp-output, (host-sycl) // PREPROC_PHASES: 7: clang-offload-bundler, {2, 6}, c++-cpp-output, (host-sycl) diff --git a/clang/test/Driver/sycl-preprocess.cpp b/clang/test/Driver/sycl-preprocess.cpp index 91fd801e586d..41f037e246d7 100644 --- a/clang/test/Driver/sycl-preprocess.cpp +++ b/clang/test/Driver/sycl-preprocess.cpp @@ -24,7 +24,7 @@ // PREPROC_PHASES: 1: preprocessor, {0}, c++-cpp-output, (host-sycl) // PREPROC_PHASES: 2: input, "[[INPUT]]", c++, (device-sycl) // PREPROC_PHASES: 3: preprocessor, {2}, c++-cpp-output, (device-sycl) -// PREPROC_PHASES: 4: compiler, {3}, none, (device-sycl) +// PREPROC_PHASES: 4: compiler, {2}, none, (device-sycl) // PREPROC_PHASES: 5: offload, "device-sycl (spir64-unknown-unknown)" {3}, c++-cpp-output // PREPROC_PHASES: 6: llvm-offload-binary, {5, 1}, c++-cpp-output // PREPROC_PHASES: 7: offload, "host-sycl ([[TARGET]])" {1}, "device-sycl (spir64-unknown-unknown)" {3}, "device-sycl (spir64-unknown-unknown)" {4}, " ([[TARGET]])" {6}, c++-cpp-output