Fix minor warnings.
When compiling with -Wall/-Werror, several warnings related to signed/unsigned
comparison and an incorrect format string kill the build. Additionally, when
compiling under GCC 4.8.x, `max_align_t` is not a member of `std`. This change
fixes these minor errors.
PiperOrigin-RevId: 284012863
Change-Id: I52846f0125933d37788b766746c89ab6eb160d8f
diff --git a/tensorflow/lite/experimental/micro/micro_allocator.cc b/tensorflow/lite/experimental/micro/micro_allocator.cc
index 48a0901..82b3b35 100644
--- a/tensorflow/lite/experimental/micro/micro_allocator.cc
+++ b/tensorflow/lite/experimental/micro/micro_allocator.cc
@@ -42,19 +42,6 @@
// requirement for SIMD extensions.
constexpr int kBufferAlignment = 16;
-// If building with GCC 4.8.x or lower, `max_align_t` is not a member of `std`.
-// If using a newer version of GCC, we import `max_align_t` into the local
-// anonymous namespace to be able to use it like the global `max_align_t` from
-// the older clib.
-#ifdef __GNUC__
-#if __GNUC_PREREQ(4, 9)
-using std::max_align_t;
-#endif
-#else
-// We assume other compilers don't have this issue.
-using std::max_align_t;
-#endif
-
class MicroBuiltinDataAllocator : public BuiltinDataAllocator {
public:
explicit MicroBuiltinDataAllocator(SimpleMemoryAllocator* memory_allocator)
@@ -64,7 +51,7 @@
// Align to an address that is proper for all primitive types, but no more
// than the size.
return memory_allocator_->AllocateFromTail(
- size, std::min(size, alignof(max_align_t)));
+ size, std::min(size, alignof(std::max_align_t)));
}
void Deallocate(void* data) override {
// Do not deallocate, builtin data needs to be available for the life time
@@ -425,7 +412,7 @@
// If we've found a buffer, does it have any data?
if (auto* array = buffer->data()) {
// If it has any data, is the data size larger than zero?
- if (array->size()) {
+ if (size_t array_size = array->size()) {
// We've found a buffer with valid data, so update the runtime tensor
// data structure to point to it.
result->data.raw =
diff --git a/tensorflow/lite/experimental/micro/micro_interpreter.cc b/tensorflow/lite/experimental/micro/micro_interpreter.cc
index 7185d64..ba46cbf 100644
--- a/tensorflow/lite/experimental/micro/micro_interpreter.cc
+++ b/tensorflow/lite/experimental/micro/micro_interpreter.cc
@@ -21,7 +21,7 @@
namespace tflite {
namespace {
-const size_t kStackDataAllocatorSize = 128;
+const int kStackDataAllocatorSize = 128;
class StackDataAllocator : public BuiltinDataAllocator {
public:
void* Allocate(size_t size) override {
@@ -91,7 +91,7 @@
// NOTE: This requires that the flatbuffer is held in memory which can be
// modified by this process.
if (!FLATBUFFERS_LITTLEENDIAN) {
- for (size_t t = 0; t < tensors_size(); ++t) {
+ for (int t = 0; t < tensors_size(); ++t) {
TfLiteTensor* thisTensor = &context_.tensors[t];
if (thisTensor->allocation_type == kTfLiteMmapRo)
CorrectTensorEndianness(thisTensor);
diff --git a/tensorflow/lite/experimental/micro/micro_optional_debug_tools.cc b/tensorflow/lite/experimental/micro/micro_optional_debug_tools.cc
index 1f6ce53..e27317a 100644
--- a/tensorflow/lite/experimental/micro/micro_optional_debug_tools.cc
+++ b/tensorflow/lite/experimental/micro/micro_optional_debug_tools.cc
@@ -14,13 +14,6 @@
==============================================================================*/
#include "tensorflow/lite/experimental/micro/micro_optional_debug_tools.h"
-// `cinttypes` requires `__STDC_FORMAT_MACROS` to be defined to expose `PRId32`.
-#ifndef __STDC_FORMAT_MACROS
-#define __STDC_FORMAT_MACROS
-#endif
-
-#include <cinttypes>
-
#include "tensorflow/lite/schema/schema_generated.h"
namespace tflite {
namespace {
@@ -129,7 +122,7 @@
printf("Node %3zu Operator Custom Name %s\n", node_index,
reg->custom_name);
} else {
- printf("Node %3zu Operator Builtin Code %3" PRId32 " %s\n", node_index,
+ printf("Node %3zu Operator Builtin Code %3d %s\n", node_index,
reg->builtin_code, EnumNamesBuiltinOperator()[reg->builtin_code]);
}
printf(" Inputs:");
diff --git a/tensorflow/lite/experimental/micro/test_helpers.cc b/tensorflow/lite/experimental/micro/test_helpers.cc
index a1b9801..03e1d91 100644
--- a/tensorflow/lite/experimental/micro/test_helpers.cc
+++ b/tensorflow/lite/experimental/micro/test_helpers.cc
@@ -47,7 +47,7 @@
return *inst;
}
- static constexpr size_t kStackAllocatorSize = 4096;
+ static constexpr int kStackAllocatorSize = 4096;
private:
uint8_t data_backing_[kStackAllocatorSize];