https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/156648

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

>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] [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;

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to