Skip to content

Commit

Permalink
Merge commit 'd83ae228657c' from swift/release/6.0 into stable/20230725
Browse files Browse the repository at this point in the history
  • Loading branch information
git apple-llvm automerger committed Jul 30, 2024
2 parents a70f7a5 + d83ae22 commit a378aef
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lldb/source/Plugins/Language/Swift/SwiftArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ SwiftArrayNativeBufferHandler::SwiftArrayNativeBufferHandler(
}

bool SwiftArrayNativeBufferHandler::IsValid() {
return m_metadata_ptr != LLDB_INVALID_ADDRESS &&
return m_metadata_ptr != LLDB_INVALID_ADDRESS && m_metadata_ptr &&
m_first_elem_ptr != LLDB_INVALID_ADDRESS && m_capacity >= m_size &&
m_elem_type.IsValid();
}
Expand Down Expand Up @@ -437,10 +437,7 @@ SwiftArrayBufferHandler::CreateBufferHandler(ValueObject &static_valobj) {
handler.reset(new SwiftArrayBridgedBufferHandler(
process_sp, masked_storage_location));
}

if (handler && handler->IsValid())
return handler;
return nullptr;
return handler;
} else {
CompilerType elem_type(
valobj.GetCompilerType().GetArrayElementType(exe_scope));
Expand All @@ -457,6 +454,12 @@ bool lldb_private::formatters::swift::Array_SummaryProvider(
if (!handler)
return false;

if (!handler->IsValid()) {
// FIXME: This should be an out-of-band llvm::Error return value.
stream << "<uninitialized>";
return true;
}

auto count = handler->GetCount();

stream.Printf("%zu value%s", count, (count == 1 ? "" : "s"));
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lang/swift/array_uninitialized/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS := -parse-as-library
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftArrayUninitialized(lldbtest.TestBase):
@swiftTest
def test(self):
"""Test unitialized global arrays"""
self.build()
lldbutil.run_to_source_breakpoint(
self, 'break here', lldb.SBFileSpec('main.swift'))
self.expect("target variable -- array_unused", substrs=['<uninitialized>'])
self.expect("target variable -- array_used_empty", substrs=['0 values'])
8 changes: 8 additions & 0 deletions lldb/test/API/lang/swift/array_uninitialized/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var array_unused : [Int] = [1,2,3]
var array_used_empty : [Int] = []
@main struct Main {
static func main() {
print(array_used_empty)
print("break here")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
var tb = Test() as Array + []

print("second stop") //% self.expect('frame variable -d run -- t', substrs=['t = 0x', 'NSArray = {', 'NSObject = {'])
//% self.expect('frame variable -d run -- ta', substrs=['ta = {', '_buffer = {', '_storage =', 'rawValue = 0x'])
//% self.expect('frame variable -d run -- ta', substrs=['ta = <uninitialized>', '_buffer = {', '_storage =', 'rawValue = 0x'])
//% self.expect('frame variable -d run -- tb', substrs=['tb = 1 value {', '"abc"'])
//% self.expect('po t', substrs=['0 : abc'])
//% self.expect('po ta', substrs=['0 : abc'])
Expand Down

0 comments on commit a378aef

Please sign in to comment.