[llvm] 565f3f7 - [Dwarf] Don't crash in dwarf::isC() on vendor-defined languages (#223739)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 06:15:03 PDT 2026
Author: Matt Davis
Date: 2026-09-22T09:14:57-04:00
New Revision: 565f3f73eef2220bfa80a1894bab29fd6e579a2d
URL: https://github.com/llvm/llvm-project/commit/565f3f73eef2220bfa80a1894bab29fd6e579a2d
DIFF: https://github.com/llvm/llvm-project/commit/565f3f73eef2220bfa80a1894bab29fd6e579a2d.diff
LOG: [Dwarf] Don't crash in dwarf::isC() on vendor-defined languages (#223739)
isC() enumerates SourceLanguage and falls off the end of the switch into
llvm_unreachable("Unknown language kind."). DW_LANG_lo_user and
DW_LANG_hi_user are both explicit cases, but every vendor-defined code
strictly between them is not, so any of them aborts an asserts-enabled
build.
Assisted-by: LLM
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply at anthropic.com>
Added:
llvm/test/DebugInfo/X86/unknown-source-language.ll
Modified:
llvm/include/llvm/BinaryFormat/Dwarf.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index 502f42b9ddc7e..fe2c73b28ad20 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -825,7 +825,8 @@ inline bool isC(SourceLanguage S) {
case DW_LANG_Gleam:
return false;
}
- llvm_unreachable("Unknown language kind.");
+
+ return false;
}
inline TypeKind getArrayIndexTypeEncoding(SourceLanguage S) {
diff --git a/llvm/test/DebugInfo/X86/unknown-source-language.ll b/llvm/test/DebugInfo/X86/unknown-source-language.ll
new file mode 100644
index 0000000000000..aa7de1ba1caeb
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/unknown-source-language.ll
@@ -0,0 +1,46 @@
+; dwarf::isC() enumerates every named DW_LANG_* code, but a DICompileUnit may
+; name any source language, including ones no case covers: standard codes not
+; yet added to Dwarf.def, and vendor codes strictly between DW_LANG_lo_user and
+; DW_LANG_hi_user (both of which *are* named). Emitting a prototyped subprogram
+; queries isC(), which used to fall through to a trailing llvm_unreachable for
+; all of them. Check that each kind is emitted unrecognised rather than
+; crashing, and that neither is treated as C.
+
+; RUN: rm -rf %t
+; RUN: mkdir %t
+
+; 0x7fff: a standard-range code above the highest assigned one (0x0048). If it
+; is ever assigned a name in Dwarf.def, replace it with another unassigned one.
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o %t/test.o < %s
+; RUN: llvm-dwarfdump -debug-info %t/test.o | FileCheck %s -DLANG=0x7fff
+
+; 0x8003: a vendor code strictly between DW_LANG_lo_user and DW_LANG_hi_user.
+; RUN: sed -e "s/language: 32767/language: 32771/" %s > %t/test.ll
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o %t/test.o < %t/test.ll
+; RUN: llvm-dwarfdump -debug-info %t/test.o | FileCheck %s -DLANG=0x8003
+
+; CHECK: DW_TAG_compile_unit
+; CHECK: DW_AT_language ([[LANG]])
+
+; An unrecognised language is not C, so DIFlagPrototyped must not become
+; DW_AT_prototyped.
+; CHECK: DW_TAG_subprogram
+; CHECK-NOT: DW_AT_prototyped
+; CHECK: DW_AT_name ("f")
+; CHECK-NOT: DW_AT_prototyped
+; CHECK: NULL
+
+define void @f() !dbg !4 {
+ ret void
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+
+!0 = distinct !DICompileUnit(language: 32767, file: !1, emissionKind: FullDebug)
+!1 = !DIFile(filename: "a.c", directory: "/")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !{i32 2, !"Dwarf Version", i32 5}
+!4 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !5, unit: !0, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition)
+!5 = !DISubroutineType(types: !6)
+!6 = !{null}
More information about the llvm-commits
mailing list