Skip to content

Commit

Permalink
Work around SR-11680 (OpenCombine#145)
Browse files Browse the repository at this point in the history
The Swift bug report: https://bugs.swift.org/browse/SR-11680

Swift nightly toolchains are available here: https://swift.org/download/

The Swift nightly toolchains cannot build OpenCombine. Here's why:

The COpenCombineHelpers target defines a non-static function
(`opencombine_stop_in_debugger`) in a header file. This function is
emitted in the target's IR, but not in the target's TBD.

Swift nightly toolchains have assertions enabled, so they use the
-validate-tbd-against-ir=missing build setting. This build setting
makes the compiler fail if the TBD doesn't match the IR.

This commit un-inlines `opencombine_stop_in_debugger`, so it
is not emitted in the IR. This stops the TBD validator from
complaining.
  • Loading branch information
mayoff authored and sfmntmzzn committed Jun 10, 2020
1 parent 3f86357 commit 0ec3a00
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
5 changes: 5 additions & 0 deletions Sources/COpenCombineHelpers/COpenCombineHelpers.cpp
Expand Up @@ -11,6 +11,7 @@
#include <cstdlib>
#include <system_error>
#include <pthread.h>
#include <signal.h>

#ifdef __APPLE__
#include <os/lock.h>
Expand Down Expand Up @@ -235,4 +236,8 @@ void opencombine_unfair_recursive_lock_dealloc(OpenCombineUnfairRecursiveLock lo
return delete static_cast<PlatformIndependentMutex*>(lock.opaque);
}

void opencombine_stop_in_debugger(void) {
raise(SIGTRAP);
}

} // extern "C"
14 changes: 1 addition & 13 deletions Sources/COpenCombineHelpers/include/COpenCombineHelpers.h
Expand Up @@ -9,20 +9,13 @@
#define COPENCOMBINEHELPERS_H

#include <stdint.h>
#include <signal.h>

#if __has_attribute(swift_name)
# define OPENCOMBINE_SWIFT_NAME(_name) __attribute__((swift_name(#_name)))
#else
# define OPENCOMBINE_SWIFT_NAME(_name)
#endif

#if __has_attribute(always_inline)
# define OPENCOMBINE_ALWAYS_INLINE __attribute__((always_inline))
#else
# define OPENCOMBINE_ALWAYS_INLINE
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -77,12 +70,7 @@ void opencombine_unfair_recursive_lock_dealloc(OpenCombineUnfairRecursiveLock lo

#pragma mark - Breakpoint

OPENCOMBINE_ALWAYS_INLINE
inline void opencombine_stop_in_debugger(void) OPENCOMBINE_SWIFT_NAME(__stopInDebugger());

void opencombine_stop_in_debugger(void) {
raise(SIGTRAP);
}
void opencombine_stop_in_debugger(void) OPENCOMBINE_SWIFT_NAME(__stopInDebugger());

#ifdef __cplusplus
} // extern "C"
Expand Down

0 comments on commit 0ec3a00

Please sign in to comment.