Skip to content

Commit 0a87fff

Browse files
laramielcopybara-github
authored andcommitted
Fix a few compilation warnings and metric asan issues
PiperOrigin-RevId: 940906248 Change-Id: Icccc528ae1e169a8bb24eb97e7d2e7f191eb4a15
1 parent a976c5a commit 0a87fff

4 files changed

Lines changed: 27 additions & 10 deletions

File tree

.bazelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ build:msvc --per_file_copt=grpc/.*\\.cc$@/wd4244
7575
build:msvc --host_per_file_copt=grpc/.*\\.cc$@/wd4244
7676
build:msvc --per_file_copt=external/xds/.*\\.cc$@/wd4244
7777
build:msvc --host_per_file_copt=external/xds/.*\\.cc$@/wd4244
78+
build:msvc --per_file_copt=grpc/.*$@/wd4715
79+
build:msvc --host_per_file_copt=grpc/.*$@/wd4715
80+
81+
# Silence macro redefinition warnings from AWS SDK
82+
build:msvc --per_file_copt=external/aws_c_.*$@/wd4005
83+
build:msvc --host_per_file_copt=external/aws_c_.*$@/wd4005
84+
85+
# Silence not all control paths return a value warnings from protobuf
86+
build:msvc --per_file_copt=external/com_google_protobuf/.*$@/wd4715
87+
build:msvc --host_per_file_copt=external/com_google_protobuf/.*$@/wd4715
88+
7889

7990
# ----------------------------------------
8091
# Disable warnings

tensorstore/internal/metrics/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ tensorstore_cc_library(
136136
deps = [
137137
":domain_field",
138138
"@abseil-cpp//absl/base:core_headers",
139+
"@abseil-cpp//absl/base:dynamic_annotations",
139140
"@abseil-cpp//absl/container:node_hash_map",
140141
"@abseil-cpp//absl/debugging:leak_check",
141142
"@abseil-cpp//absl/functional:function_ref",

tensorstore/internal/metrics/metric_impl.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <type_traits>
2929
#include <utility>
3030

31+
#include "absl/base/dynamic_annotations.h"
3132
#include "absl/base/optimization.h"
3233
#include "absl/container/node_hash_map.h"
3334
#include "absl/debugging/leak_check.h"
@@ -88,6 +89,7 @@ size_t MetricThreadCounter();
8889
template <typename T>
8990
T* LazyInit(std::atomic<T*>& ptr) {
9091
T* p = ptr.load(std::memory_order_acquire);
92+
ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(&p, sizeof(p));
9193
if (ABSL_PREDICT_FALSE(!p)) {
9294
auto* candidate = absl::IgnoreLeak(new T());
9395
T* expected = nullptr;
@@ -326,8 +328,7 @@ class AbstractMetric {
326328
using field_values_type = typename Key::tuple_type;
327329
using value_type = typename Cell::value_type;
328330

329-
constexpr AbstractMetric() : state_(nullptr) {}
330-
331+
constexpr AbstractMetric() = default;
331332
~AbstractMetric() {
332333
// NOTE: State* should be "eternal", so we just leak it.
333334
}
@@ -384,14 +385,14 @@ class AbstractMetric {
384385
private:
385386
State* GetState() const { return LazyInit(state_); }
386387

387-
mutable std::atomic<State*> state_;
388+
mutable std::atomic<State*> state_{nullptr};
388389
};
389390

390391
// Lock-free Specialization for no fields using a sharded counter.
391392
template <typename Cell>
392393
class AbstractMetric<Cell, true> {
393394
public:
394-
static constexpr bool kNumThreads = 4;
395+
static constexpr size_t kNumThreads = 4;
395396
using field_values_type = std::tuple<>;
396397
using value_type = typename Cell::value_type;
397398

@@ -432,7 +433,7 @@ class AbstractMetric<Cell, true> {
432433
template <typename Cell, typename Enable = void>
433434
class CellStorage {
434435
public:
435-
constexpr CellStorage() : value_() {}
436+
constexpr CellStorage() = default;
436437
~CellStorage() = default;
437438

438439
Cell* Get() const { return &value_; }
@@ -447,7 +448,7 @@ template <typename Cell>
447448
class CellStorage<Cell,
448449
std::enable_if_t<!std::is_trivially_destructible_v<Cell>>> {
449450
public:
450-
constexpr CellStorage() : ptr_(nullptr) {}
451+
constexpr CellStorage() = default;
451452
~CellStorage() {
452453
// NOTE: Cell* should be "eternal", so we just leak it.
453454
}
@@ -462,7 +463,7 @@ class CellStorage<Cell,
462463
}
463464

464465
private:
465-
mutable std::atomic<Cell*> ptr_;
466+
mutable std::atomic<Cell*> ptr_{nullptr};
466467
};
467468

468469
// Lock-free Specialization for no fields.

tensorstore/util/span.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ struct SpanTypeHelper<T, std::void_t<internal_span::ContainerElementType<T>>> {
115115
constexpr static ptrdiff_t extent = dynamic_extent;
116116
};
117117

118-
constexpr inline ptrdiff_t SubspanExtent(ptrdiff_t extent, ptrdiff_t offset,
119-
ptrdiff_t count) {
118+
constexpr ptrdiff_t SubspanExtent(ptrdiff_t extent, ptrdiff_t offset,
119+
ptrdiff_t count) {
120120
return count == dynamic_extent && extent == dynamic_extent ? dynamic_extent
121121
: count == dynamic_extent ? extent - offset
122122
: count;
@@ -404,7 +404,7 @@ class span {
404404
if (ABSL_PREDICT_TRUE(i < size() && i >= 0)) {
405405
return *(data() + i);
406406
}
407-
ABSL_LOG(FATAL) << "span.at(" << i << (i >= 0 ? ") >= size()" : ") i < 0");
407+
AtFatal(i);
408408
}
409409

410410
/// Returns a reference to the first element.
@@ -440,6 +440,10 @@ class span {
440440
std::conditional_t<Extent == dynamic_extent, ptrdiff_t,
441441
std::integral_constant<ptrdiff_t, Extent>>
442442
size_;
443+
444+
[[noreturn]] void AtFatal(ptrdiff_t i) const {
445+
ABSL_LOG(FATAL) << "span.at(" << i << (i >= 0 ? ") >= size()" : ") i < 0");
446+
}
443447
};
444448

445449
template <typename T>

0 commit comments

Comments
 (0)