Skip to content

Commit 1cc25c4

Browse files
committed
Refactor more code to adhere to a stricter set of warnings
1 parent 4ec9f8b commit 1cc25c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+198
-132
lines changed

source/.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ build:asan -c dbg --copt='-fsanitize=address' --copt='-fno-omit-frame-pointer' -
2828

2929
# For profiling builds
3030
build:profile -c dbg --copt='-fno-omit-frame-pointer'
31+
32+
# Build with warnings as errors in CI
33+
build:ci --copt='-Werror'

source/bazel/cc.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ _warnings = [
1717
# We're okay with these for now, but should refactor to remove if we can
1818
"-Wno-global-constructors",
1919
"-Wno-exit-time-destructors",
20+
21+
# It's okay if we use `default` in switch statements
22+
"-Wno-switch-enum",
23+
24+
# Flexible array members
25+
"-Wno-c99-extensions",
2026
]
2127

2228
_test_warnings = _warnings + [

source/neuropod/BUILD

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
# limitations under the License.
1414

1515
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
16+
load("//bazel:cc.bzl", "neuropod_cc_binary", "neuropod_cc_library")
1617

17-
cc_library(
18+
neuropod_cc_library(
1819
name = "neuropod_hdrs",
1920
hdrs = [
2021
"neuropod.hh",
@@ -31,15 +32,15 @@ cc_library(
3132
],
3233
)
3334

34-
cc_library(
35+
neuropod_cc_library(
3536
name = "options",
3637
hdrs = ["options.hh"],
3738
visibility = [
3839
"//visibility:public",
3940
],
4041
)
4142

42-
cc_binary(
43+
neuropod_cc_binary(
4344
name = "libneuropod.so",
4445
linkopts = select({
4546
"@bazel_tools//src/conditions:darwin": ["-Wl,-rpath,@loader_path"],
@@ -55,7 +56,7 @@ cc_binary(
5556
],
5657
)
5758

58-
cc_library(
59+
neuropod_cc_library(
5960
name = "neuropod_impl",
6061
srcs = [
6162
"neuropod.cc",

source/neuropod/backends/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
# limitations under the License.
1414

1515
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
16+
load("//bazel:cc.bzl", "neuropod_cc_library")
1617

17-
cc_library(
18+
neuropod_cc_library(
1819
name = "neuropod_backend",
1920
srcs = [
2021
"neuropod_backend.cc",

source/neuropod/backends/neuropod_backend.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void validate_tensors_against_specs(const NeuropodValueMap & tensors,
129129
}
130130

131131
// Validate the shape
132-
for (int i = 0; i < spec.dims.size(); i++)
132+
for (size_t i = 0; i < spec.dims.size(); i++)
133133
{
134134
auto dim = tensor->get_dims()[i];
135135
auto expected = spec.dims[i];
@@ -318,7 +318,7 @@ std::unique_ptr<NeuropodValueMap> NeuropodBackend::infer_internal(const Neuropod
318318
return out;
319319
}
320320

321-
std::unique_ptr<NeuropodValueMap> NeuropodBackend::infer_internal(const NeuropodValueMap &inputs)
321+
std::unique_ptr<NeuropodValueMap> NeuropodBackend::infer_internal(const NeuropodValueMap & /*unused*/)
322322
{
323323
NEUROPOD_ERROR("Backend implementations must provide a `infer_internal` implementation");
324324
}

source/neuropod/backends/python_bridge/BUILD

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
# limitations under the License.
1414

1515
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
16+
load("//bazel:cc.bzl", "neuropod_cc_binary", "neuropod_cc_library")
1617

17-
cc_binary(
18+
neuropod_cc_binary(
1819
name = "libneuropod_pythonbridge_backend.so",
1920
srcs = [
2021
"//neuropod:libneuropod.so",
@@ -33,7 +34,7 @@ cc_binary(
3334
],
3435
)
3536

36-
cc_library(
37+
neuropod_cc_library(
3738
name = "python_bridge",
3839
srcs = [
3940
"python_bridge.cc",

source/neuropod/backends/tensorflow/BUILD

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
1616
load("//bazel:copy_libs.bzl", "copy_libs")
17+
load("//bazel:cc.bzl", "neuropod_cc_binary", "neuropod_cc_library")
1718

18-
cc_binary(
19+
neuropod_cc_binary(
1920
name = "libneuropod_tensorflow_backend.so",
2021
srcs = [
2122
"//neuropod:libneuropod.so",
@@ -37,7 +38,7 @@ cc_binary(
3738
],
3839
)
3940

40-
cc_library(
41+
neuropod_cc_library(
4142
name = "tensorflow_backend",
4243
srcs = [
4344
"tf_backend.cc",

source/neuropod/backends/tensorflow/tf_backend.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ void TensorflowNeuropodBackend::load_model_internal()
186186

187187
// Create a buffer of the right size
188188
graph_stream->seekg(0, graph_stream->end);
189-
std::streamsize graph_length = graph_stream->tellg();
189+
auto graph_length = static_cast<size_t>(graph_stream->tellg());
190190
std::vector<char> buffer(graph_length);
191191

192192
// Read into the buffer
193193
graph_stream->seekg(0, graph_stream->beg);
194-
graph_stream->read(buffer.data(), graph_length);
194+
graph_stream->read(buffer.data(), static_cast<std::streamsize>(graph_length));
195195
if (graph_stream->fail())
196196
{
197197
NEUROPOD_ERROR("Error reading TensorFlow GraphDef for neuropod {}", neuropod_path_);

source/neuropod/backends/tensorflow/tf_tensor.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class NeuropodTensorBuffer : public tensorflow::TensorBuffer
8181

8282
void FillAllocationDescription(tensorflow::AllocationDescription *proto) const override
8383
{
84-
tensorflow::int64 rb = size();
84+
auto rb = static_cast<tensorflow::int64>(size());
8585
proto->set_requested_bytes(rb);
8686
proto->set_allocator_name(tensorflow::cpu_allocator()->Name());
8787
}
@@ -116,11 +116,11 @@ tensorflow::TensorShape get_tf_shape(const std::vector<int64_t> &dims)
116116
// Convert shapes
117117
std::vector<int64_t> get_dims(const tensorflow::Tensor &tensor)
118118
{
119-
int num_dims = tensor.dims();
119+
auto num_dims = static_cast<size_t>(tensor.dims());
120120
std::vector<int64_t> shape(num_dims);
121-
for (int i = 0; i < num_dims; i++)
121+
for (size_t i = 0; i < num_dims; i++)
122122
{
123-
shape[i] = tensor.dim_size(i);
123+
shape[i] = tensor.dim_size(static_cast<int>(i));
124124
}
125125

126126
return shape;

source/neuropod/backends/tensorflow/tf_tensor.hh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,26 +160,26 @@ public:
160160
void copy_from(const std::vector<std::string> &data)
161161
{
162162
auto flat = tensor_.flat<StringType>();
163-
if (data.size() != flat.size())
163+
if (data.size() != static_cast<size_t>(flat.size()))
164164
{
165165
NEUROPOD_ERROR("Supplied vector size ({}) does not match size of tensor ({})", data.size(), flat.size());
166166
}
167167

168-
for (int i = 0; i < data.size(); i++)
168+
for (size_t i = 0; i < data.size(); i++)
169169
{
170-
flat(i) = data[i];
170+
flat(static_cast<long>(i)) = data[i];
171171
}
172172
}
173173

174174
tensorflow::Tensor &get_native_data() { return tensor_; }
175175

176176
protected:
177-
std::string get(size_t index) const { return tensor_.flat<StringType>()(index); }
177+
std::string get(size_t index) const { return tensor_.flat<StringType>()(static_cast<long>(index)); }
178178

179179
void set(size_t index, const std::string &value)
180180
{
181-
auto flat = tensor_.flat<StringType>();
182-
flat(index) = value;
181+
auto flat = tensor_.flat<StringType>();
182+
flat(static_cast<long>(index)) = value;
183183
}
184184
};
185185

0 commit comments

Comments
 (0)