diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4432,6 +4432,11 @@ types::ID InputType = Input.first; const Arg *InputArg = Input.second; + // The toolchain can be active for unsupported file types. + if ((Kind == Action::OFK_Cuda && !types::isCuda(InputType)) || + (Kind == Action::OFK_HIP && !types::isHIP(InputType))) + continue; + // Get the product of all bound architectures and toolchains. SmallVector> TCAndArchs; for (const ToolChain *TC : ToolChains) @@ -4486,6 +4491,9 @@ if (offloadDeviceOnly()) return C.MakeAction(DDeps, types::TY_Nothing); + if (OffloadActions.empty()) + return HostAction; + OffloadAction::DeviceDependences DDep; if (C.isOffloadingHostKind(Action::OFK_Cuda) && !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false)) { diff --git a/clang/test/Driver/cuda-phases.cu b/clang/test/Driver/cuda-phases.cu --- a/clang/test/Driver/cuda-phases.cu +++ b/clang/test/Driver/cuda-phases.cu @@ -266,3 +266,32 @@ // NEW-DRIVER: 17: backend, {16}, assembler, (host-cuda) // NEW-DRIVER: 18: assembler, {17}, object, (host-cuda) // NEW-DRIVER: 19: clang-linker-wrapper, {18}, image, (host-cuda) + +// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver \ +// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s %S/Inputs/empty.cpp 2>&1 | FileCheck --check-prefix=NON-CUDA-INPUT %s +// NON-CUDA-INPUT: 0: input, "[[CUDA:.+]]", cuda, (host-cuda) +// NON-CUDA-INPUT: 1: preprocessor, {0}, cuda-cpp-output, (host-cuda) +// NON-CUDA-INPUT: 2: compiler, {1}, ir, (host-cuda) +// NON-CUDA-INPUT: 3: input, "[[CUDA]]", cuda, (device-cuda, sm_52) +// NON-CUDA-INPUT: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52) +// NON-CUDA-INPUT: 5: compiler, {4}, ir, (device-cuda, sm_52) +// NON-CUDA-INPUT: 6: backend, {5}, assembler, (device-cuda, sm_52) +// NON-CUDA-INPUT: 7: assembler, {6}, object, (device-cuda, sm_52) +// NON-CUDA-INPUT: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object +// NON-CUDA-INPUT: 9: input, "[[CUDA]]", cuda, (device-cuda, sm_70) +// NON-CUDA-INPUT: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70) +// NON-CUDA-INPUT: 11: compiler, {10}, ir, (device-cuda, sm_70) +// NON-CUDA-INPUT: 12: backend, {11}, assembler, (device-cuda, sm_70) +// NON-CUDA-INPUT: 13: assembler, {12}, object, (device-cuda, sm_70) +// NON-CUDA-INPUT: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object +// NON-CUDA-INPUT: 15: linker, {8, 14}, cuda-fatbin, (device-cuda) +// NON-CUDA-INPUT: 16: offload, "host-cuda (powerpc64le-ibm-linux-gnu)" {2}, "device-cuda (nvptx64-nvidia-cuda)" {15}, ir +// NON-CUDA-INPUT: 17: backend, {16}, assembler, (host-cuda) +// NON-CUDA-INPUT: 18: assembler, {17}, object, (host-cuda) +// NON-CUDA-INPUT: 19: input, "[[CPP:.+]]", c++, (host-cuda) +// NON-CUDA-INPUT: 20: preprocessor, {19}, c++-cpp-output, (host-cuda) +// NON-CUDA-INPUT: 21: compiler, {20}, ir, (host-cuda) +// NON-CUDA-INPUT: 22: backend, {21}, assembler, (host-cuda) +// NON-CUDA-INPUT: 23: assembler, {22}, object, (host-cuda) +// NON-CUDA-INPUT: 24: clang-linker-wrapper, {18, 23}, image, (host-cuda) +