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

Add -Wtype-limits feature #34

Merged
merged 1 commit into from
Mar 15, 2024
Merged

Add -Wtype-limits feature #34

merged 1 commit into from
Mar 15, 2024

Conversation

jwnrt
Copy link
Contributor

@jwnrt jwnrt commented Feb 5, 2024

This flag catches easy to miss cases like this:

for (uint8_t i = 5; i >= 0; --i) {
  printf("hello!\n");
}

where a uint8_t will always be >= 0:

[jw type-limits]$ clang -Wtype-limits main.c    
main.c:5:25: warning: result of comparison of unsigned expression >= 0 is always true [-Wtautological-unsigned-zero-compare]
  for (uint8_t i = 5; i >= 0; --i) {
                      ~ ^  ~

GCC includes this in -Wextra, but surprisingly Clang doesn't even include it in -Wpedantic at the moment and you have to go all the way up to -Weverything.

I haven't tested this because I can't get the CRT repo to build at the moment, but maybe it's simple enough.

@jwnrt jwnrt requested review from luismarques and cfrantz February 5, 2024 16:19
@jwnrt
Copy link
Contributor Author

jwnrt commented Mar 15, 2024

Removed the flag from the defaults

@luismarques luismarques changed the title Add -Wtype-limits to default set of flags Add -Wtype-limits feature Mar 15, 2024
@jwnrt jwnrt merged commit bacad84 into lowRISC:main Mar 15, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants