From 001faefdc327e7013a581b99e3cdcbe0ba968277 Mon Sep 17 00:00:00 2001 From: Kris Kwiatkowski Date: Fri, 25 Jun 2021 09:28:26 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20Return=20default=20value=20from=20?= =?UTF-8?q?=E2=80=98GetCacheTypeString=E2=80=99=20(#162)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The build fails with following message when -Werror and -Werror=return-type are enabled. In function ‘GetCacheTypeString’: error: control reaches end of non-void function [-Werror=return-type] Simple fix is to return explicitly communicate to the compiler that certain block is not reachable. --- include/cpu_features_macros.h | 13 +++++++++++++ src/utils/list_cpu_features.c | 1 + 2 files changed, 14 insertions(+) diff --git a/include/cpu_features_macros.h b/include/cpu_features_macros.h index 4b231a1..15f7368 100644 --- a/include/cpu_features_macros.h +++ b/include/cpu_features_macros.h @@ -213,4 +213,17 @@ #endif // defined(__mips_msa) #endif // defined(CPU_FEATURES_ARCH_MIPS) +//////////////////////////////////////////////////////////////////////////////// +// Utils +//////////////////////////////////////////////////////////////////////////////// + +// Communicates to the compiler that the block is unreachable +#if defined(CPU_FEATURES_COMPILER_CLANG) || defined(CPU_FEATURES_COMPILER_GCC) +#define UNREACHABLE() __builtin_unreachable() +#elif defined(CPU_FEATURES_COMPILER_MSC) +#define UNREACHABLE() __assume(0) +#else +#define UNREACHABLE() +#endif + #endif // CPU_FEATURES_INCLUDE_CPU_FEATURES_MACROS_H_ diff --git a/src/utils/list_cpu_features.c b/src/utils/list_cpu_features.c index c80ffc5..4389f20 100644 --- a/src/utils/list_cpu_features.c +++ b/src/utils/list_cpu_features.c @@ -340,6 +340,7 @@ static Node* GetCacheTypeString(CacheType cache_type) { case CPU_FEATURE_CACHE_PREFETCH: return CreateConstantString("prefetch"); } + UNREACHABLE(); } static void AddCacheInfo(Node* root, const CacheInfo* cache_info) {