Commit ac1398a6 by Abseil Team Committed by Derek Mauro

Export of internal Abseil changes

--
f4c7e510922668c68be4aa79a00867c3d3ca9f95 by Derek Mauro <dmauro@google.com>:

Many improvements to LeakChecker builds

The presence of the LeakChecker is now detected when possible. GCC
users using LeakChecker in standalone mode still need to use
-DLEAK_CHECKER. This is now documented in the header.

The hacky targets used for testing leak checking have been removed in
favor of testing in AddressSanitizer mode on Kokoro.

Fixes #885
Fixes #1153

PiperOrigin-RevId: 441203393
Change-Id: Ibe64ef6b104bcaf31839ff7184e558cc86abdd1c

--
5c70a23aa83b8152ab95d2cf21662fc63c80ef7d by Abseil Team <absl-team@google.com>:

Add a benchmark for stacktrace

PiperOrigin-RevId: 441196473
Change-Id: I4c9aa2e797aa2cae09abfaaee3abe5c09eb62fc4

--
50b406052273b9d5bad04a7860a96e4d5d956c02 by Abseil Team <absl-team@google.com>:

Internal change.

PiperOrigin-RevId: 441114481
Change-Id: I667af7a50d5631ca91289dd24c91ba90233e0184

--
568b4eaac120b420bce5290179d407d2b57d5bae by Dino Radakovic <dinor@google.com>:

Internal change

PiperOrigin-RevId: 440894155
Change-Id: Ia587ffc65a8321126585fb363b7c0ca8cc2a0da2

--
d53948eace4f3a10ac5a6c1496dc51b81adc412c by Abseil Team <absl-team@google.com>:

Explicitly give internal linkage to symbols which are not used outside of their
translation units.

