llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) <details> <summary>Changes</summary> 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++`, they will most likely wonder why the expression failed (we get reports like this every once in a while...https://github.com/llvm/llvm-project/issues/152113 is a variation of this). This patch rejects languages specified with `expression --language` that we won't be able to explicitly evaluate. rdar://159669244 --- Full diff: https://github.com/llvm/llvm-project/pull/156648.diff 3 Files Affected: - (modified) lldb/source/Commands/CommandObjectExpression.cpp (+17-9) - (modified) lldb/test/API/commands/expression/calculator_mode/TestCalculatorMode.py (+1-1) - (modified) lldb/test/API/commands/expression/invalid-args/TestInvalidArgsExpression.py (+14-2) ``````````diff diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 197bffe9c982f..1b951603563ac 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -44,18 +44,26 @@ 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) { - StreamString sstr; - sstr.Printf("unknown language type: '%s' for expression. " - "List of supported languages:\n", + if (const LanguageSet supported_languages = + Language::GetLanguagesSupportingTypeSystemsForExpressions(); + supported_languages[language]) + break; + + StreamString sstr; + if (language == eLanguageTypeUnknown) + sstr.Printf("unknown language '%s' for expression. ", + option_arg.str().c_str()); + else + sstr.Printf("language '%s' is currently not supported for expression " + "evaluation. ", option_arg.str().c_str()); - Language::PrintSupportedLanguagesForExpressions(sstr, " ", "\n"); - error = Status(sstr.GetString().str()); - } - break; + sstr.PutCString("List of supported languages for expressions:\n"); + Language::PrintSupportedLanguagesForExpressions(sstr, " ", "\n"); + error = Status(sstr.GetString().str()); + } break; case 'a': { bool success; 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..f0d1542d783b1 100644 --- a/lldb/test/API/commands/expression/invalid-args/TestInvalidArgsExpression.py +++ b/lldb/test/API/commands/expression/invalid-args/TestInvalidArgsExpression.py @@ -10,8 +10,20 @@ def test_invalid_lang(self): "expression -l foo --", error=True, substrs=[ - "error: unknown language type: 'foo' for expression", - "List of supported languages:", + "error: unknown language 'foo' for expression.", + "List of supported languages for expressions:", + "c++", + "c++11", + "c++14", + ], + ) + + self.expect( + "expression -l c --", + error=True, + substrs=[ + "error: language 'c' is currently not supported for expression evaluation.", + "List of supported languages for expressions:", "c++", "c++11", "c++14", `````````` </details> https://github.com/llvm/llvm-project/pull/156648 _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
