tra updated this revision to Diff 310061.
tra added a comment.
Addressed comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92617/new/
https://reviews.llvm.org/D92617
Files:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Cuda.h
clang/test/Driver/cuda-unsupported-debug-options.cu
Index: clang/test/Driver/cuda-unsupported-debug-options.cu
===================================================================
--- clang/test/Driver/cuda-unsupported-debug-options.cu
+++ clang/test/Driver/cuda-unsupported-debug-options.cu
@@ -14,9 +14,18 @@
// 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]
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-5 -gembed-source 2>&1 | FileCheck %s --check-prefix=DWARF-CLAMP
+// 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{{.*}} target 'nvptx64-nvidia-cuda'
// 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}}
+
+// DWARF-CLAMP: warning: debug information option '-gembed-source' is not supported. It needs DWARF-5 but target 'nvptx64-nvidia-cuda' only provides DWARF-2. [-Wunsupported-target-opt]
+// DWARF-CLAMP: "-triple" "nvptx64-nvidia-cuda"
+// Make sure we clamp dwarf version on the GPU side to DWARF-2
+// DWARF-CLAMP-SAME: -dwarf-version=2
+// DWARF-CLAMP: "-triple" "x86_64
+// Make sure that DWARF version on the host didn't change and remains DWARF-5
+// DWARF-CLAMP-SAME: -dwarf-version=5
Index: clang/lib/Driver/ToolChains/Cuda.h
===================================================================
--- clang/lib/Driver/ToolChains/Cuda.h
+++ clang/lib/Driver/ToolChains/Cuda.h
@@ -185,6 +185,8 @@
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;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3836,26 +3836,33 @@
}
}
- 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.
@@ -3915,9 +3922,15 @@
// 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");
}
@@ -3946,7 +3959,7 @@
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.
Index: clang/include/clang/Driver/ToolChain.h
===================================================================
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -27,6 +27,7 @@
#include "llvm/Support/VersionTuple.h"
#include "llvm/Target/TargetOptions.h"
#include <cassert>
+#include <climits>
#include <memory>
#include <string>
#include <utility>
@@ -489,6 +490,11 @@
// 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.
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -292,6 +292,9 @@
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<
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits