[Lldb-commits] [lldb] [lldb] Fix off-by-one error in ToDwarfSourceLanguage (PR #162315)
Joshua Peterson via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 8 04:11:00 PDT 2025
https://github.com/joshpeterson updated https://github.com/llvm/llvm-project/pull/162315
>From 248f4edc8bf264f944300846b2122a05129960d1 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 1/3] [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) {
>From 3254a97a7351ff7f753414283476fe72dbc60155 Mon Sep 17 00:00:00 2001
From: Josh Peterson <josh at modular.com>
Date: Tue, 7 Oct 2025 14:51:54 -0400
Subject: [PATCH 2/3] Add a test for the last language type
---
lldb/unittests/Target/LanguageTest.cpp | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/lldb/unittests/Target/LanguageTest.cpp b/lldb/unittests/Target/LanguageTest.cpp
index a00fda78d569a..d3302dcf63d33 100644
--- a/lldb/unittests/Target/LanguageTest.cpp
+++ b/lldb/unittests/Target/LanguageTest.cpp
@@ -67,3 +67,16 @@ TEST_F(LanguageTest, SourceLanguage_AsLanguageType) {
EXPECT_EQ(SourceLanguage(eLanguageTypeUnknown).AsLanguageType(),
eLanguageTypeUnknown);
}
+
+TEST_F(LanguageTest, SourceLanguage_LastStandardLanguage) {
+ // eLanguageTypeLastStandardLanguage should be treated as a standard DWARF
+ // language.
+ SourceLanguage lang(eLanguageTypeLastStandardLanguage);
+ EXPECT_TRUE(lang);
+
+ // It should have a valid description (not "Unknown").
+ EXPECT_NE(lang.GetDescription(), "Unknown");
+
+ // It should convert to the correct language type.
+ EXPECT_EQ(lang.AsLanguageType(), eLanguageTypeLastStandardLanguage);
+}
>From 790b947c51e4ecd6574780cd4d84a7c7a7b61c61 Mon Sep 17 00:00:00 2001
From: Josh Peterson <josh at modular.com>
Date: Wed, 8 Oct 2025 07:09:16 -0400
Subject: [PATCH 3/3] Allow the test to use the last language type
---
lldb/unittests/Target/LanguageTest.cpp | 3 ---
1 file changed, 3 deletions(-)
diff --git a/lldb/unittests/Target/LanguageTest.cpp b/lldb/unittests/Target/LanguageTest.cpp
index d3302dcf63d33..a1f9267dd45d0 100644
--- a/lldb/unittests/Target/LanguageTest.cpp
+++ b/lldb/unittests/Target/LanguageTest.cpp
@@ -24,9 +24,6 @@ TEST_F(LanguageTest, SourceLanguage_GetDescription) {
continue;
auto lang_type = static_cast<lldb::LanguageType>(i);
- if (lang_type == lldb::eLanguageTypeLastStandardLanguage)
- continue;
-
SourceLanguage lang(lang_type);
// eLanguageTypeHIP is not implemented as a DW_LNAME because of a conflict.
More information about the lldb-commits
mailing list