Skip to content

fix: Return default value from ‘GetCacheTypeString’ - #162

Merged
gchatelet merged 1 commit into
google:masterfrom
kriskwiatkowski:kris/fix_Werror_return_type
Jun 25, 2021
Merged

gchatelet merged 1 commit into
google:masterfrom
kriskwiatkowski:kris/fix_Werror_return_type

Conversation

@kriskwiatkowski

Copy link
Copy Markdown
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.

Comment thread src/utils/list_cpu_features.c Outdated
return CreateConstantString("prefetch");
}
/* Should never happen */
return 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread src/utils/list_cpu_features.c Outdated
case CPU_FEATURE_CACHE_PREFETCH:
return CreateConstantString("prefetch");
}
/* Should never happen */

Copy link
Copy Markdown
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
Copy Markdown
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.

@gchatelet gchatelet left a comment

Copy link
Copy Markdown
Collaborator

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!

Comment thread include/cpu_features_macros.h 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
Copy Markdown
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.

3 participants