Add DAWN_UNUSED_FUNC to ignore unused functions in generated code
BUG=dawn:13
Change-Id: I7a224503d0a33ef148e63b8327a6a53df1b3868a
Reviewed-on: https://dawn-review.googlesource.com/1520
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/generator/templates/dawn_wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp
index 1ca77dd..d9d2f4c 100644
--- a/generator/templates/dawn_wire/WireCmd.cpp
+++ b/generator/templates/dawn_wire/WireCmd.cpp
@@ -135,6 +135,9 @@
return result;
}
+ // GetExtraRequiredSize isn't used for structures that are value members of other structures
+ // because we assume they cannot contain pointers themselves.
+ DAWN_UNUSED_FUNC({{name}}GetExtraRequiredSize);
//* Serializes `record` into `transfer`, using `buffer` to get more space for pointed-to data
//* and `provider` to serialize objects.
diff --git a/src/common/Compiler.h b/src/common/Compiler.h
index e25b635..9d828be 100644
--- a/src/common/Compiler.h
+++ b/src/common/Compiler.h
@@ -23,6 +23,7 @@
// - DAWN_(UN)?LIKELY(EXPR): Where available, hints the compiler that the expression will be true
// (resp. false) to help it generate code that leads to better branch prediction.
// - DAWN_UNUSED(EXPR): Prevents unused variable/expression warnings on EXPR.
+// - DAWN_UNUSED_FUNC(FUNC): Prevents unused function warnings on FUNC.
// Clang and GCC, check for __clang__ too to catch clang-cl masquarading as MSVC
#if defined(__GNUC__) || defined(__clang__)
@@ -75,6 +76,8 @@
// It seems that (void) EXPR works on all compilers to silence the unused variable warning.
#define DAWN_UNUSED(EXPR) (void)EXPR
+// Likewise using static asserting on sizeof(&FUNC) seems to make it tagged as used
+#define DAWN_UNUSED_FUNC(FUNC) static_assert(sizeof(&FUNC) == sizeof(void (*)()), "");
// Add noop replacements for macros for features that aren't supported by the compiler.
#if !defined(DAWN_LIKELY)