Skip to content

Commit a8b0ee2

Browse files
committed
runtime: blanket application of namespacing and inclusion of new
Apply a blanket pass of including `new` for the placement new allocation and namespacing the call to the global placement new allocator. This should repair the Android ARMv7 builds.
1 parent 57f0e67 commit a8b0ee2

18 files changed

+44
-27
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "swift/Runtime/Concurrency.h"
1919
#include <atomic>
20+
#include <new>
2021

2122
#ifdef _WIN32
2223
// On Windows, an include below triggers an indirect include of minwindef.h
@@ -1217,7 +1218,7 @@ void DefaultActorImpl::scheduleActorProcessJob(JobPriority priority, bool useInl
12171218
if (useInlineJob) {
12181219
if (JobStorageHeapObject.metadata != nullptr)
12191220
JobStorage.~ProcessInlineJob();
1220-
job = new (&JobStorage) ProcessInlineJob(priority);
1221+
job = ::new (&JobStorage) ProcessInlineJob(priority);
12211222
} else {
12221223
assert(false && "Should not be here - we don't have support for any OOL actor process jobs yet");
12231224
// TODO (rokhinip): Don't we need to take a +1 per ref count rules specified?

stdlib/public/Concurrency/AsyncLet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static AsyncLetImpl *asImpl(const AsyncLet *alet) {
141141

142142
void swift::asyncLet_addImpl(AsyncTask *task, AsyncLet *asyncLet,
143143
bool didAllocateInParentTask) {
144-
AsyncLetImpl *impl = new (asyncLet) AsyncLetImpl(task);
144+
AsyncLetImpl *impl = ::new (asyncLet) AsyncLetImpl(task);
145145
impl->setDidAllocateFromParentTask(didAllocateInParentTask);
146146

147147
auto record = impl->getTaskRecord();

stdlib/public/Concurrency/Task.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "Debug.h"
2929
#include "Error.h"
3030
#include <atomic>
31+
#include <new>
3132

3233
#if SWIFT_CONCURRENCY_ENABLE_DISPATCH
3334
#include <dispatch/dispatch.h>
@@ -770,20 +771,20 @@ static AsyncTaskAndContext swift_task_create_commonImpl(
770771
// Initialize the child fragment if applicable.
771772
if (parent) {
772773
auto childFragment = task->childFragment();
773-
new (childFragment) AsyncTask::ChildFragment(parent);
774+
::new (childFragment) AsyncTask::ChildFragment(parent);
774775
}
775776

776777
// Initialize the group child fragment if applicable.
777778
if (group) {
778779
auto groupChildFragment = task->groupChildFragment();
779-
new (groupChildFragment) AsyncTask::GroupChildFragment(group);
780+
::new (groupChildFragment) AsyncTask::GroupChildFragment(group);
780781
}
781782

782783
// Initialize the future fragment if applicable.
783784
if (futureResultType) {
784785
assert(task->isFuture());
785786
auto futureFragment = task->futureFragment();
786-
new (futureFragment) FutureFragment(futureResultType);
787+
::new (futureFragment) FutureFragment(futureResultType);
787788

788789
// Set up the context for the future so there is no error, and a successful
789790
// result will be written into the future fragment's storage.
@@ -1202,7 +1203,7 @@ swift_task_addCancellationHandlerImpl(
12021203
void *allocation =
12031204
swift_task_alloc(sizeof(CancellationNotificationStatusRecord));
12041205
auto unsigned_handler = swift_auth_code(handler, 3848);
1205-
auto *record = new (allocation)
1206+
auto *record = ::new (allocation)
12061207
CancellationNotificationStatusRecord(unsigned_handler, context);
12071208

12081209
bool fireHandlerNow = false;
@@ -1237,7 +1238,7 @@ swift_task_createNullaryContinuationJobImpl(
12371238
void *allocation =
12381239
swift_task_alloc(sizeof(NullaryContinuationJob));
12391240
auto *job =
1240-
new (allocation) NullaryContinuationJob(
1241+
::new (allocation) NullaryContinuationJob(
12411242
swift_task_getCurrent(), static_cast<JobPriority>(priority),
12421243
continuation);
12431244

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "string"
3434
#include "queue" // TODO: remove and replace with usage of our mpsc queue
3535
#include <atomic>
36+
#include <new>
3637
#include <assert.h>
3738
#if SWIFT_CONCURRENCY_ENABLE_DISPATCH
3839
#include <dispatch/dispatch.h>
@@ -469,7 +470,7 @@ SWIFT_CC(swift)
469470
static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T) {
470471
SWIFT_TASK_DEBUG_LOG("creating task group = %p", group);
471472

472-
TaskGroupImpl *impl = new (group) TaskGroupImpl(T);
473+
TaskGroupImpl *impl = ::new (group) TaskGroupImpl(T);
473474
auto record = impl->getTaskRecord();
474475
assert(impl == record && "the group IS the task record");
475476

stdlib/public/Concurrency/TaskLocal.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/ABI/Metadata.h"
2525
#include "llvm/ADT/PointerIntPair.h"
2626
#include "TaskPrivate.h"
27+
#include <new>
2728
#include <set>
2829

2930
#if SWIFT_STDLIB_HAS_ASL
@@ -207,7 +208,7 @@ TaskLocal::Item::createLink(AsyncTask *task,
207208
size_t amountToAllocate = Item::itemSize(valueType);
208209
void *allocation = task ? _swift_task_alloc_specific(task, amountToAllocate)
209210
: malloc(amountToAllocate);
210-
Item *item = new (allocation) Item(key, valueType);
211+
Item *item = ::new (allocation) Item(key, valueType);
211212

212213
auto next = task ? task->_private().Local.head
213214
: FallbackTaskLocalStorage::get()->head;

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/Runtime/Heap.h"
3030
#include "swift/Runtime/HeapObject.h"
3131
#include <atomic>
32+
#include <new>
3233

3334
#define SWIFT_FATAL_ERROR swift_Concurrency_fatalError
3435
#include "../runtime/StackAllocator.h"
@@ -655,11 +656,11 @@ AsyncTask::OpaquePrivateStorage::get() const {
655656
return reinterpret_cast<const PrivateStorage &>(*this);
656657
}
657658
inline void AsyncTask::OpaquePrivateStorage::initialize(JobPriority basePri) {
658-
new (this) PrivateStorage(basePri);
659+
::new (this) PrivateStorage(basePri);
659660
}
660661
inline void AsyncTask::OpaquePrivateStorage::initializeWithSlab(
661662
JobPriority basePri, void *slab, size_t slabCapacity) {
662-
new (this) PrivateStorage(basePri, slab, slabCapacity);
663+
::new (this) PrivateStorage(basePri, slab, slabCapacity);
663664
}
664665
inline void AsyncTask::OpaquePrivateStorage::complete(AsyncTask *task) {
665666
get().complete(task);

stdlib/public/runtime/AccessibleFunction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/Runtime/Metadata.h"
2424

2525
#include <cstdint>
26+
#include <new>
2627

2728
using namespace swift;
2829

@@ -153,7 +154,7 @@ swift::runtime::swift_findAccessibleFunction(const char *targetNameStart,
153154
S.Cache.getOrInsert(
154155
name, [&](AccessibleFunctionCacheEntry *entry, bool created) {
155156
if (created)
156-
new (entry) AccessibleFunctionCacheEntry{name, record};
157+
::new (entry) AccessibleFunctionCacheEntry{name, record};
157158
return true;
158159
});
159160
}

stdlib/public/runtime/AnyHashableSupport.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "swift/Runtime/Debug.h"
2222
#include "swift/Runtime/HeapObject.h"
2323

24+
#include <new>
25+
2426
using namespace swift;
2527
using namespace swift::hashable_support;
2628

@@ -103,7 +105,7 @@ findHashableBaseTypeImpl(const Metadata *type) {
103105
HashableConformances.getOrInsert(key, [&](HashableConformanceEntry *entry,
104106
bool created) {
105107
if (created)
106-
new (entry) HashableConformanceEntry(key, baseTypeThatConformsToHashable);
108+
::new (entry) HashableConformanceEntry(key, baseTypeThatConformsToHashable);
107109
return true; // Keep the new entry.
108110
});
109111
return baseTypeThatConformsToHashable;

stdlib/public/runtime/AutoDiffSupport.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "swift/ABI/Metadata.h"
1515
#include "swift/Runtime/HeapObject.h"
1616

17+
#include <new>
18+
1719
using namespace swift;
1820
using namespace llvm;
1921

@@ -59,7 +61,7 @@ AutoDiffLinearMapContext *swift::swift_autoDiffCreateLinearMapContext(
5961
sizeof(AutoDiffLinearMapContext), alignof(AutoDiffLinearMapContext))
6062
+ topLevelLinearMapStructSize;
6163
auto *buffer = (AutoDiffLinearMapContext *)malloc(allocationSize);
62-
return new (buffer) AutoDiffLinearMapContext;
64+
return ::new (buffer) AutoDiffLinearMapContext;
6365
}
6466

6567
void *swift::swift_autoDiffProjectTopLevelSubcontext(

stdlib/public/runtime/HeapObject.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <cstring>
3232
#include <cstdio>
3333
#include <cstdlib>
34+
#include <new>
3435
#include <thread>
3536
#include "../SwiftShims/GlobalObjects.h"
3637
#include "../SwiftShims/RuntimeShims.h"
@@ -124,7 +125,7 @@ static HeapObject *_swift_allocObject_(HeapMetadata const *metadata,
124125
// NOTE: this relies on the C++17 guaranteed semantics of no null-pointer
125126
// check on the placement new allocator which we have observed on Windows,
126127
// Linux, and macOS.
127-
new (object) HeapObject(metadata);
128+
::new (object) HeapObject(metadata);
128129

129130
// If leak tracking is enabled, start tracking this object.
130131
SWIFT_LEAKS_START_TRACKING_OBJECT(object);

stdlib/public/runtime/KeyPaths.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "swift/Runtime/Metadata.h"
1515
#include <cstdint>
1616
#include <cstring>
17+
#include <new>
1718

1819
using namespace swift;
1920

@@ -98,7 +99,7 @@ namespace {
9899
static OpaqueValue *allocateIn(const Metadata *type,
99100
YieldOnceBuffer *buffer) {
100101
auto *temp =
101-
new (reinterpret_cast<void*>(buffer)) YieldOnceTemporary(type);
102+
::new (reinterpret_cast<void*>(buffer)) YieldOnceTemporary(type);
102103
return type->allocateBufferIn(&temp->Buffer);
103104
}
104105

stdlib/public/runtime/Metadata.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,7 +2385,7 @@ static ValueWitnessTable *getMutableVWTableForInit(StructMetadata *self,
23852385
// Otherwise, allocate permanent memory for it and copy the existing table.
23862386
void *memory = allocateMetadata(sizeof(ValueWitnessTable),
23872387
alignof(ValueWitnessTable));
2388-
auto newTable = new (memory) ValueWitnessTable(*oldTable);
2388+
auto newTable = ::new (memory) ValueWitnessTable(*oldTable);
23892389

23902390
// If we ever need to check layout-completeness asynchronously from
23912391
// initialization, we'll need this to be a store-release (and rely on
@@ -4650,7 +4650,7 @@ static const WitnessTable *_getForeignWitnessTable(
46504650
ForeignWitnessTables.getOrInsert(
46514651
key, [&](ForeignWitnessTableCacheEntry *entryPtr, bool created) {
46524652
if (created)
4653-
new (entryPtr)
4653+
::new (entryPtr)
46544654
ForeignWitnessTableCacheEntry(key, witnessTableCandidate);
46554655
result = entryPtr->data;
46564656
return true;

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <functional>
3939
#include <vector>
4040
#include <list>
41+
#include <new>
4142

4243
using namespace swift;
4344
using namespace Demangle;
@@ -774,7 +775,7 @@ _findContextDescriptor(Demangle::NodePointer node,
774775
*entry,
775776
bool created) {
776777
if (created)
777-
new (entry) NominalTypeDescriptorCacheEntry{mangledName, foundContext};
778+
::new (entry) NominalTypeDescriptorCacheEntry{mangledName, foundContext};
778779
return true;
779780
});
780781

@@ -931,7 +932,7 @@ _findProtocolDescriptor(NodePointer node,
931932
*entry,
932933
bool created) {
933934
if (created)
934-
new (entry) ProtocolDescriptorCacheEntry{mangledName, foundProtocol};
935+
::new (entry) ProtocolDescriptorCacheEntry{mangledName, foundProtocol};
935936
return true;
936937
});
937938
}

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "ImageInspection.h"
3232
#include "Private.h"
3333

34+
#include <new>
3435
#include <vector>
3536

3637
#if __has_include(<mach-o/dyld_priv.h>)
@@ -510,7 +511,7 @@ struct ConformanceState {
510511
SectionsToScan.snapshot().count() != sectionsCount)
511512
return false; // abandon the new entry
512513

513-
new (entry) ConformanceCacheEntry(
514+
::new (entry) ConformanceCacheEntry(
514515
ConformanceCacheKey(type, proto), witness);
515516
return true; // keep the new entry
516517
});

stdlib/public/runtime/StackAllocator.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "swift/Runtime/Debug.h"
2626
#include "llvm/Support/Alignment.h"
2727
#include <cstddef>
28+
#include <new>
2829

2930
// Notes: swift::fatalError is not shared between libswiftCore and libswift_Concurrency
3031
// and libswift_Concurrency uses swift_Concurrency_fatalError instead.
@@ -170,7 +171,7 @@ class StackAllocator {
170171
assert(llvm::isAligned(llvm::Align(alignment), alignedSize));
171172
assert(canAllocate(alignedSize));
172173
void *buffer = getAddr(currentOffset);
173-
auto *allocation = new (buffer) Allocation(lastAllocation, this);
174+
auto *allocation = ::new (buffer) Allocation(lastAllocation, this);
174175
currentOffset += Allocation::includingHeader(alignedSize);
175176
if (guardAllocations) {
176177
uintptr_t *endOfCurrentAllocation = (uintptr_t *)getAddr(currentOffset);
@@ -251,7 +252,7 @@ class StackAllocator {
251252
size_t capacity = std::max(SlabCapacity,
252253
Allocation::includingHeader(size));
253254
void *slabBuffer = malloc(Slab::includingHeader(capacity));
254-
Slab *newSlab = new (slabBuffer) Slab(capacity);
255+
Slab *newSlab = ::new (slabBuffer) Slab(capacity);
255256
if (slab)
256257
slab->next = newSlab;
257258
else
@@ -292,7 +293,7 @@ class StackAllocator {
292293
char *end = (char *)firstSlabBuffer + bufferCapacity;
293294
assert(start + Slab::headerSize() <= end &&
294295
"buffer for first slab too small");
295-
firstSlab = new (start) Slab(end - start - Slab::headerSize());
296+
firstSlab = ::new (start) Slab(end - start - Slab::headerSize());
296297
firstSlabIsPreallocated = true;
297298
numAllocatedSlabs = 0;
298299
}

stdlib/public/runtime/SwiftRT-COFF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void swift_image_constructor() {
6565
{ reinterpret_cast<uintptr_t>(&__start_##name) + sizeof(__start_##name), \
6666
reinterpret_cast<uintptr_t>(&__stop_##name) - reinterpret_cast<uintptr_t>(&__start_##name) - sizeof(__start_##name) }
6767

68-
new (&sections) swift::MetadataSections {
68+
::new (&sections) swift::MetadataSections {
6969
swift::CurrentSectionMetadataVersion,
7070
{ __ImageBase },
7171

stdlib/public/runtime/SwiftRT-ELF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void swift_image_constructor() {
5656
{ reinterpret_cast<uintptr_t>(&__start_##name), \
5757
static_cast<uintptr_t>(&__stop_##name - &__start_##name) }
5858

59-
new (&sections) swift::MetadataSections {
59+
::new (&sections) swift::MetadataSections {
6060
swift::CurrentSectionMetadataVersion,
6161
{ __dso_handle },
6262

stdlib/public/runtime/SwiftValue.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <objc/runtime.h>
3535
#include <Foundation/Foundation.h>
3636

37+
#include <new>
38+
3739
using namespace swift;
3840
using namespace swift::hashable_support;
3941

@@ -196,7 +198,7 @@ static size_t getSwiftValuePayloadAlignMask(const Metadata *type) {
196198
*/
197199

198200
auto header = getSwiftValueHeader(instance);
199-
new (header) SwiftValueHeader();
201+
::new (header) SwiftValueHeader();
200202
header->type = srcType;
201203

202204
auto payload = getSwiftValuePayload(instance, alignMask);

0 commit comments

Comments
 (0)