[clang] [DebugInfo] Init DwarfVersion of MCOptions like the other. (PR #146666)
Liu Ke via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 4 00:46:40 PDT 2025
================
@@ -51,6 +51,16 @@
// RUN: not %clang -target powerpc64-ibm-aix-xcoff -gdwarf-5 -S -emit-llvm -o - %s 2>&1| \
// RUN: FileCheck %s --check-prefix=UNSUPPORTED-VER5
+// Check what version of dwarf is used to emit debug info when compiling ir with clang.
+// RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s \
+// RUN: | %clang -target x86_64-linux-gnu -gdwarf-4 -x ir -c -o - - \
+// RUN: | llvm-dwarfdump -v - \
+// RUN: | FileCheck %s --check-prefix=SINGLE-4
+// RUN: %clang -target x86_64-linux-gnu -gdwarf-4 -S -emit-llvm -o - %s \
+// RUN: | %clang -target x86_64-linux-gnu -g -x ir -c -o - - \
+// RUN: | llvm-dwarfdump -v - \
+// RUN: | FileCheck %s --check-prefix=SINGLE-5
----------------
Sockke wrote:
> Is this actually the behavior we want? Normally, I'd expect bitcode files to already have a version specified; when clang generates LLVM IR, it generates the DWARF version as metadata. This patch explicitly overrides that version in favor of whatever is specified on the command-line when the bitcode is lowered to asm.
``` c++
DwarfDebug::DwarfDebug(AsmPrinter *A)
...
unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
unsigned DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
: MMI->getModule()->getDwarfVersion();
...
Dwarf64 &=
((Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64()) &&
TT.isOSBinFormatELF()) ||
TT.isOSBinFormatXCOFF();
```
The effective value of DwarfVersion was designed to let MCOptions override the metadata, including Dwarf64. However, unlike other options, DwarfVersion was not initialized by CodeGenOpts.
> Overriding the version won't really work right, anyway: clang generates different debug info depending on the version it's targeting.
Sorry, could you please explain in detail why it's not working properly?
https://github.com/llvm/llvm-project/pull/146666
More information about the cfe-commits
mailing list