Skip to content

Commit 8118e17

Browse files
Merge pull request #11414 from swiftlang/revert-11409-add_dispatch_apply
Revert "Add dispatch apply"
2 parents 68e54dd + aca2091 commit 8118e17

File tree

5 files changed

+6
-119
lines changed

5 files changed

+6
-119
lines changed

compiler-rt/lib/asan/asan_mac.cpp

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ void FlushUnneededASanShadowMemory(uptr p, uptr size) {
103103
// dispatch_after()
104104
// dispatch_group_async_f()
105105
// dispatch_group_async()
106-
// dispatch_apply()
107-
// dispatch_apply_f()
108106
// TODO(glider): libdispatch API contains other functions that we don't support
109107
// yet.
110108
//
@@ -130,7 +128,6 @@ typedef void* dispatch_queue_t;
130128
typedef void* dispatch_source_t;
131129
typedef u64 dispatch_time_t;
132130
typedef void (*dispatch_function_t)(void *block);
133-
typedef void (*dispatch_apply_function_t)(void *, size_t);
134131
typedef void* (*worker_t)(void *block);
135132
typedef unsigned long dispatch_mach_reason;
136133
typedef void *dispatch_mach_msg_t;
@@ -150,11 +147,7 @@ typedef void (^dispatch_mach_handler_t)(dispatch_mach_reason reason,
150147
// A wrapper for the ObjC blocks used to support libdispatch.
151148
typedef struct {
152149
void *block;
153-
union {
154-
dispatch_function_t dispatch_func;
155-
dispatch_apply_function_t dispatch_apply_func;
156-
static_assert(sizeof(dispatch_func) == sizeof(dispatch_apply_func));
157-
};
150+
dispatch_function_t func;
158151
u32 parent_tid;
159152
} asan_block_context_t;
160153

@@ -182,8 +175,8 @@ void asan_dispatch_call_block_and_release(void *block) {
182175
block, (void*)pthread_self());
183176
asan_register_worker_thread(context->parent_tid, &stack);
184177
// Call the original dispatcher for the block.
185-
context->dispatch_func(context->block);
186-
asan_free(context, &stack);
178+
context->func(context->block);
179+
asan_free(context, &stack, FROM_MALLOC);
187180
}
188181

189182
} // namespace __asan
@@ -198,7 +191,7 @@ asan_block_context_t *alloc_asan_context(void *ctxt, dispatch_function_t func,
198191
asan_block_context_t *asan_ctxt =
199192
(asan_block_context_t*) asan_malloc(sizeof(asan_block_context_t), stack);
200193
asan_ctxt->block = ctxt;
201-
asan_ctxt->dispatch_func = func;
194+
asan_ctxt->func = func;
202195
asan_ctxt->parent_tid = GetCurrentTidOrInvalid();
203196
return asan_ctxt;
204197
}
@@ -250,34 +243,13 @@ INTERCEPTOR(void, dispatch_group_async_f, dispatch_group_t group,
250243
asan_dispatch_call_block_and_release);
251244
}
252245

253-
extern "C" void asan_dispatch_apply_f_work(void *context, size_t iteration) {
254-
GET_STACK_TRACE_THREAD;
255-
asan_block_context_t *asan_ctxt = (asan_block_context_t *)context;
256-
asan_register_worker_thread(asan_ctxt->parent_tid, &stack);
257-
asan_ctxt->dispatch_apply_func(asan_ctxt->block, iteration);
258-
}
259-
260-
INTERCEPTOR(void, dispatch_apply_f, size_t iterations, dispatch_queue_t queue,
261-
void *ctxt, dispatch_apply_function_t work) {
262-
GET_STACK_TRACE_THREAD;
263-
asan_block_context_t *asan_ctxt =
264-
(asan_block_context_t *)asan_malloc(sizeof(asan_block_context_t), &stack);
265-
asan_ctxt->block = ctxt;
266-
asan_ctxt->dispatch_apply_func = work;
267-
asan_ctxt->parent_tid = GetCurrentTidOrInvalid();
268-
REAL(dispatch_apply_f)(iterations, queue, (void *)asan_ctxt,
269-
asan_dispatch_apply_f_work);
270-
}
271-
272-
# if !defined(MISSING_BLOCKS_SUPPORT)
246+
#if !defined(MISSING_BLOCKS_SUPPORT)
273247
extern "C" {
274248
void dispatch_async(dispatch_queue_t dq, void(^work)(void));
275249
void dispatch_group_async(dispatch_group_t dg, dispatch_queue_t dq,
276250
void(^work)(void));
277251
void dispatch_after(dispatch_time_t when, dispatch_queue_t queue,
278252
void(^work)(void));
279-
void dispatch_apply(size_t iterations, dispatch_queue_t queue,
280-
void (^block)(size_t iteration));
281253
void dispatch_source_set_cancel_handler(dispatch_source_t ds,
282254
void(^work)(void));
283255
void dispatch_source_set_event_handler(dispatch_source_t ds, void(^work)(void));
@@ -360,20 +332,6 @@ INTERCEPTOR(void *, dispatch_mach_create_f, const char *label,
360332
});
361333
}
362334

363-
INTERCEPTOR(void, dispatch_apply, size_t iterations, dispatch_queue_t queue,
364-
void (^block)(size_t iteration)) {
365-
ENABLE_FRAME_POINTER;
366-
int parent_tid = GetCurrentTidOrInvalid();
367-
368-
void (^asan_block)(size_t) = ^(size_t iteration) {
369-
GET_STACK_TRACE_THREAD;
370-
asan_register_worker_thread(parent_tid, &stack);
371-
block(iteration);
372-
};
373-
374-
REAL(dispatch_apply)(iterations, queue, asan_block);
375-
}
376-
377-
# endif
335+
#endif
378336

379337
#endif // SANITIZER_APPLE

compiler-rt/lib/asan/tests/asan_mac_test.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ TEST(AddressSanitizerMac, GCDDispatchAfter) {
116116
EXPECT_DEATH(TestGCDDispatchAfter(), "Shadow byte legend");
117117
}
118118

119-
TEST(AddressSanitizerMac, GCDDispatchApply) {
120-
// Make sure the whole ASan report is printed, i.e. that we don't die
121-
// on a CHECK.
122-
EXPECT_DEATH(TestGCDDispatchApply(), "Shadow byte legend");
123-
}
124-
125119
TEST(AddressSanitizerMac, GCDSourceEvent) {
126120
// Make sure the whole ASan report is printed, i.e. that we don't die
127121
// on a CHECK.

compiler-rt/lib/asan/tests/asan_mac_test.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ extern "C" {
99
void TestGCDReuseWqthreadsAsync();
1010
void TestGCDReuseWqthreadsSync();
1111
void TestGCDDispatchAfter();
12-
void TestGCDDispatchApply();
1312
void TestGCDInTSDDestructor();
1413
void TestGCDSourceEvent();
1514
void TestGCDSourceCancel();

compiler-rt/lib/asan/tests/asan_mac_test_helpers.mm

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,6 @@ void TestGCDDispatchAfter() {
148148
wait_forever();
149149
}
150150

151-
void TestGCDDispatchApply() {
152-
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
153-
__block char *buffer = (char *)malloc(4);
154-
dispatch_apply(8, queue, ^(size_t i) {
155-
access_memory(&buffer[i]);
156-
});
157-
158-
free(buffer); // not reached
159-
}
160-
161151
void worker_do_deallocate(void *ptr) {
162152
free(ptr);
163153
}

compiler-rt/test/asan/TestCases/Darwin/dispatch_apply_threadno.c

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)