Skip to content

Commit 1fdbe1e

Browse files
Abseil Teamderekmauro
authored andcommitted
Export of internal Abseil changes
-- 4b566a7deeba5db473c83f4924c1d182a002779f by Abseil Team <[email protected]>: Add absl::LeakCheckerIsActive to check whether a leak checker is built into the target and enabled. For LeakSanitizer, it is by default enabled unless __lsan_is_turned_off() is defined and returns true. PiperOrigin-RevId: 364654465 -- 0a56ff5310b66f9d1ff5e5e2a053335ecfb5c75b by Abseil Team <[email protected]>: Update absl::FromTM documentation to reflect implementation. PiperOrigin-RevId: 364388743 GitOrigin-RevId: 4b566a7deeba5db473c83f4924c1d182a002779f Change-Id: I8df35b761b532e79d620f484153083c3499ef55b
1 parent f3eff47 commit 1fdbe1e

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

absl/debugging/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ cc_library(
260260
visibility = ["//visibility:private"],
261261
deps = [
262262
"//absl/base:config",
263+
"//absl/base:core_headers",
263264
],
264265
)
265266

@@ -273,6 +274,7 @@ cc_library(
273274
visibility = ["//visibility:private"],
274275
deps = [
275276
"//absl/base:config",
277+
"//absl/base:core_headers",
276278
],
277279
)
278280

absl/debugging/leak_check.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
// When lsan is not linked in, these functions are not available,
1717
// therefore Abseil code which depends on these functions is conditioned on the
1818
// definition of LEAK_SANITIZER.
19+
#include "absl/base/attributes.h"
1920
#include "absl/debugging/leak_check.h"
2021

2122
#ifndef LEAK_SANITIZER
2223

2324
namespace absl {
2425
ABSL_NAMESPACE_BEGIN
2526
bool HaveLeakSanitizer() { return false; }
27+
bool LeakCheckerIsActive() { return false; }
2628
void DoIgnoreLeak(const void*) { }
2729
void RegisterLivePointers(const void*, size_t) { }
2830
void UnRegisterLivePointers(const void*, size_t) { }
@@ -35,9 +37,22 @@ ABSL_NAMESPACE_END
3537

3638
#include <sanitizer/lsan_interface.h>
3739

40+
#if ABSL_HAVE_ATTRIBUTE_WEAK
41+
extern "C" ABSL_ATTRIBUTE_WEAK int __lsan_is_turned_off();
42+
#endif
43+
3844
namespace absl {
3945
ABSL_NAMESPACE_BEGIN
4046
bool HaveLeakSanitizer() { return true; }
47+
48+
#if ABSL_HAVE_ATTRIBUTE_WEAK
49+
bool LeakCheckerIsActive() {
50+
return !(&__lsan_is_turned_off && __lsan_is_turned_off());
51+
}
52+
#else
53+
bool LeakCheckerIsActive() { return true; }
54+
#endif
55+
4156
bool FindAndReportLeaks() { return __lsan_do_recoverable_leak_check(); }
4257
void DoIgnoreLeak(const void* ptr) { __lsan_ignore_object(ptr); }
4358
void RegisterLivePointers(const void* ptr, size_t size) {

absl/debugging/leak_check.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ ABSL_NAMESPACE_BEGIN
4343
// currently built into this target.
4444
bool HaveLeakSanitizer();
4545

46+
// LeakCheckerIsActive()
47+
//
48+
// Returns true if a leak-checking sanitizer (either ASan or standalone LSan) is
49+
// currently built into this target and is turned on.
50+
bool LeakCheckerIsActive();
51+
4652
// DoIgnoreLeak()
4753
//
4854
// Implements `IgnoreLeak()` below. This function should usually

absl/debugging/leak_check_test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ namespace {
2323
TEST(LeakCheckTest, DetectLeakSanitizer) {
2424
#ifdef ABSL_EXPECT_LEAK_SANITIZER
2525
EXPECT_TRUE(absl::HaveLeakSanitizer());
26+
EXPECT_TRUE(absl::LeakCheckerIsActive());
2627
#else
2728
EXPECT_FALSE(absl::HaveLeakSanitizer());
29+
EXPECT_FALSE(absl::LeakCheckerIsActive());
2830
#endif
2931
}
3032

absl/time/time.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,11 +1180,15 @@ inline Time FromDateTime(int64_t year, int mon, int day, int hour,
11801180
//
11811181
// Converts the `tm_year`, `tm_mon`, `tm_mday`, `tm_hour`, `tm_min`, and
11821182
// `tm_sec` fields to an `absl::Time` using the given time zone. See ctime(3)
1183-
// for a description of the expected values of the tm fields. If the indicated
1184-
// time instant is not unique (see `absl::TimeZone::At(absl::CivilSecond)`
1185-
// above), the `tm_isdst` field is consulted to select the desired instant
1186-
// (`tm_isdst` > 0 means DST, `tm_isdst` == 0 means no DST, `tm_isdst` < 0
1187-
// means use the post-transition offset).
1183+
// for a description of the expected values of the tm fields. If the civil time
1184+
// is unique (see `absl::TimeZone::At(absl::CivilSecond)` above), the matching
1185+
// time instant is returned. Otherwise, the `tm_isdst` field is consulted to
1186+
// choose between the possible results. For a repeated civil time, `tm_isdst !=
1187+
// 0` returns the matching DST instant, while `tm_isdst == 0` returns the
1188+
// matching non-DST instant. For a skipped civil time there is no matching
1189+
// instant, so `tm_isdst != 0` returns the DST instant, and `tm_isdst == 0`
1190+
// returns the non-DST instant, that would have matched if the transition never
1191+
// happened.
11881192
Time FromTM(const struct tm& tm, TimeZone tz);
11891193

11901194
// ToTM()

0 commit comments

Comments
 (0)