diff --git a/lib/IRGen/GenType.cpp b/lib/IRGen/GenType.cpp index 3067a18fcf9f0..5382b6326a2f2 100644 --- a/lib/IRGen/GenType.cpp +++ b/lib/IRGen/GenType.cpp @@ -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); diff --git a/stdlib/public/runtime/Heap.cpp b/stdlib/public/runtime/Heap.cpp index 5480c02107c36..ceab57f9f2b6d 100644 --- a/stdlib/public/runtime/Heap.cpp +++ b/stdlib/public/runtime/Heap.cpp @@ -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; } diff --git a/test/IRGen/generic_structs.swift b/test/IRGen/generic_structs.swift new file mode 100644 index 0000000000000..97b4ededf2c40 --- /dev/null +++ b/test/IRGen/generic_structs.swift @@ -0,0 +1,26 @@ +// RUN: %target-swift-frontend -primary-file %s -emit-ir | FileCheck %s + +struct A +{ + var b: T1 + var c: T2 + var d: B +} +struct B +{ + var c: T1 + var d: T2 +} + +struct C +{} +struct D +{} + +struct Foo +{ + var b: Bar +} + +struct Bar { +} \ No newline at end of file