Skip to content

Fixes Heap Allocations for Large alignMask #238

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

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 4 additions & 0 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,10 @@ SILType irgen::getSingletonAggregateFieldType(IRGenModule &IGM,
// If there's only one stored property, we have the layout of its field.
auto allFields = structDecl->getStoredProperties();
auto field = allFields.begin();
// If there are no other fields exit early to prevent calling std::next on
// an invalid iterator.
if (field == allFields.end())
return SILType();
if (std::next(field) == allFields.end())
return t.getFieldType(*field, *IGM.SILMod);

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/runtime/Heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
using namespace swift;

void *swift::swift_slowAlloc(size_t size, size_t alignMask) {
void *p;
// FIXME: use posix_memalign if alignMask is larger than the system guarantee.
void *p = malloc(size);
if (!p) swift::crash("Could not allocate memory.");
return p;
}

Expand Down
26 changes: 26 additions & 0 deletions test/IRGen/generic_structs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir | FileCheck %s

struct A<T1, T2>
{
var b: T1
var c: T2
var d: B<T1, T2>
}
struct B<T1, T2>
{
var c: T1
var d: T2
}

struct C<T1>
{}
struct D<T2>
{}

struct Foo<A1, A2>
{
var b: Bar<A1, A2>
}

struct Bar {
}