Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Return default value from ‘GetCacheTypeString’ #162

Merged

Conversation

kriskwiatkowski
Copy link
Contributor

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 0 from that function. The
return value is then checked by an assert in the
AddMapEntry. The assert will only work in debug mode,
but that seems to be enough.

@@ -340,6 +340,8 @@ static Node* GetCacheTypeString(CacheType cache_type) {
case CPU_FEATURE_CACHE_PREFETCH:
return CreateConstantString("prefetch");
}
/* Should never happen */
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -340,6 +340,8 @@ static Node* GetCacheTypeString(CacheType cache_type) {
case CPU_FEATURE_CACHE_PREFETCH:
return CreateConstantString("prefetch");
}
/* Should never happen */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this should never happen I'd rather use __builtin_unreachable() for clang/gcc and __assume(0) for MSVC.
Something along these lines:

#if defined(CPU_FEATURES_COMPILER_CLANG) || defined(CPU_FEATURES_COMPILER_GCC)
  __builtin_unreachable();
#elif defined(CPU_FEATURES_COMPILER_MSC)
  __assume(0);
#else
#error "Unsupported compiler."
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done. thanks, I wasn't aware of those builtins.
Instead of issuing an error for compiler other than MSC,GCC,clang I simply do nothing. In this unusual situation, it is a bit better as compilation may still work if something like -pedantic is not used.

@kriskwiatkowski kriskwiatkowski force-pushed the kris/fix_Werror_return_type branch 2 times, most recently from f0d43fa to 38f4324 Compare June 25, 2021 06:17
Copy link
Collaborator

@gchatelet gchatelet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx! I was about to suggest to add this to include/cpu_features_macros.h, you read my mind : )
One nit on a missing new line and this is good to go!

include/cpu_features_macros.h Show resolved Hide resolved
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.
@gchatelet gchatelet merged commit 001faef into google:master Jun 25, 2021
@kriskwiatkowski
Copy link
Contributor Author

Thanks!

@gchatelet gchatelet added this to the v0.7.0 milestone Mar 8, 2022
@gchatelet gchatelet added the misc non user facing: internal, cleanup, ci, release process label Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
misc non user facing: internal, cleanup, ci, release process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants