Commit ee776518 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

keep_sink

Summary: A helper for use with check functions using `FOLLY_KEEP`.

Reviewed By: luciang

Differential Revision: D27072070

fbshipit-source-id: 9c106ca1e0854b0f16453e8ad73d7001c3b7fff6
parent f4f864ef
......@@ -16,6 +16,8 @@
#pragma once
#include <folly/CPortability.h>
// FOLLY_KEEP
//
// When applied to a function, prevents removal of the function.
......@@ -64,5 +66,9 @@ class keep {
// noinline ctor and trivial dtor minimize the text size of this
static keep keep_instance{keep_anchor};
// weak and noinline to prevent the compiler from eliding calls
template <typename... T>
FOLLY_ATTR_WEAK FOLLY_NOINLINE void keep_sink(T&&...) {}
} // namespace detail
} // namespace folly
......@@ -25,26 +25,17 @@
#include <folly/lang/Pretty.h>
#include <folly/portability/GTest.h>
namespace folly {
namespace exception_test {
template <typename... T>
FOLLY_ATTR_WEAK FOLLY_NOINLINE void sink(T&&...) {}
} // namespace exception_test
} // namespace folly
extern "C" FOLLY_KEEP void check_cond_std_terminate(bool c) {
if (c) {
std::terminate();
}
folly::exception_test::sink();
folly::detail::keep_sink();
}
extern "C" FOLLY_KEEP void check_cond_folly_terminate_with(bool c) {
if (c) {
folly::terminate_with<std::runtime_error>("bad error");
}
folly::exception_test::sink();
folly::detail::keep_sink();
}
template <typename Ex>
......
......@@ -23,23 +23,14 @@
#include <folly/lang/Keep.h>
#include <folly/portability/GTest.h>
namespace folly {
namespace safe_assert_test {
template <typename... T>
FOLLY_ATTR_WEAK FOLLY_NOINLINE void sink(T&&...) {}
} // namespace safe_assert_test
} // namespace folly
extern "C" FOLLY_KEEP void check_folly_safe_check(bool cond) {
FOLLY_SAFE_CHECK(cond, "the condition failed");
folly::safe_assert_test::sink();
folly::detail::keep_sink();
}
extern "C" FOLLY_KEEP void check_folly_safe_pcheck(bool cond) {
FOLLY_SAFE_PCHECK(cond, "the condition failed");
folly::safe_assert_test::sink();
folly::detail::keep_sink();
}
// clang-format off
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment