[Lldb-commits] [lldb] [lldb] Fix off-by-one error in ToDwarfSourceLanguage (PR #162315)

Joshua Peterson via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 7 09:17:42 PDT 2025


https://github.com/joshpeterson created https://github.com/llvm/llvm-project/pull/162315

The ToDwarfSourceLanguage function incorrectly excluded languages that equal eLanguageTypeLastStandardLanguage. The comparison used `<` instead of `<=`, causing the last standard language to fall through to the default case and return std::nullopt.

This broke language plugins that use eLanguageTypeLastStandardLanguage (currently Mojo at 0x0033) as their language code, preventing proper DWARF language conversion and breaking REPL functionality.

The fix changes the comparison from `<` to `<=` to include the last standard language in the automatic conversion to DWARF source language.

This is a regression from commit 7f51a2a47d2e706d04855b0e41690ebafa2b3238 which introduced the ToDwarfSourceLanguage function.

>From 691252c01bf7c82e4fb54783a4af40f5ecc56d6c Mon Sep 17 00:00:00 2001
From: Josh Peterson <josh at modular.com>
Date: Tue, 7 Oct 2025 12:14:45 -0400
Subject: [PATCH] [lldb] Fix off-by-one error in ToDwarfSourceLanguage

The ToDwarfSourceLanguage function incorrectly excluded languages
that equal eLanguageTypeLastStandardLanguage. The comparison used
`<` instead of `<=`, causing the last standard language to fall
through to the default case and return std::nullopt.

This broke language plugins that use eLanguageTypeLastStandardLanguage
(currently Mojo at 0x0033) as their language code, preventing proper
DWARF language conversion and breaking REPL functionality.

The fix changes the comparison from `<` to `<=` to include the last
standard language in the automatic conversion to DWARF source language.

This is a regression from commit 7f51a2a47d2e706d04855b0e41690ebafa2b3238
which introduced the ToDwarfSourceLanguage function.
---
 lldb/source/Target/Language.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Target/Language.cpp b/lldb/source/Target/Language.cpp
index 395718ecbe292..2efd4bc1e2c09 100644
--- a/lldb/source/Target/Language.cpp
+++ b/lldb/source/Target/Language.cpp
@@ -549,7 +549,7 @@ Language::~Language() = default;
 
 static std::optional<llvm::dwarf::SourceLanguage>
 ToDwarfSourceLanguage(lldb::LanguageType language_type) {
-  if (language_type < lldb::eLanguageTypeLastStandardLanguage)
+  if (language_type <= lldb::eLanguageTypeLastStandardLanguage)
     return static_cast<llvm::dwarf::SourceLanguage>(language_type);
 
   switch (language_type) {



More information about the lldb-commits mailing list