def warn_drv_unsupported_debug_info_opt_for_target : Warning<
"debug information option '%0' is not supported for target '%1'">,
InGroup<UnsupportedTargetOpt>;
+def warn_drv_dwarf_version_limited_by_target : Warning<
+ "debug information option '%0' is not supported. It needs DWARF-%2 but target '%1' only provides DWARF-%3.">,
+ InGroup<UnsupportedTargetOpt>;
def warn_c_kext : Warning<
"ignoring -fapple-kext which is valid for C++ and Objective-C++ only">;
def warn_ignoring_fdiscard_for_bitcode : Warning<
#include "llvm/Support/VersionTuple.h"
#include "llvm/Target/TargetOptions.h"
#include <cassert>
+#include <climits>
#include <memory>
#include <string>
#include <utility>
// to the contrary.
virtual unsigned GetDefaultDwarfVersion() const { return 4; }
+ // Some toolchains may have different restrictions on the DWARF version and
+ // may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even when host
+ // compilation uses DWARF5.
+ virtual unsigned getMaxDwarfVersion() const { return UINT_MAX; }
+
// True if the driver should assume "-fstandalone-debug"
// in the absence of an option specifying otherwise,
// provided that debugging was requested in the first place.
}
}
- unsigned DWARFVersion = 0;
+ unsigned RequestedDWARFVersion = 0; // DWARF version requested by the user
+ unsigned EffectiveDWARFVersion = 0; // DWARF version TC can generate. It may
+ // be lower than what the user wanted.
unsigned DefaultDWARFVersion = ParseDebugDefaultVersion(TC, Args);
if (EmitDwarf) {
// Start with the platform default DWARF version
- DWARFVersion = TC.GetDefaultDwarfVersion();
- assert(DWARFVersion && "toolchain default DWARF version must be nonzero");
+ RequestedDWARFVersion = TC.GetDefaultDwarfVersion();
+ assert(RequestedDWARFVersion &&
+ "toolchain default DWARF version must be nonzero");
// If the user specified a default DWARF version, that takes precedence
// over the platform default.
if (DefaultDWARFVersion)
- DWARFVersion = DefaultDWARFVersion;
+ RequestedDWARFVersion = DefaultDWARFVersion;
// Override with a user-specified DWARF version
if (GDwarfN)
if (auto ExplicitVersion = DwarfVersionNum(GDwarfN->getSpelling()))
- DWARFVersion = ExplicitVersion;
+ RequestedDWARFVersion = ExplicitVersion;
+ // Clamp effective DWARF version to the max supported by the toolchain.
+ EffectiveDWARFVersion =
+ std::min(RequestedDWARFVersion, TC.getMaxDwarfVersion());
}
// -gline-directives-only supported only for the DWARF debug info.
- if (DWARFVersion == 0 && DebugInfoKind == codegenoptions::DebugDirectivesOnly)
+ if (RequestedDWARFVersion == 0 &&
+ DebugInfoKind == codegenoptions::DebugDirectivesOnly)
DebugInfoKind = codegenoptions::NoDebugInfo;
// We ignore flag -gstrict-dwarf for now.
// fallen back to the target default, so if this is still not at least 5
// we emit an error.
const Arg *A = Args.getLastArg(options::OPT_gembed_source);
- if (DWARFVersion < 5)
+ if (RequestedDWARFVersion < 5)
D.Diag(diag::err_drv_argument_only_allowed_with)
<< A->getAsString(Args) << "-gdwarf-5";
+ else if (EffectiveDWARFVersion < 5)
+ // The toolchain has reduced allowed dwarf version, so we can't enable
+ // -gembed-source.
+ D.Diag(diag::warn_drv_dwarf_version_limited_by_target)
+ << A->getAsString(Args) << TC.getTripleString() << 5
+ << EffectiveDWARFVersion;
else if (checkDebugInfoOption(A, Args, D, TC))
CmdArgs.push_back("-gembed-source");
}
DebugInfoKind <= codegenoptions::DebugDirectivesOnly)
DebugInfoKind = codegenoptions::DebugLineTablesOnly;
- RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DWARFVersion,
+ RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, EffectiveDWARFVersion,
DebuggerTuning);
// -fdebug-macro turns on macro debug info generation.
const llvm::opt::ArgList &Args) const override;
unsigned GetDefaultDwarfVersion() const override { return 2; }
+ // NVPTX supports only DWARF2.
+ unsigned getMaxDwarfVersion() const override { return 2; }
const ToolChain &HostTC;
CudaInstallationDetector CudaInstallation;
--- /dev/null
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+// REQUIRES: zlib
+
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -g -gz 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf -fdebug-info-for-profiling 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-2 -gsplit-dwarf 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-3 -glldb 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-4 -gcodeview 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-5 -gmodules 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -ggdb1 -fdebug-macro 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -ggdb2 -ggnu-pubnames 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -ggdb3 -gdwarf-aranges 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -g -gcolumn-info -fdebug-types-section 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN,COMMON
+
+// Same tests for OpenMP
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -g -gz 2>&1 | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -gdwarf -fdebug-info-for-profiling 2>&1 | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -gdwarf-2 -gsplit-dwarf 2>&1 | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -gdwarf-3 -glldb 2>&1 | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -gdwarf-4 -gcodeview 2>&1 | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -gdwarf-5 -gmodules 2>&1 | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -ggdb1 -fdebug-macro 2>&1 | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -ggdb2 -ggnu-pubnames 2>&1 | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -ggdb3 -gdwarf-aranges 2>&1 | FileCheck %s --check-prefixes WARN,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -g -gcolumn-info -fdebug-types-section 2>&1 | FileCheck %s --check-prefixes WARN,COMMON
+
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-5 -gembed-source 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN-GES,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -ggdb -gembed-source -gdwarf-5 2>&1 \
+// RUN: | FileCheck %s --check-prefixes WARN-GES,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -gdwarf-5 -gembed-source 2>&1 | FileCheck %s --check-prefixes WARN-GES,COMMON
+// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: -ggdb -gembed-source -gdwarf-5 2>&1 | FileCheck %s --check-prefixes WARN-GES,COMMON
+
+// COMMON: warning: debug information option '{{-gz|-fdebug-info-for-profiling|-gsplit-dwarf|-glldb|-gcodeview|-gmodules|-gembed-source|-fdebug-macro|-ggnu-pubnames|-gdwarf-aranges|-fdebug-types-section}}' is not supported
+// WARN-SAME: for target 'nvptx64-nvidia-cuda' [-Wunsupported-target-opt]
+// WARN-GES-SAME: It needs DWARF-5 but target 'nvptx64-nvidia-cuda' only provides DWARF-2. [-Wunsupported-target-opt]
+// COMMON-NOT: debug information option '{{.*}}' is not supported for target 'x86
+// COMMON: "-triple" "nvptx64-nvidia-cuda"
+// COMMON-NOT: {{-compress-debug|-fdebug-info-for-profiling|lldb|codeview|module-format|embed-source|debug-info-macro|gnu-pubnames|generate-arange-section|generate-type-units}}
+// COMMON: "-triple" "x86_64
+// COMMON-SAME: {{-compress-debug|-fdebug-info-for-profiling|split-dwarf|lldb|codeview|module-format|embed-source|debug-info-macro|gnu-pubnames|generate-arange-section|generate-type-units}}
+++ /dev/null
-// REQUIRES: clang-driver
-// REQUIRES: x86-registered-target
-// REQUIRES: nvptx-registered-target
-// REQUIRES: zlib
-
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -g -gz 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf -fdebug-info-for-profiling 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-2 -gsplit-dwarf 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-3 -glldb 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-4 -gcodeview 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-5 -gmodules 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -ggdb -gembed-source -gdwarf-5 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -ggdb1 -fdebug-macro 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -ggdb2 -ggnu-pubnames 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -ggdb3 -gdwarf-aranges 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -c %s -g -gcolumn-info -fdebug-types-section 2>&1 | FileCheck %s
-// CHECK: debug information option '{{-gz|-fdebug-info-for-profiling|-gsplit-dwarf|-glldb|-gcodeview|-gmodules|-gembed-source|-fdebug-macro|-ggnu-pubnames|-gdwarf-aranges|-fdebug-types-section}}' is not supported for target 'nvptx64-nvidia-cuda' [-Wunsupported-target-opt]
-// CHECK-NOT: debug information option '{{.*}}' is not supported for target 'x86
-// CHECK: "-triple" "nvptx64-nvidia-cuda"
-// CHECK-NOT: {{-compress-debug|-fdebug-info-for-profiling|lldb|codeview|module-format|embed-source|debug-info-macro|gnu-pubnames|generate-arange-section|generate-type-units}}
-// CHECK: "-triple" "x86_64
-// CHECK-SAME: {{-compress-debug|-fdebug-info-for-profiling|split-dwarf|lldb|codeview|module-format|embed-source|debug-info-macro|gnu-pubnames|generate-arange-section|generate-type-units}}
--- /dev/null
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+
+// Verify that DWARF version is properly clamped for nvptx, but not for the host.
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-5 -gembed-source 2>&1 \
+// RUN: | FileCheck %s --check-prefix=DWARF-CLAMP
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -ggdb -gembed-source -gdwarf-5 2>&1 \
+// RUN: | FileCheck %s --check-prefix=DWARF-CLAMP
+
+// DWARF-CLAMP: "-triple" "nvptx64-nvidia-cuda"
+// DWARF-CLAMP-SAME: -dwarf-version=2
+// DWARF-CLAMP: "-triple" "x86_64
+// DWARF-CLAMP-SAME: -dwarf-version=5
+++ /dev/null
-// REQUIRES: clang-driver
-// REQUIRES: x86-registered-target
-// REQUIRES: nvptx-registered-target
-// REQUIRES: zlib
-
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -g -gz 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -gdwarf -fdebug-info-for-profiling 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -gdwarf-2 -gsplit-dwarf 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -gdwarf-3 -glldb 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -gdwarf-4 -gcodeview 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -gdwarf-5 -gmodules 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -ggdb -gembed-source -gdwarf-5 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -ggdb1 -fdebug-macro 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -ggdb2 -ggnu-pubnames 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -ggdb3 -gdwarf-aranges 2>&1 | FileCheck %s
-// RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -c %s -g -gcolumn-info -fdebug-types-section 2>&1 | FileCheck %s
-// CHECK: debug information option '{{-gz|-fdebug-info-for-profiling|-gsplit-dwarf|-glldb|-gcodeview|-gmodules|-gembed-source|-fdebug-macro|-ggnu-pubnames|-gdwarf-aranges|-fdebug-types-section}}' is not supported for target 'nvptx64-nvidia-cuda' [-Wunsupported-target-opt]
-// CHECK-NOT: debug information option '{{.*}}' is not supported for target 'x86
-// CHECK: "-triple" "nvptx64-nvidia-cuda"
-// CHECK-NOT: {{-compress-debug|-fdebug-info-for-profiling|lldb|codeview|module-format|embed-source|debug-info-macro|gnu-pubnames|generate-arange-section|generate-type-units}}
-// CHECK: "-triple" "x86_64
-// CHECK-SAME: {{-compress-debug|-fdebug-info-for-profiling|split-dwarf|lldb|codeview|module-format|embed-source|debug-info-macro|gnu-pubnames|generate-arange-section|generate-type-units}}