Index: lib/Driver/ToolChains/Cuda.cpp =================================================================== --- lib/Driver/ToolChains/Cuda.cpp +++ lib/Driver/ToolChains/Cuda.cpp @@ -283,23 +283,26 @@ } // anonymous namespace static DebugInfoKind mustEmitDebugInfo(const ArgList &Args) { - Arg *A = Args.getLastArg(options::OPT_O_Group); - if (Args.hasFlag(options::OPT_cuda_noopt_device_debug, - options::OPT_no_cuda_noopt_device_debug, - !A || A->getOption().matches(options::OPT_O0))) { - if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) { - const Option &Opt = A->getOption(); - if (Opt.matches(options::OPT_gN_Group)) { - if (Opt.matches(options::OPT_g0) || Opt.matches(options::OPT_ggdb0)) - return NoDebug; - if (Opt.matches(options::OPT_gline_tables_only) || - Opt.matches(options::OPT_ggdb1)) - return LineTableOnly; - } - return FullDebug; + const Arg *OptArg = Args.getLastArg(options::OPT_O_Group); + DebugInfoKind DIKind = NoDebug; + if (const Arg *DebugArg = Args.getLastArg(options::OPT_g_Group)) { + DIKind = FullDebug; + const Option &Opt = DebugArg->getOption(); + if (Opt.matches(options::OPT_gN_Group)) { + if (Opt.matches(options::OPT_g0) || Opt.matches(options::OPT_ggdb0)) + DIKind = NoDebug; + else if (Opt.matches(options::OPT_gline_tables_only) || + Opt.matches(options::OPT_ggdb1)) + DIKind = LineTableOnly; } } - return NoDebug; + if (Args.hasFlag(options::OPT_cuda_noopt_device_debug, + options::OPT_no_cuda_noopt_device_debug, + !OptArg || OptArg->getOption().matches(options::OPT_O0))) + return DIKind; + // If --no-cuda-noopt-device-debug is provided and O>0 and debug info + // requested - generate lineinfo. + return DIKind == NoDebug ? NoDebug : LineTableOnly; } void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA, @@ -634,6 +637,13 @@ CC1Args.push_back("+ptx42"); } + // Disable emission of the `debug` option in the `.target` if the lineinfo is + // requested. + if (mustEmitDebugInfo(DriverArgs) == LineTableOnly) { + CC1Args.push_back("-mllvm"); + CC1Args.push_back("-no-cuda-debug"); + } + if (DeviceOffloadingKind == Action::OFK_OpenMP) { SmallVector LibraryPaths; // Add path to lib and/or lib64 folders. Index: test/Driver/cuda-dwarf-2.cu =================================================================== --- test/Driver/cuda-dwarf-2.cu +++ test/Driver/cuda-dwarf-2.cu @@ -15,6 +15,8 @@ // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -gline-tables-only -O2 --cuda-noopt-device-debug 2>&1 | \ // RUN: FileCheck %s -check-prefix NO_DEBUG -check-prefix LINE_TABLE +// LINE_TABLE: "-triple" "nvptx64-nvidia-cuda" +// LINE_TABLE-SAME: "-mllvm" "-no-cuda-debug" // NO_DEBUG: ptxas // NO_DEBUG-NOT: "-g" // LINE_TABLE: "-lineinfo" Index: test/Driver/openmp-offload-gpu.c =================================================================== --- test/Driver/openmp-offload-gpu.c +++ test/Driver/openmp-offload-gpu.c @@ -182,6 +182,8 @@ // RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb1 -O2 --cuda-noopt-device-debug 2>&1 \ // RUN: | FileCheck -check-prefix=NO_DEBUG -check-prefix=LINE_TABLE %s +// LINE_TABLE: "-triple" "nvptx64-nvidia-cuda" +// LINE_TABLE-SAME: "-mllvm" "-no-cuda-debug" // NO_DEBUG: ptxas // LINE_TABLE: "-lineinfo" // NO_DEBUG-NOT: "-g"