[clang] [llvm] [clang][DebugInfo] Emit DW_AT_language_name for DWARFv6 (PR #163208)

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 14 14:54:21 PDT 2025


================
@@ -647,6 +649,97 @@ StringRef CGDebugInfo::getCurrentDirname() {
   return CGM.getCodeGenOpts().DebugCompilationDir;
 }
 
+static llvm::dwarf::SourceLanguage GetSourceLanguage(const CodeGenModule &CGM) {
+  const CodeGenOptions &CGO = CGM.getCodeGenOpts();
+  const LangOptions &LO = CGM.getLangOpts();
+
+  assert(CGO.DwarfVersion <= 5);
+
+  llvm::dwarf::SourceLanguage LangTag;
+  if (LO.CPlusPlus) {
+    if (LO.ObjC)
+      LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
+    else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
+      LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
+    else if (LO.CPlusPlus14)
+      LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
+    else if (LO.CPlusPlus11)
+      LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
+    else
+      LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
+  } else if (LO.ObjC) {
+    LangTag = llvm::dwarf::DW_LANG_ObjC;
+  } else if (LO.OpenCL && (!CGO.DebugStrictDwarf || CGO.DwarfVersion >= 5)) {
+    LangTag = llvm::dwarf::DW_LANG_OpenCL;
+  } else if (LO.C11 && !(CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)) {
+    LangTag = llvm::dwarf::DW_LANG_C11;
+  } else if (LO.C99) {
+    LangTag = llvm::dwarf::DW_LANG_C99;
+  } else {
+    LangTag = llvm::dwarf::DW_LANG_C89;
+  }
+
+  return LangTag;
+}
+
+static std::pair<llvm::dwarf::SourceLanguageName, uint32_t>
+GetSourceLanguageName(const CodeGenModule &CGM) {
+  const CodeGenOptions &CGO = CGM.getCodeGenOpts();
+  const LangOptions &LO = CGM.getLangOpts();
+
+  assert(CGO.DwarfVersion >= 6);
+
+  uint32_t LangVersion = 0;
+  llvm::dwarf::SourceLanguageName LangTag;
+  if (LO.CPlusPlus) {
+    if (LO.ObjC) {
+      LangTag = llvm::dwarf::DW_LNAME_ObjC_plus_plus;
+    } else {
+      LangTag = llvm::dwarf::DW_LNAME_C_plus_plus;
+      if (LO.CPlusPlus26)
+        LangVersion = 202400; // No official language code yet.
+      else if (LO.CPlusPlus23)
+        LangVersion = llvm::dwarf::DW_LANG_VERSION_C_plus_plus_23;
----------------
ldionne wrote:

> But we could make them constants in some shared header?

Do you mean constants defined as macros in a shared header? For example:

```
#define _LIBCPP_CPLUSPLUS17 201703L
#define _LIBCPP_CPLUSPLUS20 202002L
// etc..
```

Or do you mean actual `static constexpr` constants? If the former, I think there's not a huge benefit from the libc++ side to do that, since we already define macros like `#if _LIBCPP_STD_VER <= 17` to do our version checks, so we don't hardcode `201703L` anywhere. We have some uses that look like they are hardcoded in `<version>`, but that header is auto-generated from a script.

If you're suggesting the latter (`static constexpr` constants), then that's a non-starter because we need the ability to compare the value in preprocessor `#if`s, and the preprocessor doesn't understand constant variables, only literals.

Please let me know if I've misunderstood your suggestion and my reply doesn't make sense.

https://github.com/llvm/llvm-project/pull/163208


More information about the cfe-commits mailing list