mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Rollback of no-op changes for internal experiment
PiperOrigin-RevId: 925405274 Change-Id: Ieac8e1e8d427fefecd8ddacc62043ea27e729c88
This commit is contained in:
committed by
Copybara-Service
parent
90758df74d
commit
26139554b9
@@ -22,7 +22,6 @@ set(ABSL_INTERNAL_DLL_FILES
|
||||
"base/internal/dynamic_annotations.h"
|
||||
"base/internal/endian.h"
|
||||
"base/internal/errno_saver.h"
|
||||
"base/internal/hardening.cc"
|
||||
"base/internal/hardening.h"
|
||||
"base/internal/hide_ptr.h"
|
||||
"base/internal/iterator_traits.h"
|
||||
|
||||
@@ -80,7 +80,6 @@ cc_library(
|
||||
|
||||
cc_library(
|
||||
name = "hardening",
|
||||
srcs = ["internal/hardening.cc"],
|
||||
hdrs = [
|
||||
"internal/hardening.h",
|
||||
],
|
||||
|
||||
@@ -61,8 +61,6 @@ absl_cc_library(
|
||||
hardening
|
||||
HDRS
|
||||
"internal/hardening.h"
|
||||
SRCS
|
||||
"internal/hardening.cc"
|
||||
DEPS
|
||||
absl::config
|
||||
absl::core_headers
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
//
|
||||
// Copyright 2026 The Abseil Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "absl/base/internal/hardening.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/macros.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
|
||||
namespace base_internal {
|
||||
|
||||
void SetAbslHardeningEnabled([[maybe_unused]] bool enabled) {
|
||||
}
|
||||
|
||||
} // namespace base_internal
|
||||
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
@@ -32,8 +32,6 @@ ABSL_NAMESPACE_BEGIN
|
||||
|
||||
namespace base_internal {
|
||||
|
||||
void SetAbslHardeningEnabled(bool enabled);
|
||||
|
||||
// `HardeningAssert` performs runtime checks when Abseil Hardening is enabled,
|
||||
// even if `NDEBUG` is defined.
|
||||
//
|
||||
|
||||
@@ -42,28 +42,14 @@ bool IsHardenedSlow() {
|
||||
return hardened;
|
||||
}
|
||||
|
||||
class HardeningTest : public testing::Test {
|
||||
public:
|
||||
~HardeningTest() override {
|
||||
absl::base_internal::SetAbslHardeningEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
class HardeningDeathTest : public testing::Test {
|
||||
public:
|
||||
~HardeningDeathTest() override {
|
||||
absl::base_internal::SetAbslHardeningEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(HardeningTest, HardeningAssertSlow) {
|
||||
TEST(HardeningTest, HardeningAssertSlow) {
|
||||
absl::base_internal::HardeningAssertSlow(true);
|
||||
if (!IsHardenedSlow()) {
|
||||
absl::base_internal::HardeningAssertSlow(false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(HardeningDeathTest, HardeningAssertSlow) {
|
||||
TEST(HardeningDeathTest, HardeningAssertSlow) {
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
if (IsHardenedSlow()) {
|
||||
// The underlying mechanism of termination varies, and may include SIGILL
|
||||
@@ -73,114 +59,107 @@ TEST_F(HardeningDeathTest, HardeningAssertSlow) {
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(HardeningTest, HardeningAssertGT) {
|
||||
TEST(HardeningTest, HardeningAssertGT) {
|
||||
absl::base_internal::HardeningAssertGT(1, 0);
|
||||
}
|
||||
|
||||
TEST_F(HardeningDeathTest, HardeningAssertGT) {
|
||||
TEST(HardeningDeathTest, HardeningAssertGT) {
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
if (IsHardened()) {
|
||||
// The underlying mechanism of termination varies, and may include SIGILL
|
||||
// or SIGABRT.
|
||||
absl::base_internal::SetAbslHardeningEnabled(true);
|
||||
EXPECT_DEATH(absl::base_internal::HardeningAssertGT(1, 1), "");
|
||||
EXPECT_DEATH(absl::base_internal::HardeningAssertGT(0, 1), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(HardeningTest, HardeningAssertGE) {
|
||||
TEST(HardeningTest, HardeningAssertGE) {
|
||||
absl::base_internal::HardeningAssertGE(1, 0);
|
||||
absl::base_internal::HardeningAssertGE(1, 1);
|
||||
}
|
||||
|
||||
TEST_F(HardeningDeathTest, HardeningAssertGE) {
|
||||
TEST(HardeningDeathTest, HardeningAssertGE) {
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
if (IsHardened()) {
|
||||
// The underlying mechanism of termination varies, and may include SIGILL
|
||||
// or SIGABRT.
|
||||
absl::base_internal::SetAbslHardeningEnabled(true);
|
||||
EXPECT_DEATH(absl::base_internal::HardeningAssertGE(0, 1), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(HardeningTest, HardeningAssertLT) {
|
||||
TEST(HardeningTest, HardeningAssertLT) {
|
||||
absl::base_internal::HardeningAssertLT(0, 1);
|
||||
}
|
||||
|
||||
TEST_F(HardeningDeathTest, HardeningAssertLT) {
|
||||
TEST(HardeningDeathTest, HardeningAssertLT) {
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
if (IsHardened()) {
|
||||
// The underlying mechanism of termination varies, and may include SIGILL
|
||||
// or SIGABRT.
|
||||
absl::base_internal::SetAbslHardeningEnabled(true);
|
||||
EXPECT_DEATH(absl::base_internal::HardeningAssertLT(1, 1), "");
|
||||
EXPECT_DEATH(absl::base_internal::HardeningAssertLT(1, 0), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(HardeningTest, HardeningAssertLE) {
|
||||
TEST(HardeningTest, HardeningAssertLE) {
|
||||
absl::base_internal::HardeningAssertLE(0, 1);
|
||||
absl::base_internal::HardeningAssertLE(1, 1);
|
||||
}
|
||||
|
||||
TEST_F(HardeningDeathTest, HardeningAssertLE) {
|
||||
TEST(HardeningDeathTest, HardeningAssertLE) {
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
if (IsHardened()) {
|
||||
// The underlying mechanism of termination varies, and may include SIGILL
|
||||
// or SIGABRT.
|
||||
absl::base_internal::SetAbslHardeningEnabled(true);
|
||||
EXPECT_DEATH(absl::base_internal::HardeningAssertLE(1, 0), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(HardeningTest, HardeningAssertInBounds) {
|
||||
TEST(HardeningTest, HardeningAssertInBounds) {
|
||||
absl::base_internal::HardeningAssertInBounds(0, 10);
|
||||
}
|
||||
|
||||
TEST_F(HardeningDeathTest, HardeningAssertInBounds) {
|
||||
TEST(HardeningDeathTest, HardeningAssertInBounds) {
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
if (IsHardened()) {
|
||||
// The underlying mechanism of termination varies, and may include SIGILL
|
||||
// or SIGABRT.
|
||||
absl::base_internal::SetAbslHardeningEnabled(true);
|
||||
EXPECT_DEATH(absl::base_internal::HardeningAssertInBounds(10, 10), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(HardeningTest, HardeningAssertNonEmpty) {
|
||||
TEST(HardeningTest, HardeningAssertNonEmpty) {
|
||||
std::vector<int> v = {1};
|
||||
absl::base_internal::HardeningAssertNonEmpty(v);
|
||||
}
|
||||
|
||||
TEST_F(HardeningDeathTest, HardeningAssertNonEmpty) {
|
||||
TEST(HardeningDeathTest, HardeningAssertNonEmpty) {
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
if (IsHardened()) {
|
||||
// The underlying mechanism of termination varies, and may include SIGILL
|
||||
// or SIGABRT.
|
||||
std::vector<int> v = {};
|
||||
absl::base_internal::SetAbslHardeningEnabled(true);
|
||||
EXPECT_DEATH(absl::base_internal::HardeningAssertNonEmpty(v), "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(HardeningTest, HardeningAssertNonNull) {
|
||||
TEST(HardeningTest, HardeningAssertNonNull) {
|
||||
int x = 1;
|
||||
absl::base_internal::HardeningAssertNonNull(&x);
|
||||
}
|
||||
|
||||
TEST_F(HardeningDeathTest, HardeningAssertNonNull) {
|
||||
TEST(HardeningDeathTest, HardeningAssertNonNull) {
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
if (IsHardened()) {
|
||||
// The underlying mechanism of termination varies, and may include SIGILL
|
||||
// or SIGABRT.
|
||||
int *x = nullptr;
|
||||
absl::base_internal::SetAbslHardeningEnabled(true);
|
||||
EXPECT_DEATH(absl::base_internal::HardeningAssertNonNull(x), "");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#ifndef ABSL_BASE_MACROS_H_
|
||||
#define ABSL_BASE_MACROS_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
@@ -158,12 +157,12 @@ ABSL_NAMESPACE_END
|
||||
// See `ABSL_OPTION_HARDENED` in `absl/base/options.h` for more information on
|
||||
// hardened mode.
|
||||
#if (ABSL_OPTION_HARDENED == 1 || ABSL_OPTION_HARDENED == 2) && defined(NDEBUG)
|
||||
#define ABSL_HARDENING_ASSERT(expr) \
|
||||
do { \
|
||||
if (!ABSL_PREDICT_TRUE((expr))) { \
|
||||
ABSL_INTERNAL_HARDENING_ABORT(); \
|
||||
} \
|
||||
} while (false)
|
||||
#define ABSL_HARDENING_ASSERT(expr) \
|
||||
do { \
|
||||
if (!ABSL_PREDICT_TRUE((expr))) { \
|
||||
ABSL_INTERNAL_HARDENING_ABORT(); \
|
||||
} \
|
||||
} while (false)
|
||||
#else
|
||||
#define ABSL_HARDENING_ASSERT(expr) ABSL_ASSERT(expr)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user