PiperOrigin-RevId: 440424519
Change-Id: I531c5e229d443375483b7550a34f48042589a99b
GitOrigin-RevId: f4c7e510922668c68be4aa79a00867c3d3ca9f95
parent e854df09
...@@ -90,7 +90,6 @@ set(ABSL_INTERNAL_DLL_FILES ...@@ -90,7 +90,6 @@ set(ABSL_INTERNAL_DLL_FILES
"debugging/failure_signal_handler.cc" "debugging/failure_signal_handler.cc"
"debugging/failure_signal_handler.h" "debugging/failure_signal_handler.h"
"debugging/leak_check.h" "debugging/leak_check.h"
"debugging/leak_check_disable.cc"
"debugging/stacktrace.cc" "debugging/stacktrace.cc"
"debugging/stacktrace.h" "debugging/stacktrace.h"
"debugging/symbolize.cc" "debugging/symbolize.cc"
...@@ -345,6 +344,7 @@ set(ABSL_INTERNAL_DLL_FILES ...@@ -345,6 +344,7 @@ set(ABSL_INTERNAL_DLL_FILES
"types/internal/span.h" "types/internal/span.h"
"types/variant.h" "types/variant.h"
"utility/utility.h" "utility/utility.h"
"debugging/leak_check.cc"
) )
set(ABSL_INTERNAL_DLL_TARGETS set(ABSL_INTERNAL_DLL_TARGETS
...@@ -355,7 +355,6 @@ set(ABSL_INTERNAL_DLL_TARGETS ...@@ -355,7 +355,6 @@ set(ABSL_INTERNAL_DLL_TARGETS
"debugging_internal" "debugging_internal"
"demangle_internal" "demangle_internal"
"leak_check" "leak_check"
"leak_check_disable"
"stack_consumption" "stack_consumption"
"debugging" "debugging"
"hash" "hash"
......
...@@ -797,10 +797,27 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || ...@@ -797,10 +797,27 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
// ABSL_HAVE_LEAK_SANITIZER // ABSL_HAVE_LEAK_SANITIZER
// //
// LeakSanitizer (or lsan) is a detector of memory leaks. // LeakSanitizer (or lsan) is a detector of memory leaks.
// https://clang.llvm.org/docs/LeakSanitizer.html
// https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer
//
// The macro ABSL_HAVE_LEAK_SANITIZER can be used to detect at compile-time
// whether the LeakSanitizer is potentially available. However, just because the
// LeakSanitizer is available does not mean it is active. Use the
// always-available run-time interface in //absl/debugging/leak_check.h for
// interacting with LeakSanitizer.
#ifdef ABSL_HAVE_LEAK_SANITIZER #ifdef ABSL_HAVE_LEAK_SANITIZER
#error "ABSL_HAVE_LEAK_SANITIZER cannot be directly set." #error "ABSL_HAVE_LEAK_SANITIZER cannot be directly set."
#elif defined(LEAK_SANITIZER)
// GCC provides no method for detecting the presense of the standalone
// LeakSanitizer (-fsanitize=leak), so GCC users of -fsanitize=leak should also
// use -DLEAK_SANITIZER.
#define ABSL_HAVE_LEAK_SANITIZER 1
// Clang standalone LeakSanitizer (-fsanitize=leak)
#elif ABSL_HAVE_FEATURE(leak_sanitizer) #elif ABSL_HAVE_FEATURE(leak_sanitizer)
#define ABSL_HAVE_LEAK_SANITIZER 1 #define ABSL_HAVE_LEAK_SANITIZER 1
#elif defined(ABSL_HAVE_ADDRESS_SANITIZER)
// GCC or Clang using the LeakSanitizer integrated into AddressSanitizer.
#define ABSL_HAVE_LEAK_SANITIZER 1
#endif #endif
// ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION // ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
......
...@@ -124,7 +124,6 @@ int Win32NumCPUs() { ...@@ -124,7 +124,6 @@ int Win32NumCPUs() {
} // namespace } // namespace
static int GetNumCPUs() { static int GetNumCPUs() {
#if defined(__myriad2__) #if defined(__myriad2__)
return 1; return 1;
......
# See absl/copts/copts.py and absl/copts/generate_copts.py # See absl/copts/copts.py and absl/copts/generate_copts.py
include(GENERATED_AbseilCopts) include(GENERATED_AbseilCopts)
set(ABSL_LSAN_LINKOPTS "")
set(ABSL_HAVE_LSAN OFF)
set(ABSL_DEFAULT_LINKOPTS "") set(ABSL_DEFAULT_LINKOPTS "")
if (BUILD_SHARED_LIBS AND MSVC) if (BUILD_SHARED_LIBS AND MSVC)
...@@ -85,14 +83,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # MATCHES so we get both Clang an ...@@ -85,14 +83,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # MATCHES so we get both Clang an
else() else()
set(ABSL_DEFAULT_COPTS "${ABSL_LLVM_FLAGS}") set(ABSL_DEFAULT_COPTS "${ABSL_LLVM_FLAGS}")
set(ABSL_TEST_COPTS "${ABSL_LLVM_FLAGS};${ABSL_LLVM_TEST_FLAGS}") set(ABSL_TEST_COPTS "${ABSL_LLVM_FLAGS};${ABSL_LLVM_TEST_FLAGS}")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# AppleClang doesn't have lsan
# https://developer.apple.com/documentation/code_diagnostics
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
set(ABSL_LSAN_LINKOPTS "-fsanitize=leak")
set(ABSL_HAVE_LSAN ON)
endif()
endif()
endif() endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(ABSL_DEFAULT_COPTS "${ABSL_MSVC_FLAGS}") set(ABSL_DEFAULT_COPTS "${ABSL_MSVC_FLAGS}")
......
...@@ -225,6 +225,7 @@ cc_library( ...@@ -225,6 +225,7 @@ cc_library(
name = "leak_check", name = "leak_check",
srcs = ["leak_check.cc"], srcs = ["leak_check.cc"],
hdrs = ["leak_check.h"], hdrs = ["leak_check.h"],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [ deps = [
"//absl/base:config", "//absl/base:config",
...@@ -232,98 +233,33 @@ cc_library( ...@@ -232,98 +233,33 @@ cc_library(
], ],
) )
# Adding a dependency to leak_check_disable will disable
# sanitizer leak checking (asan/lsan) in a test without
# the need to mess around with build features.
cc_library(
name = "leak_check_disable",
srcs = ["leak_check_disable.cc"],
linkopts = ABSL_DEFAULT_LINKOPTS,
linkstatic = 1,
deps = ["//absl/base:config"],
alwayslink = 1,
)
# These targets exists for use in tests only, explicitly configuring the
# LEAK_SANITIZER macro. It must be linked with -fsanitize=leak for lsan.
ABSL_LSAN_LINKOPTS = select({
"//absl:clang_compiler": ["-fsanitize=leak"],
"//conditions:default": [],
})
cc_library(
name = "leak_check_api_enabled_for_testing",
testonly = 1,
srcs = ["leak_check.cc"],
hdrs = ["leak_check.h"],
copts = select({
"//absl:clang_compiler": ["-DLEAK_SANITIZER"],
"//conditions:default": [],
}),
linkopts = ABSL_DEFAULT_LINKOPTS,
visibility = ["//visibility:private"],
deps = [
"//absl/base:config",
"//absl/base:core_headers",
],
)
cc_library(
name = "leak_check_api_disabled_for_testing",
testonly = 1,
srcs = ["leak_check.cc"],
hdrs = ["leak_check.h"],
copts = ["-ULEAK_SANITIZER"],
linkopts = ABSL_DEFAULT_LINKOPTS,
visibility = ["//visibility:private"],
deps = [
"//absl/base:config",
"//absl/base:core_headers",
],
)
cc_test( cc_test(
name = "leak_check_test", name = "leak_check_test",
srcs = ["leak_check_test.cc"], srcs = ["leak_check_test.cc"],
copts = select({ copts = ABSL_TEST_COPTS,
"//absl:clang_compiler": ["-DABSL_EXPECT_LEAK_SANITIZER"],
"//conditions:default": [],
}),
linkopts = ABSL_LSAN_LINKOPTS + ABSL_DEFAULT_LINKOPTS,
tags = ["notsan"],
deps = [
":leak_check_api_enabled_for_testing",
"//absl/base",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "leak_check_no_lsan_test",
srcs = ["leak_check_test.cc"],
copts = ["-UABSL_EXPECT_LEAK_SANITIZER"],
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
tags = ["noasan"], tags = ["notsan"],
deps = [ deps = [
":leak_check_api_disabled_for_testing", ":leak_check",
"//absl/base", # for raw_logging "//absl/base:config",
"//absl/base:raw_logging_internal",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )
# Test that leak checking is skipped when lsan is enabled but # Binary that leaks memory and expects to fail on exit. This isn't a
# ":leak_check_disable" is linked in. # test that expected to pass on its own; it exists to be called by a
# # script that checks exit status and output.
# This test should fail in the absence of a dependency on ":leak_check_disable" # TODO(absl-team): Write a test to run this with a script that
cc_test( # verifies that it correctly fails.
name = "disabled_leak_check_test", cc_binary(
name = "leak_check_fail_test_binary",
srcs = ["leak_check_fail_test.cc"], srcs = ["leak_check_fail_test.cc"],
linkopts = ABSL_LSAN_LINKOPTS + ABSL_DEFAULT_LINKOPTS, copts = ABSL_TEST_COPTS,
tags = ["notsan"], linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [ deps = [
":leak_check_api_enabled_for_testing", ":leak_check",
":leak_check_disable", "//absl/base:raw_logging_internal",
"//absl/base",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )
...@@ -356,3 +292,18 @@ cc_test( ...@@ -356,3 +292,18 @@ cc_test(
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )
cc_binary(
name = "stacktrace_benchmark",
testonly = 1,
srcs = ["stacktrace_benchmark.cc"],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
tags = ["benchmark"],
deps = [
":stacktrace",
"//absl/base:config",
"//absl/base:core_headers",
"@com_github_google_benchmark//:benchmark_main",
],
)
...@@ -218,42 +218,6 @@ absl_cc_library( ...@@ -218,42 +218,6 @@ absl_cc_library(
PUBLIC PUBLIC
) )
absl_cc_library(
NAME
leak_check_disable
SRCS
"leak_check_disable.cc"
COPTS
${ABSL_DEFAULT_COPTS}
PUBLIC
)
absl_cc_library(
NAME
leak_check_api_enabled_for_testing
HDRS
"leak_check.h"
SRCS
"leak_check.cc"
COPTS
${ABSL_DEFAULT_COPTS}
$<$<BOOL:${ABSL_HAVE_LSAN}>:-DLEAK_SANITIZER>
TESTONLY
)
absl_cc_library(
NAME
leak_check_api_disabled_for_testing
HDRS
"leak_check.h"
SRCS
"leak_check.cc"
COPTS
${ABSL_DEFAULT_COPTS}
"-ULEAK_SANITIZER"
TESTONLY
)
absl_cc_test( absl_cc_test(
NAME NAME
leak_check_test leak_check_test
...@@ -261,43 +225,11 @@ absl_cc_test( ...@@ -261,43 +225,11 @@ absl_cc_test(
"leak_check_test.cc" "leak_check_test.cc"
COPTS COPTS
${ABSL_TEST_COPTS} ${ABSL_TEST_COPTS}
"$<$<BOOL:${ABSL_HAVE_LSAN}>:-DABSL_EXPECT_LEAK_SANITIZER>"
LINKOPTS LINKOPTS
"${ABSL_LSAN_LINKOPTS}" ${ABSL_DEFAULT_LINKOPTS}
DEPS
absl::leak_check_api_enabled_for_testing
absl::base
GTest::gmock_main
)
absl_cc_test(
NAME
leak_check_no_lsan_test
SRCS
"leak_check_test.cc"
COPTS
${ABSL_TEST_COPTS}
"-UABSL_EXPECT_LEAK_SANITIZER"
DEPS
absl::leak_check_api_disabled_for_testing
absl::base
GTest::gmock_main
)
absl_cc_test(
NAME
disabled_leak_check_test
SRCS
"leak_check_fail_test.cc"
COPTS
${ABSL_TEST_COPTS}
LINKOPTS
"${ABSL_LSAN_LINKOPTS}"
DEPS DEPS
absl::leak_check_api_enabled_for_testing absl::leak_check
absl::leak_check_disable
absl::base absl::base
absl::raw_logging_internal
GTest::gmock_main GTest::gmock_main
) )
......
...@@ -11,29 +11,19 @@ ...@@ -11,29 +11,19 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//
// Wrappers around lsan_interface functions. // Wrappers around lsan_interface functions.
// When lsan is not linked in, these functions are not available, //
// therefore Abseil code which depends on these functions is conditioned on the // These are always-available run-time functions manipulating the LeakSanitizer,
// definition of LEAK_SANITIZER. // even when the lsan_interface (and LeakSanitizer) is not available. When
#include "absl/base/attributes.h" // LeakSanitizer is not linked in, these functions become no-op stubs.
#include "absl/debugging/leak_check.h"
#ifndef LEAK_SANITIZER #include "absl/debugging/leak_check.h"
namespace absl { #include "absl/base/attributes.h"
ABSL_NAMESPACE_BEGIN #include "absl/base/config.h"
bool HaveLeakSanitizer() { return false; }
bool LeakCheckerIsActive() { return false; }
void DoIgnoreLeak(const void*) { }
void RegisterLivePointers(const void*, size_t) { }
void UnRegisterLivePointers(const void*, size_t) { }
LeakCheckDisabler::LeakCheckDisabler() { }
LeakCheckDisabler::~LeakCheckDisabler() { }
ABSL_NAMESPACE_END
} // namespace absl
#else #if defined(ABSL_HAVE_LEAK_SANITIZER)
#include <sanitizer/lsan_interface.h> #include <sanitizer/lsan_interface.h>
...@@ -66,4 +56,18 @@ LeakCheckDisabler::~LeakCheckDisabler() { __lsan_enable(); } ...@@ -66,4 +56,18 @@ LeakCheckDisabler::~LeakCheckDisabler() { __lsan_enable(); }
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
#endif // LEAK_SANITIZER #else // defined(ABSL_HAVE_LEAK_SANITIZER)
namespace absl {
ABSL_NAMESPACE_BEGIN
bool HaveLeakSanitizer() { return false; }
bool LeakCheckerIsActive() { return false; }
void DoIgnoreLeak(const void*) { }
void RegisterLivePointers(const void*, size_t) { }
void UnRegisterLivePointers(const void*, size_t) { }
LeakCheckDisabler::LeakCheckDisabler() { }
LeakCheckDisabler::~LeakCheckDisabler() { }
ABSL_NAMESPACE_END
} // namespace absl
#endif // defined(ABSL_HAVE_LEAK_SANITIZER)
...@@ -24,7 +24,24 @@ ...@@ -24,7 +24,24 @@
// Note: this leak checking API is not yet supported in MSVC. // Note: this leak checking API is not yet supported in MSVC.
// Leak checking is enabled by default in all ASan builds. // Leak checking is enabled by default in all ASan builds.
// //
// See https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer // https://clang.llvm.org/docs/LeakSanitizer.html
// https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer
//
// GCC and Clang both automatically enable LeakSanitizer when AddressSanitizer
// is enabled. To use the mode, simply pass `-fsanitize=address` to both the
// compiler and linker. An example Bazel command could be
//
// $ bazel test --copt=-fsanitize=address --linkopt=-fsanitize=address ...
//
// GCC and Clang auto support a standalone LeakSanitizer mode (a mode which does
// not also use AddressSanitizer). To use the mode, simply pass
// `-fsanitize=leak` to both the compiler and linker. Since GCC does not
// currently provide a way of detecting this mode at compile-time, GCC users
// must also pass -DLEAK_SANIITIZER to the compiler. An example Bazel command
// could be
//
// $ bazel test --copt=-DLEAK_SANITIZER --copt=-fsanitize=leak
// --linkopt=-fsanitize=leak ...
// //
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef ABSL_DEBUGGING_LEAK_CHECK_H_ #ifndef ABSL_DEBUGGING_LEAK_CHECK_H_
......
// Copyright 2017 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.
// Disable LeakSanitizer when this file is linked in.
// This function overrides __lsan_is_turned_off from sanitizer/lsan_interface.h
extern "C" int __lsan_is_turned_off();
extern "C" int __lsan_is_turned_off() {
return 1;
}
...@@ -15,27 +15,24 @@ ...@@ -15,27 +15,24 @@
#include <string> #include <string>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/base/config.h"
#include "absl/base/internal/raw_logging.h" #include "absl/base/internal/raw_logging.h"
#include "absl/debugging/leak_check.h" #include "absl/debugging/leak_check.h"
namespace { namespace {
TEST(LeakCheckTest, DetectLeakSanitizer) {
#ifdef ABSL_EXPECT_LEAK_SANITIZER
EXPECT_TRUE(absl::HaveLeakSanitizer());
EXPECT_TRUE(absl::LeakCheckerIsActive());
#else
EXPECT_FALSE(absl::HaveLeakSanitizer());
EXPECT_FALSE(absl::LeakCheckerIsActive());
#endif
}
TEST(LeakCheckTest, IgnoreLeakSuppressesLeakedMemoryErrors) { TEST(LeakCheckTest, IgnoreLeakSuppressesLeakedMemoryErrors) {
if (!absl::LeakCheckerIsActive()) {
GTEST_SKIP() << "LeakChecker is not active";
}
auto foo = absl::IgnoreLeak(new std::string("some ignored leaked string")); auto foo = absl::IgnoreLeak(new std::string("some ignored leaked string"));
ABSL_RAW_LOG(INFO, "Ignoring leaked string %s", foo->c_str()); ABSL_RAW_LOG(INFO, "Ignoring leaked string %s", foo->c_str());
} }
TEST(LeakCheckTest, LeakCheckDisablerIgnoresLeak) { TEST(LeakCheckTest, LeakCheckDisablerIgnoresLeak) {
if (!absl::LeakCheckerIsActive()) {
GTEST_SKIP() << "LeakChecker is not active";
}
absl::LeakCheckDisabler disabler; absl::LeakCheckDisabler disabler;
auto foo = new std::string("some string leaked while checks are disabled"); auto foo = new std::string("some string leaked while checks are disabled");
ABSL_RAW_LOG(INFO, "Ignoring leaked string %s", foo->c_str()); ABSL_RAW_LOG(INFO, "Ignoring leaked string %s", foo->c_str());
......
// Copyright 2022 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/attributes.h"
#include "absl/base/config.h"
#include "absl/base/optimization.h"
#include "absl/debugging/stacktrace.h"
#include "benchmark/benchmark.h"
namespace absl {
ABSL_NAMESPACE_BEGIN
namespace {
static constexpr int kMaxStackDepth = 100;
static constexpr int kCacheSize = (1 << 16);
void* pcs[kMaxStackDepth];
ABSL_ATTRIBUTE_NOINLINE void func(benchmark::State& state, int x, int depth) {
if (x <= 0) {
// Touch a significant amount of memory so that the stack is likely to be
// not cached in the L1 cache.
state.PauseTiming();
int* arr = new int[kCacheSize];
for (int i = 0; i < kCacheSize; ++i) benchmark::DoNotOptimize(arr[i] = 100);
delete[] arr;
state.ResumeTiming();
benchmark::DoNotOptimize(absl::GetStackTrace(pcs, depth, 0));
return;
}
ABSL_BLOCK_TAIL_CALL_OPTIMIZATION();
func(state, --x, depth);
}
void BM_GetStackTrace(benchmark::State& state) {
int depth = state.range(0);
for (auto s : state) {
func(state, depth, depth);
}
}
BENCHMARK(BM_GetStackTrace)->DenseRange(10, kMaxStackDepth, 10);
} // namespace
ABSL_NAMESPACE_END
} // namespace absl
...@@ -854,7 +854,9 @@ ABSL_RETIRED_FLAG(bool, old_bool_flag, true, "old descr"); ...@@ -854,7 +854,9 @@ ABSL_RETIRED_FLAG(bool, old_bool_flag, true, "old descr");
ABSL_RETIRED_FLAG(int, old_int_flag, (int)std::sqrt(10), "old descr"); ABSL_RETIRED_FLAG(int, old_int_flag, (int)std::sqrt(10), "old descr");
ABSL_RETIRED_FLAG(std::string, old_str_flag, "", absl::StrCat("old ", "descr")); ABSL_RETIRED_FLAG(std::string, old_str_flag, "", absl::StrCat("old ", "descr"));
bool initializaion_order_fiasco_test = [] { namespace {
bool initialization_order_fiasco_test ABSL_ATTRIBUTE_UNUSED = [] {
// Iterate over all the flags during static initialization. // Iterate over all the flags during static initialization.
// This should not trigger ASan's initialization-order-fiasco. // This should not trigger ASan's initialization-order-fiasco.
auto* handle1 = absl::FindCommandLineFlag("flag_on_separate_file"); auto* handle1 = absl::FindCommandLineFlag("flag_on_separate_file");
...@@ -865,8 +867,6 @@ bool initializaion_order_fiasco_test = [] { ...@@ -865,8 +867,6 @@ bool initializaion_order_fiasco_test = [] {
return true; return true;
}(); }();
namespace {
TEST_F(FlagTest, TestRetiredFlagRegistration) { TEST_F(FlagTest, TestRetiredFlagRegistration) {
auto* handle = absl::FindCommandLineFlag("old_bool_flag"); auto* handle = absl::FindCommandLineFlag("old_bool_flag");
EXPECT_TRUE(handle->IsOfType<bool>()); EXPECT_TRUE(handle->IsOfType<bool>());
......
...@@ -47,8 +47,10 @@ struct UDT { ...@@ -47,8 +47,10 @@ struct UDT {
UDT(const UDT&) = default; UDT(const UDT&) = default;
UDT& operator=(const UDT&) = default; UDT& operator=(const UDT&) = default;
}; };
bool AbslParseFlag(absl::string_view, UDT*, std::string*) { return true; } static bool AbslParseFlag(absl::string_view, UDT*, std::string*) {
std::string AbslUnparseFlag(const UDT&) { return "UDT{}"; } return true;
}
static std::string AbslUnparseFlag(const UDT&) { return "UDT{}"; }
ABSL_FLAG(UDT, usage_reporting_test_flag_05, {}, ABSL_FLAG(UDT, usage_reporting_test_flag_05, {},
"usage_reporting_test_flag_05 help message"); "usage_reporting_test_flag_05 help message");
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
namespace hash_internal { namespace hash_internal {
namespace {
static const uint64_t k0 = 0xc3a5c85c97cb3127ULL; static const uint64_t k0 = 0xc3a5c85c97cb3127ULL;
static const uint64_t kSeed0 = 1234567; static const uint64_t kSeed0 = 1234567;
...@@ -590,6 +591,7 @@ TEST(CityHashTest, Unchanging) { ...@@ -590,6 +591,7 @@ TEST(CityHashTest, Unchanging) {
TestUnchanging(testdata[i], 0, kDataSize); TestUnchanging(testdata[i], 0, kDataSize);
} }
} // namespace
} // namespace hash_internal } // namespace hash_internal
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
...@@ -29,6 +29,7 @@ using ::testing::Ge; ...@@ -29,6 +29,7 @@ using ::testing::Ge;
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
namespace profiling_internal { namespace profiling_internal {
namespace {
MATCHER_P2(IsBetween, a, b, MATCHER_P2(IsBetween, a, b,
absl::StrCat(std::string(negation ? "isn't" : "is"), " between ", a, absl::StrCat(std::string(negation ? "isn't" : "is"), " between ", a,
...@@ -194,6 +195,7 @@ TEST(ExponentialBiasedTest, InitializationModes) { ...@@ -194,6 +195,7 @@ TEST(ExponentialBiasedTest, InitializationModes) {
EXPECT_THAT(eb_stack.GetSkipCount(2), Ge(0)); EXPECT_THAT(eb_stack.GetSkipCount(2), Ge(0));
} }
} // namespace
} // namespace profiling_internal } // namespace profiling_internal
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
...@@ -719,6 +719,7 @@ TEST_F(FormatWrapperTest, ParsedFormat) { ...@@ -719,6 +719,7 @@ TEST_F(FormatWrapperTest, ParsedFormat) {
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
namespace {
using FormatExtensionTest = ::testing::Test; using FormatExtensionTest = ::testing::Test;
struct Point { struct Point {
...@@ -750,6 +751,7 @@ TEST_F(FormatExtensionTest, AbslFormatConvertExample) { ...@@ -750,6 +751,7 @@ TEST_F(FormatExtensionTest, AbslFormatConvertExample) {
// FormatUntyped will return false for bad character. // FormatUntyped will return false for bad character.
EXPECT_FALSE(absl::FormatUntyped(&actual, f1, {absl::FormatArg(p)})); EXPECT_FALSE(absl::FormatUntyped(&actual, f1, {absl::FormatArg(p)}));
} }
} // namespace
// Some codegen thunks that we can use to easily dump the generated assembly for // Some codegen thunks that we can use to easily dump the generated assembly for
// different StrFormat calls. // different StrFormat calls.
......
...@@ -97,8 +97,8 @@ cc_library( ...@@ -97,8 +97,8 @@ cc_library(
deps = [ deps = [
":graphcycles_internal", ":graphcycles_internal",
":kernel_timeout_internal", ":kernel_timeout_internal",
"//absl/base",
"//absl/base:atomic_hook", "//absl/base:atomic_hook",
"//absl/base",
"//absl/base:base_internal", "//absl/base:base_internal",
"//absl/base:config", "//absl/base:config",
"//absl/base:core_headers", "//absl/base:core_headers",
...@@ -108,7 +108,9 @@ cc_library( ...@@ -108,7 +108,9 @@ cc_library(
"//absl/debugging:stacktrace", "//absl/debugging:stacktrace",
"//absl/debugging:symbolize", "//absl/debugging:symbolize",
"//absl/time", "//absl/time",
], ] + select({
"//conditions:default": [],
}),
) )
cc_test( cc_test(
......
...@@ -85,7 +85,11 @@ cc_library( ...@@ -85,7 +85,11 @@ cc_library(
deps = [ deps = [
":civil_time", ":civil_time",
"//absl/base:config", "//absl/base:config",
], ] + select(
{
"//conditions:default": [],
},
),
) )
### tests ### tests
......
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