Skip to content

Commit

Permalink
fix: Return default value from ‘GetCacheTypeString’ (google#162)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kriskwiatkowski authored Jun 25, 2021
1 parent 646b80f commit 001faef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/cpu_features_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
1 change: 1 addition & 0 deletions src/utils/list_cpu_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 001faef

Please sign in to comment.