Skip to content

Conversation

@Michael137
Copy link
Member

The utility expressions in the InstrumentationRuntime plugins are just plain C code, but we run them as ObjC++. That meant we were doing redundant work (like looking up decls in the Objective-C runtime). The sanitizer tests sporadically time out while looking up function symbols in the Objective-C runtime. This patch switches the expression language to C.

Didn't find a great way of testing this other than looking at the expression log.

rdar://165656320

@llvmbot
Copy link
Member

llvmbot commented Dec 12, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

The utility expressions in the InstrumentationRuntime plugins are just plain C code, but we run them as ObjC++. That meant we were doing redundant work (like looking up decls in the Objective-C runtime). The sanitizer tests sporadically time out while looking up function symbols in the Objective-C runtime. This patch switches the expression language to C.

Didn't find a great way of testing this other than looking at the expression log.

rdar://165656320


Full diff: https://github.com/llvm/llvm-project/pull/172019.diff

6 Files Affected:

  • (modified) lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp (+1-1)
  • (modified) lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp (+1-1)
  • (modified) lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp (+1-1)
  • (added) lldb/test/Shell/Expr/TestASanReportExprNoObjC.test (+22)
  • (added) lldb/test/Shell/Expr/TestTSanReportExprNoObjC.test (+34)
  • (added) lldb/test/Shell/Expr/TestUBSanReportExprNoObjC.test (+24)
