From 8bf7080c1795229cdf3876959ea9e155c8ff1dbd Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 11 May 2026 15:31:54 +0200 Subject: [PATCH 1/4] Fix uninitialized layout in LayoutDescriptor --- Sources/ComputeCxx/Comparison/LayoutDescriptor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ComputeCxx/Comparison/LayoutDescriptor.cpp b/Sources/ComputeCxx/Comparison/LayoutDescriptor.cpp index faa2259..9e3fe73 100644 --- a/Sources/ComputeCxx/Comparison/LayoutDescriptor.cpp +++ b/Sources/ComputeCxx/Comparison/LayoutDescriptor.cpp @@ -593,7 +593,7 @@ bool compare_existential_values(const swift::existential_type_metadata &type, co } ValueLayout wrapped_layout = fetch(reinterpret_cast(type), options, 0); - ValueLayout layout = wrapped_layout == ValueLayoutTrivial ? nullptr : layout; + ValueLayout layout = wrapped_layout == ValueLayoutTrivial ? nullptr : wrapped_layout; return compare(layout, lhs_value, rhs_value, type.vw_size(), options); } From 92ac2f75847a20861b7007fb883c02915db52536 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 11 May 2026 15:32:29 +0200 Subject: [PATCH 2/4] Fix implementation of AG::swift::metadata::visit_heap_locals --- Sources/ComputeCxx/Swift/Metadata.cpp | 31 ++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/Sources/ComputeCxx/Swift/Metadata.cpp b/Sources/ComputeCxx/Swift/Metadata.cpp index 7b4389b..6b2d887 100644 --- a/Sources/ComputeCxx/Swift/Metadata.cpp +++ b/Sources/ComputeCxx/Swift/Metadata.cpp @@ -737,27 +737,34 @@ bool metadata::visit_heap_class(metadata_visitor &visitor) const { bool metadata::visit_heap_locals(metadata_visitor &visitor) const { auto local_type = reinterpret_cast(this); - if (!local_type->CaptureDescription || local_type->CaptureDescription[1] != '\0' || - local_type->OffsetToFirstCapture == 0) { + if (!local_type->CaptureDescription) { return visitor.unknown_result(); } auto descriptor = reinterpret_cast(local_type->CaptureDescription); + if (descriptor->NumMetadataSources != 0) { + return visitor.unknown_result(); + } + + size_t offset = local_type->OffsetToFirstCapture; + if (offset == 0) { + return visitor.unknown_result(); + } if (descriptor->NumBindings) { - size_t offset = local_type->OffsetToFirstCapture; + // Builtin.RawPointer, see https://github.com/swiftlang/swift/blob/main/docs/ABI/Mangling.rst + static const metadata *pointer_type = mangled_type_name_ref("Bp", true, nullptr); + if (pointer_type == nullptr) { + return visitor.unknown_result(); + } for (unsigned i = 0; i < descriptor->NumBindings; ++i) { - // Builtin.RawPointer, see https://github.com/swiftlang/swift/blob/main/docs/ABI/Mangling.rst - static const metadata *pointer_type = mangled_type_name_ref("Bp", true, nullptr); - if (pointer_type == nullptr) { - return visitor.unknown_result(); + if (!visitor.visit_element(*pointer_type, metadata::ref_kind::unmanaged, offset, vw_size())) { + return false; } - visitor.visit_element(*pointer_type, metadata::ref_kind::unmanaged, offset, vw_size()); offset += sizeof(void *); } } - size_t offset = local_type->OffsetToFirstCapture; for (auto capture_type_record = descriptor->capture_begin(), end = descriptor->capture_end(); capture_type_record != end; ++capture_type_record) { const char *mangled_name = nullptr; @@ -772,13 +779,13 @@ bool metadata::visit_heap_locals(metadata_visitor &visitor) const { size_t size = element_type->vw_size(); size_t alignment_mask = element_type->getValueWitnesses()->getAlignmentMask(); - size_t offset = (offset + alignment_mask) & ~alignment_mask; + size_t aligned_offset = (offset + alignment_mask) & ~alignment_mask; - if (!visitor.visit_element(*element_type, kind, offset, size)) { + if (!visitor.visit_element(*element_type, kind, aligned_offset, size)) { return false; } - offset += size; + offset = aligned_offset + size; } return true; From a566a756c38fb9fc9cc922d060a66d771da573e6 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 11 May 2026 15:33:01 +0200 Subject: [PATCH 3/4] Fix unused variable warnings --- Sources/ComputeCxx/Graph/Graph.cpp | 4 ---- Sources/ComputeCxx/Graph/Graph.mm | 2 -- Sources/ComputeCxx/Swift/Metadata.cpp | 1 - Sources/Platform/MachOFile.cpp | 4 ++-- Sources/Utilities/HashTable.cpp | 2 -- Sources/Utilities/include/Utilities/List.h | 1 - 6 files changed, 2 insertions(+), 12 deletions(-) diff --git a/Sources/ComputeCxx/Graph/Graph.cpp b/Sources/ComputeCxx/Graph/Graph.cpp index 6d7cf75..605c8e4 100644 --- a/Sources/ComputeCxx/Graph/Graph.cpp +++ b/Sources/ComputeCxx/Graph/Graph.cpp @@ -154,7 +154,6 @@ Graph::Context *Graph::primary_context() const { Info info = {nullptr, UINT64_MAX}; _contexts_by_id.for_each( [](const uint64_t context_id, Context *const context, void *info_ref) { - auto typed_info_ref = (std::pair *)info_ref; if (context_id < ((Info *)info_ref)->context_id) { ((Info *)info_ref)->context = context; ((Info *)info_ref)->context_id = context_id; @@ -872,7 +871,6 @@ void Graph::indirect_attribute_set(data::ptr indirect_node, Attrib OffsetAttributeID resolved_source = source.resolve(TraversalOptions::SkipMutableReference); source = resolved_source.attribute(); - uint32_t offset = resolved_source.offset(); AttributeID old_source = indirect_node->source().identifier(); if (source == old_source) { @@ -2052,8 +2050,6 @@ CFStringRef Graph::all_copy_trace_path() { } void Graph::trace_assertion_failure(bool all_stop_tracing, const char *format, ...) { - char *message = nullptr; - va_list args; va_start(args, format); diff --git a/Sources/ComputeCxx/Graph/Graph.mm b/Sources/ComputeCxx/Graph/Graph.mm index 39ec395..84bd15a 100644 --- a/Sources/ComputeCxx/Graph/Graph.mm +++ b/Sources/ComputeCxx/Graph/Graph.mm @@ -547,7 +547,6 @@ int trap_cycles() { data::ptr tree = tree_stack.top(); tree_stack.pop(); - uint64_t tree_element_index; auto found_tree_element = tree_element_indices.find(tree); if (found_tree_element != tree_element_indices.end()) { auto index = trees.size(); @@ -939,7 +938,6 @@ int trap_cycles() { int frame_count = 0; for (auto update = current_update(); update != nullptr; update = update.get()->next()) { - auto &frames = update.get()->frames(); for (auto &frame : std::ranges::reverse_view(update.get()->frames())) { [nodes addObject:[NSNumber numberWithUnsignedInt:frame.attribute.offset()]]; diff --git a/Sources/ComputeCxx/Swift/Metadata.cpp b/Sources/ComputeCxx/Swift/Metadata.cpp index 6b2d887..d5022a6 100644 --- a/Sources/ComputeCxx/Swift/Metadata.cpp +++ b/Sources/ComputeCxx/Swift/Metadata.cpp @@ -535,7 +535,6 @@ bool metadata::visit(metadata_visitor &visitor) const { } case ::swift::MetadataKind::Enum: case ::swift::MetadataKind::Optional: { - auto enum_type = reinterpret_cast(this); auto context = descriptor(); if (context && ::swift::EnumDescriptor::classof(context)) { auto enum_context = reinterpret_cast(context); diff --git a/Sources/Platform/MachOFile.cpp b/Sources/Platform/MachOFile.cpp index 942c0fa..ae6c39b 100644 --- a/Sources/Platform/MachOFile.cpp +++ b/Sources/Platform/MachOFile.cpp @@ -35,8 +35,8 @@ void MachOFile::forEachLoadCommand(/* Diagnostics& diag, */ void (^callback)(con } else if (hasMachOBigEndianMagic()) { return; // can't process big endian mach-o } else { - const uint32_t *h = (uint32_t *)this; - /* diag.error("file does not start with MH_MAGIC[_64]: 0x%08X 0x%08X", h[0], h[1]); */ + /* const uint32_t *h = (uint32_t *)this; + diag.error("file does not start with MH_MAGIC[_64]: 0x%08X 0x%08X", h[0], h[1]); */ return; // not a mach-o file } const load_command *const cmdsEnd = (load_command *)((char *)startCmds + this->sizeofcmds); diff --git a/Sources/Utilities/HashTable.cpp b/Sources/Utilities/HashTable.cpp index fafc674..4ac9389 100644 --- a/Sources/Utilities/HashTable.cpp +++ b/Sources/Utilities/HashTable.cpp @@ -189,8 +189,6 @@ bool UntypedTable::insert(key_type key, value_type value) { this->create_buckets(); } - void *result; - uint64_t hash_value = _hash(key); HashNode *node = _buckets[hash_value & _bucket_mask]; diff --git a/Sources/Utilities/include/Utilities/List.h b/Sources/Utilities/include/Utilities/List.h index 898d498..2013e39 100644 --- a/Sources/Utilities/include/Utilities/List.h +++ b/Sources/Utilities/include/Utilities/List.h @@ -131,7 +131,6 @@ template void ForwardList::pop_front() { } Node *next = _front->next; - T value = _front->value; _front->next = _spare; _spare = _front; From b8a83f011cf07b3aa4feb8b9ea3ded4dbd8ed346 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 11 May 2026 15:33:13 +0200 Subject: [PATCH 4/4] Format Swift code --- .../Shared/PrefetchCompareValuesTests.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/ComputeLayoutDescriptorTests/Shared/PrefetchCompareValuesTests.swift b/Tests/ComputeLayoutDescriptorTests/Shared/PrefetchCompareValuesTests.swift index f2c0de1..64ebc1b 100644 --- a/Tests/ComputeLayoutDescriptorTests/Shared/PrefetchCompareValuesTests.swift +++ b/Tests/ComputeLayoutDescriptorTests/Shared/PrefetchCompareValuesTests.swift @@ -173,10 +173,18 @@ struct PrefetchCompareValuesTests { let types: [Any.Type] = [Int.self, Double.self, Float.self] for type in types { - let layout0 = prefetchCompareValues(of: type, options: ComparisonOptions(mode: .bitwise), priority: 0) + let layout0 = prefetchCompareValues( + of: type, + options: ComparisonOptions(mode: .bitwise), + priority: 0 + ) #expect(layout0 == .trivial) - let layout1 = prefetchCompareValues(of: type, options: ComparisonOptions(mode: .indirect), priority: 0) + let layout1 = prefetchCompareValues( + of: type, + options: ComparisonOptions(mode: .indirect), + priority: 0 + ) #expect(layout1 == .trivial) let layout2 = prefetchCompareValues(