[clang] [DebugInfo] Init DwarfVersion of MCOptions like the other. (PR #146666)
Liu Ke via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 3 01:38:09 PDT 2025
https://github.com/Sockke updated https://github.com/llvm/llvm-project/pull/146666
>From 1a402b04e60ef3c74c8a3a7ecb3ef0439415d6ec Mon Sep 17 00:00:00 2001
From: Sockke <liuke.gehry at bytedance.com>
Date: Wed, 2 Jul 2025 16:54:29 +0800
Subject: [PATCH 1/3] Init DwarfVersion of MCOptions like the other.
---
clang/lib/CodeGen/BackendUtil.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 1c92ea45c7458..9cee6281a43f6 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -486,6 +486,7 @@ static bool initTargetOptions(const CompilerInstance &CI,
break;
}
+ Options.MCOptions.DwarfVersion = CodeGenOpts.DwarfVersion;
Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
Options.MCOptions.EmitCompactUnwindNonCanonical =
>From a0946b814f6f4e061c18eb364049d62a69c6f6ec Mon Sep 17 00:00:00 2001
From: Sockke <liuke.gehry at bytedance.com>
Date: Wed, 2 Jul 2025 16:54:29 +0800
Subject: [PATCH 2/3] Init DwarfVersion of MCOptions like the other.
---
clang/lib/CodeGen/BackendUtil.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 2f6d4c414e737..27c6b181a3295 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -487,6 +487,7 @@ static bool initTargetOptions(const CompilerInstance &CI,
break;
}
+ Options.MCOptions.DwarfVersion = CodeGenOpts.DwarfVersion;
Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
Options.MCOptions.EmitCompactUnwindNonCanonical =
>From 3e6b1a9c36f5a9141a9fba4618ce05bd0a790f36 Mon Sep 17 00:00:00 2001
From: Sockke <liuke.gehry at bytedance.com>
Date: Thu, 3 Jul 2025 16:06:36 +0800
Subject: [PATCH 3/3] added test
---
clang/test/CodeGen/dwarf-version.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/clang/test/CodeGen/dwarf-version.c b/clang/test/CodeGen/dwarf-version.c
index 258c258e5f5a2..bf4fedb267bb4 100644
--- a/clang/test/CodeGen/dwarf-version.c
+++ b/clang/test/CodeGen/dwarf-version.c
@@ -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
+
int main (void) {
return 0;
}
@@ -67,3 +77,11 @@ int main (void) {
// CODEVIEW: !{i32 2, !"CodeView", i32 1}
// NOCODEVIEW-NOT: !"CodeView"
// NODWARF-NOT: !"Dwarf Version"
+
+// SINGLE-4: .debug_info contents:
+// SINGLE-4: 0x00000000: Compile Unit: {{.*}} version = 0x0004, abbr_offset
+// SINGLE-4: 0x0000000b: DW_TAG_compile_unit
+
+// SINGLE-5: .debug_info contents:
+// SINGLE-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_compile, abbr_offset
+// SINGLE-5: 0x0000000c: DW_TAG_compile_unit
More information about the cfe-commits
mailing list