Add -Wc++14-compat to common TFLite warning opts

PiperOrigin-RevId: 351631306
Change-Id: Ie0b5b545d23751ce216a72a43d83d2b95dc4200d
This commit is contained in:
Jared Duke 2021-01-13 11:41:20 -08:00 committed by TensorFlower Gardener
parent ec31ec335a
commit 26c468322d
8 changed files with 62 additions and 65 deletions

View File

@ -1,5 +1,5 @@
load("//tensorflow:tensorflow.bzl", "if_not_windows", "tf_cc_test") load("//tensorflow:tensorflow.bzl", "if_not_windows", "tf_cc_test")
load("//tensorflow/lite:build_def.bzl", "tflite_cc_shared_object", "tflite_copts") load("//tensorflow/lite:build_def.bzl", "tflite_cc_shared_object", "tflite_copts", "tflite_copts_warnings")
load("//tensorflow/lite:special_rules.bzl", "internal_visibility_allowlist", "tflite_portable_test_suite") load("//tensorflow/lite:special_rules.bzl", "internal_visibility_allowlist", "tflite_portable_test_suite")
load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable") load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable")
@ -58,12 +58,6 @@ config_setting(
}, },
) )
TFLITE_DEFAULT_COPTS = if_not_windows([
"-Wall",
"-Wno-comment",
"-Wno-extern-c-compat",
])
FRAMEWORK_LIB_HDRS = [ FRAMEWORK_LIB_HDRS = [
"allocation.h", "allocation.h",
"context.h", "context.h",
@ -91,7 +85,7 @@ cc_library(
name = "version", name = "version",
hdrs = ["version.h"], hdrs = ["version.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
# Note that we only use the header defines from :version_lib. # Note that we only use the header defines from :version_lib.
deps = ["//tensorflow/core:version_lib"], deps = ["//tensorflow/core:version_lib"],
) )
@ -109,7 +103,7 @@ cc_library(
srcs = ["arena_planner.cc"], srcs = ["arena_planner.cc"],
hdrs = ["arena_planner.h"], hdrs = ["arena_planner.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
deps = [ deps = [
":graph_info", ":graph_info",
":memory_planner", ":memory_planner",
@ -140,7 +134,7 @@ cc_library(
name = "context", name = "context",
hdrs = ["context.h"], hdrs = ["context.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
deps = ["//tensorflow/lite/c:common"], deps = ["//tensorflow/lite/c:common"],
) )
@ -149,7 +143,7 @@ cc_library(
srcs = ["external_cpu_backend_context.cc"], srcs = ["external_cpu_backend_context.cc"],
hdrs = ["external_cpu_backend_context.h"], hdrs = ["external_cpu_backend_context.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
deps = [ deps = [
"//tensorflow/lite/c:common", "//tensorflow/lite/c:common",
], ],
@ -159,7 +153,7 @@ cc_library(
name = "graph_info", name = "graph_info",
hdrs = ["graph_info.h"], hdrs = ["graph_info.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
deps = ["//tensorflow/lite/c:common"], deps = ["//tensorflow/lite/c:common"],
) )
@ -167,7 +161,7 @@ cc_library(
name = "memory_planner", name = "memory_planner",
hdrs = ["memory_planner.h"], hdrs = ["memory_planner.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
deps = ["//tensorflow/lite/c:common"], deps = ["//tensorflow/lite/c:common"],
) )
@ -176,7 +170,7 @@ cc_library(
srcs = ["simple_memory_arena.cc"], srcs = ["simple_memory_arena.cc"],
hdrs = ["simple_memory_arena.h"], hdrs = ["simple_memory_arena.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
deps = ["//tensorflow/lite/c:common"], deps = ["//tensorflow/lite/c:common"],
) )
@ -211,7 +205,7 @@ cc_library(
"string_type.h", "string_type.h",
], ],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
) )
cc_library( cc_library(
@ -233,7 +227,7 @@ cc_library(
"allocation.h", "allocation.h",
], ],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
deps = [ deps = [
":string", ":string",
"//tensorflow/lite/c:common", "//tensorflow/lite/c:common",
@ -247,7 +241,7 @@ cc_library(
name = "framework_lib", name = "framework_lib",
hdrs = FRAMEWORK_LIB_HDRS, hdrs = FRAMEWORK_LIB_HDRS,
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
visibility = [ visibility = [
"//tensorflow/lite:__subpackages__", "//tensorflow/lite:__subpackages__",
], ],
@ -292,7 +286,7 @@ cc_library(
srcs = [], srcs = [],
hdrs = FRAMEWORK_LIB_HDRS, hdrs = FRAMEWORK_LIB_HDRS,
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
deps = [ deps = [
":allocation", ":allocation",
":arena_planner", ":arena_planner",
@ -335,7 +329,7 @@ cc_library(
"model_builder.h", "model_builder.h",
], ],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
visibility = [ visibility = [
"//tensorflow/lite/core/shims:__subpackages__", "//tensorflow/lite/core/shims:__subpackages__",
"//tensorflow/lite/kernels:__subpackages__", "//tensorflow/lite/kernels:__subpackages__",
@ -377,7 +371,7 @@ cc_library(
], ],
hdrs = ["optional_debug_tools.h"], hdrs = ["optional_debug_tools.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
visibility = [ visibility = [
"//visibility:public", "//visibility:public",
], ],
@ -393,7 +387,7 @@ cc_library(
name = "error_reporter", name = "error_reporter",
hdrs = ["error_reporter.h"], hdrs = ["error_reporter.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
visibility = [ visibility = [
"//visibility:public", "//visibility:public",
], ],
@ -408,7 +402,7 @@ cc_library(
srcs = ["stderr_reporter.cc"], srcs = ["stderr_reporter.cc"],
hdrs = ["stderr_reporter.h"], hdrs = ["stderr_reporter.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
visibility = [ visibility = [
"//visibility:public", "//visibility:public",
], ],
@ -423,7 +417,7 @@ cc_library(
name = "op_resolver", name = "op_resolver",
hdrs = ["op_resolver.h"], hdrs = ["op_resolver.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
visibility = [ visibility = [
"//visibility:public", "//visibility:public",
], ],
@ -438,7 +432,7 @@ cc_library(
srcs = ["mutable_op_resolver.cc"], srcs = ["mutable_op_resolver.cc"],
hdrs = ["mutable_op_resolver.h"], hdrs = ["mutable_op_resolver.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
visibility = [ visibility = [
"//visibility:public", "//visibility:public",
], ],
@ -454,7 +448,7 @@ cc_library(
srcs = ["string_util.cc"], srcs = ["string_util.cc"],
hdrs = ["string_util.h"], hdrs = ["string_util.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
deps = [ deps = [
":string", ":string",
"//tensorflow/lite/c:common", "//tensorflow/lite/c:common",
@ -466,7 +460,7 @@ cc_library(
cc_library( cc_library(
name = "tflite_with_xnnpack", name = "tflite_with_xnnpack",
srcs = ["tflite_with_xnnpack.cc"], srcs = ["tflite_with_xnnpack.cc"],
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
linkstatic = True, linkstatic = True,
deps = [ deps = [
"//tensorflow/lite/c:common", "//tensorflow/lite/c:common",
@ -517,7 +511,7 @@ cc_library(
"tflite_with_xnnpack_optional.h", "tflite_with_xnnpack_optional.h",
], ],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
deps = [ deps = [
"//tensorflow/lite/c:common", "//tensorflow/lite/c:common",
] + select({ ] + select({
@ -712,7 +706,7 @@ cc_library(
srcs = ["util.cc"], srcs = ["util.cc"],
hdrs = ["util.h"], hdrs = ["util.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS + tflite_copts(), copts = tflite_copts_warnings() + tflite_copts(),
deps = [ deps = [
":kernel_api", ":kernel_api",
"//tensorflow/lite/c:common", "//tensorflow/lite/c:common",
@ -766,7 +760,7 @@ cc_library(
}), }),
hdrs = ["minimal_logging.h"], hdrs = ["minimal_logging.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS + tflite_copts(), copts = tflite_copts_warnings() + tflite_copts(),
linkopts = select({ linkopts = select({
"//tensorflow:android": ["-llog"], "//tensorflow:android": ["-llog"],
"//conditions:default": [], "//conditions:default": [],

View File

@ -11,7 +11,7 @@ load("//tensorflow/lite/java:aar_with_jni.bzl", "aar_with_jni")
load("@build_bazel_rules_android//android:rules.bzl", "android_library") load("@build_bazel_rules_android//android:rules.bzl", "android_library")
def tflite_copts(): def tflite_copts():
"""Defines compile time flags.""" """Defines common compile time flags for TFLite libraries."""
copts = [ copts = [
"-DFARMHASH_NO_CXX_STRING", "-DFARMHASH_NO_CXX_STRING",
] + select({ ] + select({
@ -46,6 +46,27 @@ def tflite_copts():
return copts return copts
def tflite_copts_warnings():
"""Defines common warning flags used primarily by internal TFLite libraries."""
# TODO(b/155906820): Include with `tflite_copts()` after validating clients.
return select({
clean_dep("//tensorflow:windows"): [
# We run into trouble on Windows toolchains with warning flags,
# as mentioned in the comments below on each flag.
# We could be more aggressive in enabling supported warnings on each
# Windows toolchain, but we compromise with keeping BUILD files simple
# by limiting the number of config_setting's.
],
"//conditions:default": [
"-Wall",
# TensorFlow is C++14 at the moment. This flag ensures that we warn
# on any code that isn't C++14. Not supported by MSVC.
"-Wc++14-compat",
],
})
EXPORTED_SYMBOLS = clean_dep("//tensorflow/lite/java/src/main/native:exported_symbols.lds") EXPORTED_SYMBOLS = clean_dep("//tensorflow/lite/java/src/main/native:exported_symbols.lds")
LINKER_SCRIPT = clean_dep("//tensorflow/lite/java/src/main/native:version_script.lds") LINKER_SCRIPT = clean_dep("//tensorflow/lite/java/src/main/native:version_script.lds")

View File

@ -1,8 +1,7 @@
# Description: this package contains shim library targets that forward # Description: this package contains shim library targets that forward
# to the TF Lite C and C++ API targets. See README.md. # to the TF Lite C and C++ API targets. See README.md.
load("//tensorflow:tensorflow.bzl", "if_not_windows") load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_copts_warnings")
load("//tensorflow/lite:build_def.bzl", "tflite_copts")
load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite") load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite")
load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable") load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable")
load(":build_defs.bzl", "build_test") load(":build_defs.bzl", "build_test")
@ -12,12 +11,6 @@ package(
licenses = ["notice"], # Apache 2.0 licenses = ["notice"], # Apache 2.0
) )
TFLITE_DEFAULT_COPTS = if_not_windows([
"-Wall",
"-Wno-comment",
"-Wno-extern-c-compat",
])
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# C++ API # C++ API
@ -47,7 +40,7 @@ cc_library(
srcs = [], srcs = [],
hdrs = FRAMEWORK_LIB_HDRS + CC_API_HDRS, hdrs = FRAMEWORK_LIB_HDRS + CC_API_HDRS,
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
visibility = [ visibility = [
"//tensorflow/lite:__subpackages__", "//tensorflow/lite:__subpackages__",
"//tensorflow_lite_support:__subpackages__", "//tensorflow_lite_support:__subpackages__",
@ -79,7 +72,7 @@ cc_library(
srcs = [], srcs = [],
hdrs = CC_API_HDRS, hdrs = CC_API_HDRS,
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + tflite_copts_warnings(),
visibility = ["//tensorflow/lite:__pkg__"], visibility = ["//tensorflow/lite:__pkg__"],
deps = [ deps = [
"//tensorflow/lite:allocation", "//tensorflow/lite:allocation",
@ -139,7 +132,7 @@ cc_library(
name = "c_api", name = "c_api",
hdrs = ["c/c_api.h"], hdrs = ["c/c_api.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
visibility = [ visibility = [
"//tensorflow/lite:__subpackages__", "//tensorflow/lite:__subpackages__",
"//tensorflow_lite_support:__subpackages__", "//tensorflow_lite_support:__subpackages__",
@ -151,7 +144,7 @@ cc_library(
name = "c_api_experimental", name = "c_api_experimental",
hdrs = ["c/c_api_experimental.h"], hdrs = ["c/c_api_experimental.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
visibility = [ visibility = [
"//tensorflow/lite:__subpackages__", "//tensorflow/lite:__subpackages__",
"//tensorflow_lite_support:__subpackages__", "//tensorflow_lite_support:__subpackages__",
@ -163,7 +156,7 @@ cc_library(
name = "common", name = "common",
hdrs = ["c/common.h"], hdrs = ["c/common.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
visibility = [ visibility = [
"//tensorflow/lite:__subpackages__", "//tensorflow/lite:__subpackages__",
"//tensorflow_lite_support:__subpackages__", "//tensorflow_lite_support:__subpackages__",
@ -175,7 +168,7 @@ cc_library(
name = "builtin_op_data", name = "builtin_op_data",
hdrs = ["c/builtin_op_data.h"], hdrs = ["c/builtin_op_data.h"],
compatible_with = get_compatible_with_portable(), compatible_with = get_compatible_with_portable(),
copts = TFLITE_DEFAULT_COPTS, copts = tflite_copts_warnings(),
visibility = [ visibility = [
"//tensorflow/lite:__subpackages__", "//tensorflow/lite:__subpackages__",
"//tensorflow_lite_support:__subpackages__", "//tensorflow_lite_support:__subpackages__",

View File

@ -1,6 +1,5 @@
load("//tensorflow:tensorflow.bzl", "if_not_windows")
load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable") load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable")
load("//tensorflow/lite:build_def.bzl", "tflite_copts") load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_copts_warnings")
load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite_combined") load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite_combined")
package( package(
@ -8,7 +7,7 @@ package(
licenses = ["notice"], # Apache 2.0 licenses = ["notice"], # Apache 2.0
) )
common_copts = tflite_copts() + if_not_windows(["-Wall"]) common_copts = tflite_copts() + tflite_copts_warnings()
cc_library( cc_library(
name = "profiler", name = "profiler",

View File

@ -1,5 +1,5 @@
load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite") load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite")
load("//tensorflow/lite:build_def.bzl", "tflite_copts") load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_copts_warnings")
load("//tensorflow:tensorflow.bzl", "tf_cc_binary", "tf_cc_test") load("//tensorflow:tensorflow.bzl", "tf_cc_binary", "tf_cc_test")
package( package(
@ -13,8 +13,6 @@ exports_files([
"logging.h", "logging.h",
]) ])
common_copts = ["-Wall"]
py_binary( py_binary(
name = "visualize", name = "visualize",
srcs = ["visualize.py"], srcs = ["visualize.py"],
@ -236,7 +234,7 @@ cc_test(
cc_library( cc_library(
name = "logging", name = "logging",
hdrs = ["logging.h"], hdrs = ["logging.h"],
copts = common_copts, copts = tflite_copts_warnings(),
) )
cc_library( cc_library(

View File

@ -1,6 +1,6 @@
load("//tensorflow:tensorflow.bzl", "tf_cc_binary") load("//tensorflow:tensorflow.bzl", "tf_cc_binary")
load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite") load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite")
load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_linkopts") load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_copts_warnings", "tflite_linkopts")
package( package(
default_visibility = [ default_visibility = [
@ -9,7 +9,7 @@ package(
licenses = ["notice"], # Apache 2.0 licenses = ["notice"], # Apache 2.0
) )
common_copts = ["-Wall"] + tflite_copts() common_copts = tflite_copts() + tflite_copts_warnings()
# We create a library for benchmark_main.cc to faciliate the creation of a # We create a library for benchmark_main.cc to faciliate the creation of a
# customized benchmark model binary that only needs linking with extra # customized benchmark model binary that only needs linking with extra
@ -237,7 +237,6 @@ cc_test(
srcs = [ srcs = [
"benchmark_utils_test.cc", "benchmark_utils_test.cc",
], ],
copts = common_copts,
deps = [ deps = [
":benchmark_utils", ":benchmark_utils",
"//tensorflow/lite/profiling:time", "//tensorflow/lite/profiling:time",

View File

@ -1,4 +1,4 @@
load("//tensorflow/lite:build_def.bzl", "tflite_copts") load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_copts_warnings")
package( package(
default_visibility = [ default_visibility = [
@ -7,7 +7,7 @@ package(
licenses = ["notice"], # Apache 2.0 licenses = ["notice"], # Apache 2.0
) )
common_copts = ["-Wall"] + tflite_copts() common_copts = tflite_copts() + tflite_copts_warnings()
cc_library( cc_library(
name = "delegate_provider_hdr", name = "delegate_provider_hdr",

View File

@ -1,7 +1,6 @@
# Utilities for signature_defs in TFLite # Utilities for signature_defs in TFLite
load("//tensorflow:tensorflow.bzl", "pybind_extension") load("//tensorflow:tensorflow.bzl", "pybind_extension")
load("//tensorflow:tensorflow.bzl", "if_not_windows") load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_copts_warnings")
load("//tensorflow/lite:build_def.bzl", "tflite_copts")
load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite") load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite")
package( package(
@ -11,17 +10,11 @@ package(
licenses = ["notice"], # Apache 2.0 licenses = ["notice"], # Apache 2.0
) )
TFLITE_DEFAULT_COPTS = if_not_windows([
"-Wall",
"-Wno-comment",
"-Wno-extern-c-compat",
])
cc_library( cc_library(
name = "signature_def_util", name = "signature_def_util",
srcs = ["signature_def_util.cc"], srcs = ["signature_def_util.cc"],
hdrs = ["signature_def_util.h"], hdrs = ["signature_def_util.h"],
copts = TFLITE_DEFAULT_COPTS + tflite_copts(), copts = tflite_copts() + tflite_copts_warnings(),
deps = [ deps = [
"//tensorflow/core:lib_proto_parsing", "//tensorflow/core:lib_proto_parsing",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",