[Lldb-commits] [lldb] [LLDB] Update DIL handling of array subscripting. (PR #151605)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 4 02:08:15 PDT 2025
================
@@ -323,47 +323,144 @@ Interpreter::Visit(const MemberOfNode *node) {
m_expr, errMsg, node->GetLocation(), node->GetFieldName().size());
}
+
llvm::Expected<lldb::ValueObjectSP>
Interpreter::Visit(const ArraySubscriptNode *node) {
auto lhs_or_err = Evaluate(node->GetBase());
if (!lhs_or_err)
return lhs_or_err;
lldb::ValueObjectSP base = *lhs_or_err;
- // Check to see if 'base' has a synthetic value; if so, try using that.
+ StreamString var_expr_path_strm;
uint64_t child_idx = node->GetIndex();
- if (lldb::ValueObjectSP synthetic = base->GetSyntheticValue()) {
- llvm::Expected<uint32_t> num_children =
- synthetic->GetNumChildren(child_idx + 1);
- if (!num_children)
- return llvm::make_error<DILDiagnosticError>(
- m_expr, toString(num_children.takeError()), node->GetLocation());
- if (child_idx >= *num_children) {
- std::string message = llvm::formatv(
- "array index {0} is not valid for \"({1}) {2}\"", child_idx,
- base->GetTypeName().AsCString("<invalid type>"),
- base->GetName().AsCString());
- return llvm::make_error<DILDiagnosticError>(m_expr, message,
+ lldb::ValueObjectSP child_valobj_sp;
+ bool is_incomplete_array = false;
+ CompilerType base_type = base->GetCompilerType().GetNonReferenceType();
+ base->GetExpressionPath(var_expr_path_strm);
+ if (base_type.IsPointerType()) {
+ bool is_objc_pointer = true;
+ if (base->GetCompilerType().GetMinimumLanguage() != lldb::eLanguageTypeObjC)
+ is_objc_pointer = false;
+ else if (!base_type.IsPointerType())
+ is_objc_pointer = false;
+
+ if (is_objc_pointer && !m_use_synthetic) {
+ std::string errMsg =
+ llvm::formatv("\"(({0}) {1}\" is an Objective-C pointer, and cannot "
+ "be subscripted",
+ base->GetTypeName().AsCString("<invalid type>"),
+ base->GetName());
+ return llvm::make_error<DILDiagnosticError>(m_expr, errMsg,
+ node->GetLocation());
+ } else if (is_objc_pointer) {
----------------
labath wrote:
https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
(everywhere in this function)
https://github.com/llvm/llvm-project/pull/151605
More information about the lldb-commits
mailing list