Skip to content

[lldb][ObjC] Don't query objective-c runtime for decls in C++ contexts #95963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ void ClangASTSource::FindExternalVisibleDecls(
FindDeclInModules(context, name);
}

if (!context.m_found_type) {
if (!context.m_found_type && m_ast_context->getLangOpts().ObjC) {
FindDeclInObjCRuntime(context, name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ def test(self):
(_, process, _, _) = lldbutil.run_to_name_breakpoint(self, "main")

self.assertState(process.GetState(), lldb.eStateStopped)

# Tests that we can use builtin Objective-C identifiers.
self.expect("expr id", error=False)

# Tests that we can lookup Objective-C decls in the ObjC runtime plugin.
self.expect_expr(
"NSString *c; c == nullptr", result_value="true", result_type="bool"
)
21 changes: 21 additions & 0 deletions lldb/test/Shell/Expr/TestObjCInCXXContext.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// UNSUPPORTED: system-linux, system-windows

// Tests that we don't consult the the Objective-C runtime
// plugin when in a purely C++ context.
//
// RUN: %clangxx_host %p/Inputs/objc-cast.cpp -g -o %t
// RUN: %lldb %t \
// RUN: -o "b main" -o run \
// RUN: -o "expression --language objective-c -- NSString * a; a" \
// RUN: -o "expression --language objective-c++ -- NSString * b; b" \
// RUN: -o "expression NSString" \
// RUN: 2>&1 | FileCheck %s

// CHECK: (lldb) expression --language objective-c -- NSString * a; a
// CHECK-NEXT: (NSString *){{.*}}= nil

// CHECK: (lldb) expression --language objective-c++ -- NSString * b; b
// CHECK-NEXT: (NSString *){{.*}}= nil

// CHECK: (lldb) expression NSString
// CHECK-NEXT: error:{{.*}} use of undeclared identifier 'NSString'
Loading