https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/156648
>From 5689f9e8489c66237097891e98aba93571f8583f Mon Sep 17 00:00:00 2001 From: Michael Buch <michaelbuc...@gmail.com> Date: Wed, 3 Sep 2025 12:19:17 +0100 Subject: [PATCH 1/2] [lldb][Expression] Reject languages not supported by TypeSystems for expression evaluation There are some languages for which the `ClangExpressionParser` currently switches the language type behind a user's back. Specifically, `C` gets turned into `C++` and `ObjC` into `ObjC++`. That's because the Clang expression evaluator depends on C++ features. These languages have different semantics, so if, e.g., a user forcefully wants to evaluate an expression in `C`, but we switch it to `C++`, we get reports from users confused why the expression failed. This patch rejects languages specified with `expression --language` that we won't be able to explicitly evaluate. rdar://159669244 --- lldb/source/Commands/CommandObjectExpression.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 197bffe9c982f..accc46431d927 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -44,18 +44,21 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue( const int short_option = GetDefinitions()[option_idx].short_option; switch (short_option) { - case 'l': + case 'l': { language = Language::GetLanguageTypeFromString(option_arg); - if (language == eLanguageTypeUnknown) { + + if (const LanguageSet supported_languages = + Language::GetLanguagesSupportingTypeSystemsForExpressions(); + !supported_languages[language]) { StreamString sstr; - sstr.Printf("unknown language type: '%s' for expression. " + sstr.Printf("invalid language '%s' for expression. " "List of supported languages:\n", option_arg.str().c_str()); Language::PrintSupportedLanguagesForExpressions(sstr, " ", "\n"); error = Status(sstr.GetString().str()); } - break; + } break; case 'a': { bool success; >From 74e869631658d5db48f37faca35f586ab20ef2d2 Mon Sep 17 00:00:00 2001 From: Michael Buch <michaelbuc...@gmail.com> Date: Wed, 3 Sep 2025 12:36:57 +0100 Subject: [PATCH 2/2] fixup! tests --- .../calculator_mode/TestCalculatorMode.py | 2 +- .../invalid-args/TestInvalidArgsExpression.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lldb/test/API/commands/expression/calculator_mode/TestCalculatorMode.py b/lldb/test/API/commands/expression/calculator_mode/TestCalculatorMode.py index 138027507c7a7..f12b5b0a12814 100644 --- a/lldb/test/API/commands/expression/calculator_mode/TestCalculatorMode.py +++ b/lldb/test/API/commands/expression/calculator_mode/TestCalculatorMode.py @@ -21,7 +21,7 @@ def test__calculator_mode(self): ) # Now try it with a specific language: self.expect( - "expression -l c -- 11 + 22", + "expression -l c++ -- 11 + 22", "11 + 22 didn't get the expected result", substrs=["33"], ) diff --git a/lldb/test/API/commands/expression/invalid-args/TestInvalidArgsExpression.py b/lldb/test/API/commands/expression/invalid-args/TestInvalidArgsExpression.py index 344aef318d783..ef34344627468 100644 --- a/lldb/test/API/commands/expression/invalid-args/TestInvalidArgsExpression.py +++ b/lldb/test/API/commands/expression/invalid-args/TestInvalidArgsExpression.py @@ -10,7 +10,19 @@ def test_invalid_lang(self): "expression -l foo --", error=True, substrs=[ - "error: unknown language type: 'foo' for expression", + "error: invalid language 'foo' for expression.", + "List of supported languages:", + "c++", + "c++11", + "c++14", + ], + ) + + self.expect( + "expression -l c --", + error=True, + substrs=[ + "error: invalid language 'c' for expression.", "List of supported languages:", "c++", "c++11", _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits