Index: cfe/trunk/lib/Driver/Driver.cpp =================================================================== --- cfe/trunk/lib/Driver/Driver.cpp +++ cfe/trunk/lib/Driver/Driver.cpp @@ -920,12 +920,15 @@ } else AL = &A->getInputs(); - const char *Prefix = "{"; - for (Action *PreRequisite : *AL) { - os << Prefix << PrintActions1(C, PreRequisite, Ids); - Prefix = ", "; - } - os << "}"; + if (AL->size()) { + const char *Prefix = "{"; + for (Action *PreRequisite : *AL) { + os << Prefix << PrintActions1(C, PreRequisite, Ids); + Prefix = ", "; + } + os << "}"; + } else + os << "{}"; } unsigned Id = Ids.size(); @@ -1243,6 +1246,13 @@ buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args, const Arg *InputArg, std::unique_ptr HostAction, ActionList &Actions) { + Arg *PartialCompilationArg = Args.getLastArg(options::OPT_cuda_host_only, + options::OPT_cuda_device_only); + // Host-only compilation case. + if (PartialCompilationArg && + PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only)) + return std::unique_ptr( + new CudaHostAction(std::move(HostAction), {})); // Collect all cuda_gpu_arch parameters, removing duplicates. SmallVector GpuArchList; @@ -1288,7 +1298,7 @@ // Figure out what to do with device actions -- pass them as inputs to the // host action or run each of them independently. - bool DeviceOnlyCompilation = Args.hasArg(options::OPT_cuda_device_only); + bool DeviceOnlyCompilation = PartialCompilationArg != nullptr; if (PartialCompilation || DeviceOnlyCompilation) { // In case of partial or device-only compilation results of device actions // are not consumed by the host action device actions have to be added to @@ -1421,11 +1431,8 @@ continue; } - phases::ID CudaInjectionPhase; - bool InjectCuda = (InputType == types::TY_CUDA && - !Args.hasArg(options::OPT_cuda_host_only)); - CudaInjectionPhase = FinalPhase; - for (auto &Phase : PL) + phases::ID CudaInjectionPhase = FinalPhase; + for (const auto &Phase : PL) if (Phase <= FinalPhase && Phase == phases::Compile) { CudaInjectionPhase = Phase; break; @@ -1457,7 +1464,7 @@ // Otherwise construct the appropriate action. Current = ConstructPhaseAction(TC, Args, Phase, std::move(Current)); - if (InjectCuda && Phase == CudaInjectionPhase) { + if (InputType == types::TY_CUDA && Phase == CudaInjectionPhase) { Current = buildCudaActions(*this, TC, Args, InputArg, std::move(Current), Actions); if (!Current) Index: cfe/trunk/test/Driver/cuda-options.cu =================================================================== --- cfe/trunk/test/Driver/cuda-options.cu +++ cfe/trunk/test/Driver/cuda-options.cu @@ -21,7 +21,7 @@ // Then link things. // RUN: -check-prefix CUDA-L %s -// Verify that -cuda-no-device disables device-side compilation and linking +// Verify that --cuda-host-only disables device-side compilation and linking // RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only %s 2>&1 \ // Make sure we didn't run device-side compilation. // RUN: | FileCheck -check-prefix CUDA-ND \ @@ -30,13 +30,31 @@ // Linking is allowed to happen, even if we're missing GPU code. // RUN: -check-prefix CUDA-L %s -// Verify that -cuda-no-host disables host-side compilation and linking +// Same test as above, but with preceeding --cuda-device-only to make +// sure only last option has effect. +// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only --cuda-host-only %s 2>&1 \ +// Make sure we didn't run device-side compilation. +// RUN: | FileCheck -check-prefix CUDA-ND \ +// Then compile host side and make sure we don't attempt to incorporate GPU code. +// RUN: -check-prefix CUDA-H -check-prefix CUDA-H-NI \ +// Linking is allowed to happen, even if we're missing GPU code. +// RUN: -check-prefix CUDA-L %s + +// Verify that --cuda-device-only disables host-side compilation and linking // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only %s 2>&1 \ // Compile device-side to PTX assembly // RUN: | FileCheck -check-prefix CUDA-D1 -check-prefix CUDA-D1NS\ // Make sure there are no host cmpilation or linking. // RUN: -check-prefix CUDA-NH -check-prefix CUDA-NL %s +// Same test as above, but with preceeding --cuda-host-only to make +// sure only last option has effect. +// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only --cuda-device-only %s 2>&1 \ +// Compile device-side to PTX assembly +// RUN: | FileCheck -check-prefix CUDA-D1 -check-prefix CUDA-D1NS\ +// Make sure there are no host cmpilation or linking. +// RUN: -check-prefix CUDA-NH -check-prefix CUDA-NL %s + // Verify that with -S we compile host and device sides to assembly // and incorporate device code on the host side. // RUN: %clang -### -target x86_64-linux-gnu -S -c %s 2>&1 \