Repository navigation
fix: Return default value from ‘GetCacheTypeString’ - #162
Merged
gchatelet merged 1 commit intoJun 25, 2021
Merged
Conversation
Mizux
reviewed
Jun 23, 2021
| return CreateConstantString("prefetch"); | ||
| } | ||
| /* Should never happen */ | ||
| return 0; |
Collaborator
There was a problem hiding this comment.
gchatelet
reviewed
Jun 24, 2021
| case CPU_FEATURE_CACHE_PREFETCH: | ||
| return CreateConstantString("prefetch"); | ||
| } | ||
| /* Should never happen */ |
Collaborator
There was a problem hiding this comment.
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
Contributor
Author
There was a problem hiding this comment.
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.
gchatelet
reviewed
Jun 25, 2021
gchatelet
left a comment
Collaborator
There was a problem hiding this comment.
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!
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.
Contributor
Author
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.