diff --git a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
index 498da3ffe5a4a..7db971556a2f0 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
@@ -319,7 +319,7 @@ StructuredData::ObjectSP InstrumentationRuntimeTSan::RetrieveReportData(
   options.SetTimeout(process_sp->GetUtilityExpressionTimeout());
   options.SetPrefix(thread_sanitizer_retrieve_report_data_prefix);
   options.SetAutoApplyFixIts(false);
-  options.SetLanguage(eLanguageTypeObjC_plus_plus);
+  options.SetLanguage(eLanguageTypeC);
 
   ValueObjectSP main_value;
   ExecutionContext exe_ctx;
diff --git a/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp b/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
index 565fd353a98e5..1db85e6815636 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
@@ -124,7 +124,7 @@ StructuredData::ObjectSP InstrumentationRuntimeUBSan::RetrieveReportData(
   options.SetTimeout(process_sp->GetUtilityExpressionTimeout());
   options.SetPrefix(ub_sanitizer_retrieve_report_data_prefix);
   options.SetAutoApplyFixIts(false);
-  options.SetLanguage(eLanguageTypeObjC_plus_plus);
+  options.SetLanguage(eLanguageTypeC);
 
   ValueObjectSP main_value;
   ExecutionContext exe_ctx;
diff --git a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp
index 3642cb18c7a97..85852ba40c61c 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp
@@ -81,7 +81,7 @@ ReportRetriever::RetrieveReportData(const ProcessSP process_sp) {
   options.SetTimeout(process_sp->GetUtilityExpressionTimeout());
   options.SetPrefix(address_sanitizer_retrieve_report_data_prefix);
   options.SetAutoApplyFixIts(false);
-  options.SetLanguage(eLanguageTypeObjC_plus_plus);
+  options.SetLanguage(eLanguageTypeC);
 
   if (auto [m, _] = GetPreferredAsanModule(process_sp->GetTarget()); m) {
     SymbolContextList sc_list;
diff --git a/lldb/test/Shell/Expr/TestASanReportExprNoObjC.test b/lldb/test/Shell/Expr/TestASanReportExprNoObjC.test
new file mode 100644
index 0000000000000..6d50ca264b107
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestASanReportExprNoObjC.test
@@ -0,0 +1,22 @@
+# Tests that the ASan Instrumentation Runtime's utility expression
+# runs as C (and doesn't try to find decls in the ObjC runtime).
+#
+# RUN: split-file %s %t
+# RUN: %clangxx_host -g %t/main.cpp -fsanitize=address -o %t.out
+#
+# RUN: %lldb -s %t/commands.input %t.out -o exit \
+# RUN:     | FileCheck %s --implicit-check-not="AppleObjCVendor"
+
+#--- main.cpp
+
+int main() {
+  int a[5] = {0};
+
+  return a[10];
+}
+
+#--- commands.input
+log enable lldb expr
+run
+
+# CHECK: Picked c for expression evaluation.
diff --git a/lldb/test/Shell/Expr/TestTSanReportExprNoObjC.test b/lldb/test/Shell/Expr/TestTSanReportExprNoObjC.test
new file mode 100644
index 0000000000000..fe1ea3f4f28f4
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestTSanReportExprNoObjC.test
@@ -0,0 +1,34 @@
+# Tests that the TSan Instrumentation Runtime's utility expression
+# runs as C (and doesn't try to find decls in the ObjC runtime).
+#
+# RUN: split-file %s %t
+# RUN: %clangxx_host -std=c++11 -g %t/main.cpp -fsanitize=thread -o %t.out
+#
+# RUN: %lldb -s %t/commands.input %t.out -o exit \
+# RUN:     | FileCheck %s --implicit-check-not="AppleObjCVendor"
+
+#--- main.cpp
+
+#include <thread>
+
+char c = '\0';
+
+void f() {
+  c = 'x';
+}
+
+int main() {
+    std::thread t1(f);
+    std::thread t2(f);
+
+    t1.join();
+    t2.join();
+}
+
+#--- commands.input
+log enable lldb expr
+run
+
+# CHECK: Picked c for expression evaluation.
+
+
diff --git a/lldb/test/Shell/Expr/TestUBSanReportExprNoObjC.test b/lldb/test/Shell/Expr/TestUBSanReportExprNoObjC.test
new file mode 100644
index 0000000000000..39fb9b41a5fed
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestUBSanReportExprNoObjC.test
@@ -0,0 +1,24 @@
+# Tests that the UBSan Instrumentation Runtime's utility expression
+# runs as C (and doesn't try to find decls in the ObjC runtime).
+# Tests that the UBSan Instrumentation Runtime's utility expression
+# runs as C (and doesn't try to find decls in the ObjC runtime).
+#
+# RUN: split-file %s %t
+# RUN: %clangxx_host -g %t/main.cpp -fsanitize=undefined -o %t.out
+#
+# RUN: %lldb -s %t/commands.input %t.out -o exit \
+# RUN:     | FileCheck %s --implicit-check-not="AppleObjCVendor"
+
+#--- main.cpp
+
+int main() {
+  int *p = nullptr;
+
+  return *p;
+}
+
+#--- commands.input
+log enable lldb expr
+run
+
+# CHECK: Picked c for expression evaluation.

@Michael137
Copy link
Member Author

Might need a REQUIRES on the tests that checks that sanitizers are available. Do we have one of those?

The utility expressions in the `InstrumentationRuntime` plugins are just plain C code, but we run them as `ObjC++`. That meant we were doing redundant work (like looking up decls in the Objective-C runtime). The sanitizer tests sporadically time out while looking up function symbols in the Objective-C runtime. This patch switches the expression language to `C`.

Didn't find a great way of testing this other than looking at the expression log.

rdar://165656320
@Michael137 Michael137 force-pushed the lldb/sanitizer-expression-language branch from 9e1ab2a to 764d04c Compare December 12, 2025 15:28
@github-actions
Copy link

github-actions bot commented Dec 12, 2025

🐧 Linux x64 Test Results

  • 33227 tests passed
  • 502 tests skipped

✅ The build succeeded and all tests passed.

Copy link
Collaborator

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly, I probably wouldn't even have bothered with a test for this...

@@ -0,0 +1,24 @@
# Tests that the UBSan Instrumentation Runtime's utility expression
# runs as C (and doesn't try to find decls in the ObjC runtime).
# Tests that the UBSan Instrumentation Runtime's utility expression
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: double pasted comment here.

Copy link
Contributor

@DanBlackwell DanBlackwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Michael137
Copy link
Member Author

Frankly, I probably wouldn't even have bothered with a test for this...

Yea removed the tests because we don't have Shell test infrastructure to require presence of compiler-rt (i.e., the sanitizer dylibs). Change is simple enough

@Michael137 Michael137 enabled auto-merge (squash) December 12, 2025 16:01
@Michael137 Michael137 merged commit d7cbc7f into llvm:main Dec 12, 2025
10 checks passed
Michael137 added a commit to swiftlang/llvm-project that referenced this pull request Dec 12, 2025
…llvm#172019)

The utility expressions in the `InstrumentationRuntime` plugins are just
plain C code, but we run them as `ObjC++`. That meant we were doing
redundant work (like looking up decls in the Objective-C runtime). The
sanitizer tests sporadically time out while looking up function symbols
in the Objective-C runtime. This patch switches the expression language
to `C`.

Didn't find a great way of testing this other than looking at the
expression log.

rdar://165656320
(cherry picked from commit d7cbc7f)
Michael137 added a commit to swiftlang/llvm-project that referenced this pull request Dec 12, 2025
…llvm#172019)

The utility expressions in the `InstrumentationRuntime` plugins are just
plain C code, but we run them as `ObjC++`. That meant we were doing
redundant work (like looking up decls in the Objective-C runtime). The
sanitizer tests sporadically time out while looking up function symbols
in the Objective-C runtime. This patch switches the expression language
to `C`.

Didn't find a great way of testing this other than looking at the
expression log.

rdar://165656320
(cherry picked from commit d7cbc7f)
anonymouspc pushed a commit to anonymouspc/llvm that referenced this pull request Dec 15, 2025
…llvm#172019)

The utility expressions in the `InstrumentationRuntime` plugins are just
plain C code, but we run them as `ObjC++`. That meant we were doing
redundant work (like looking up decls in the Objective-C runtime). The
sanitizer tests sporadically time out while looking up function symbols
in the Objective-C runtime. This patch switches the expression language
to `C`.

Didn't find a great way of testing this other than looking at the
expression log.

rdar://165656320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants