Summary:
Provide translations for gcc always_inline and noinline attribute
Change to using a macro from portability.h for attributes for using always_inline and noinline for cross platform support
Test Plan: fbmake runtests
Reviewed By: delong.j@fb.com
FB internal diff:
D1279652
# define FOLLY_NORETURN
#endif
+// noinline
+#ifdef _MSC_VER
+# define FOLLY_NOINLINE __declspec(noinline)
+#elif defined(__clang__) || defined(__GNUC__)
+# define FOLLY_NOINLINE __attribute__((noinline))
+#else
+# define FOLLY_NOINLINE
+#endif
+
+// always inline
+#ifdef _MSC_VER
+# define FOLLY_ALWAYS_INLINE __forceinline
+#elif defined(__clang__) || defined(__GNUC__)
+# define FOLLY_ALWAYS_INLINE inline __attribute__((always_inline))
+#else
+# define FOLLY_ALWAYS_INLINE
+#endif
// portable version check
#ifndef __GNUC_PREREQ
assert((tls_stackLimit & (s_pageSize - 1)) == 0);
}
-static __attribute__((noinline)) uintptr_t getStackPtr() {
+FOLLY_NOINLINE static uintptr_t getStackPtr() {
char marker;
auto rv = uintptr_t(&marker);
return rv;
namespace {
// Make sure we're counting stack frames correctly, don't inline.
-void addActiveException() __attribute__((noinline));
+FOLLY_NOINLINE void addActiveException();
void addActiveException() {
pthread_once(&initialized, initialize);
auto gSignalSafeElfCache = new SignalSafeElfCache(kDefaultCapacity);
} // namespace
-void dumpStackTrace(bool symbolize) __attribute__((noinline));
+FOLLY_NOINLINE void dumpStackTrace(bool symbolize);
void dumpStackTrace(bool symbolize) {
SCOPE_EXIT { fsyncNoInt(STDERR_FILENO); };
// Always inline these functions; they don't do much, and unittests rely
// on them never showing up in a stack trace.
template <size_t N>
-inline bool getStackTrace(FrameArray<N>& fa) __attribute__((always_inline));
+FOLLY_ALWAYS_INLINE bool getStackTrace(FrameArray<N>& fa);
template <size_t N>
inline bool getStackTrace(FrameArray<N>& fa) {
return detail::fixFrameArray(fa, getStackTrace(fa.addresses, N));
}
template <size_t N>
-inline bool getStackTraceSafe(FrameArray<N>& fa) __attribute__((always_inline));
+FOLLY_ALWAYS_INLINE bool getStackTraceSafe(FrameArray<N>& fa);
template <size_t N>
inline bool getStackTraceSafe(FrameArray<N>& fa) {
using namespace folly;
using namespace folly::symbolizer;
-void foo1() __attribute__((noinline));
-void foo2() __attribute__((noinline));
+FOLLY_NOINLINE void foo1();
+FOLLY_NOINLINE void foo2();
void verifyStackTraces() {
constexpr size_t kMaxAddresses = 100;
}
// Test stack frames...
-void bar() __attribute__((noinline));
+FOLLY_NOINLINE void bar();
void bar() {
int a[2] = {1, 2};