Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -4676,8 +4676,10 @@ DAL->append(A); } - if (BoundArch) + if (BoundArch) { + DAL->eraseArg(options::OPT_march_EQ); DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); + } return DAL; } Index: test/Driver/cuda-march.cu =================================================================== --- /dev/null +++ test/Driver/cuda-march.cu @@ -0,0 +1,31 @@ +// Checks that cuda compilation does the right thing when passed -march. +// (Specifically, we want to pass it to host compilation, but not to device +// compilation or ptxas!) +// +// REQUIRES: clang-driver +// REQUIRES: x86-registered-target +// REQUIRES: nvptx-registered-target + +// RUN: %clang -### -target x86_64-linux-gnu -c -march=haswell %s 2>&1 | \ +// RUN: FileCheck -check-prefix HASWELL -check-prefix SM20 %s + +// RUN: %clang -### -target x86_64-linux-gnu -c -march=haswell --cuda-gpu-arch=sm_20 %s 2>&1 | \ +// RUN: FileCheck -check-prefix HASWELL -check-prefix SM20 %s + +// SM20:clang +// SM20: "-cc1" +// SM20-SAME: "-triple" "nvptx +// SM20-SAME: "-target-cpu" "sm_20" +// SM20: ptxas +// SM20-SAME: "--gpu-name" "sm_20" + +// SM30:clang +// SM30: "-cc1" +// SM30-SAME: "-triple" "nvptx +// SM30-SAME: "-target-cpu" "sm_30" +// SM30: ptxas +// SM30-SAME: "--gpu-name" "sm_30" + +// HASWELL:clang +// HASWELL-SAME: "-cc1" +// HASWELL-SAME: "-target-cpu" "haswell"