-
Notifications
You must be signed in to change notification settings - Fork 51
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
Feature/fixing clang gnu compiler warnings #45
Feature/fixing clang gnu compiler warnings #45
Conversation
…ments related to (FreeRTOS#35)
a modified xsdps driver that requires it.
…ed code for removing failure in 2032 due to uint32_t used for time.
@@ -186,22 +186,16 @@ target_compile_definitions( freertos_plus_fat | |||
|
|||
target_compile_options( freertos_plus_fat | |||
PRIVATE | |||
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-array-bounds> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is compiling with clang 14.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I feel array-bounds violations are fairly useful warnings, but I'm unaware whether there were intended "false positive" types being reported. Regardless plenty of other warnings were fixed, so approved first round of reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I built POSIX test on Ubuntu 22.04 with GCC11 with Warray-bounds
and no array bound warnings came up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dachalco I also use GCC11.3.0 and had to compile with that added to ensure no errors. I treat all warnings
as errors
. So this list is merely stating what is detected by Clang and GNU when compiling with those.
If they are no longer there then feel free to delete them, but the process I typically use is:
- identify everything first the linters/compilers show up
- Remove the warnings I intend to fix,
- Fix the warnings until those compile without error.
If you have a build that confirms this is no longer there then feel free to remove once the workflow adds those.
/bot run uncrustify |
@@ -186,22 +186,16 @@ target_compile_definitions( freertos_plus_fat | |||
|
|||
target_compile_options( freertos_plus_fat | |||
PRIVATE | |||
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-array-bounds> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I feel array-bounds violations are fairly useful warnings, but I'm unaware whether there were intended "false positive" types being reported. Regardless plenty of other warnings were fixed, so approved first round of reviews.
@@ -186,22 +186,16 @@ target_compile_definitions( freertos_plus_fat | |||
|
|||
target_compile_options( freertos_plus_fat | |||
PRIVATE | |||
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-array-bounds> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I built POSIX test on Ubuntu 22.04 with GCC11 with Warray-bounds
and no array bound warnings came up.
@phelter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @phelter, you did a very good job!
One more comment about a line that is not visible here below:
- if( uxIndex == 0 )
+ if( uxIndex == 0U )
{
- uxIndex = 1;
+ uxIndex = 1U;
}
that is because you made xIndex
unsigned:
- BaseType_t xIndex;
+ UBaseType_t uxIndex;
I approve the changes, thank you.
|
||
FF_PendSemaphore( pxIOManager->pvSemaphore ); | ||
{ | ||
for( xIndex = 0; xIndex < ffconfigPATH_CACHE_DEPTH; xIndex++ ) | ||
for( UBaseType_t xIndex = 0; xIndex < ffconfigPATH_CACHE_DEPTH; xIndex++ ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like the declaration within a for loop, but some users might still be using an older C dialect than C99?
And also, when xIndex
becomes unsigned, it should be called uxIndex
.
@@ -252,13 +252,13 @@ static FF_Error_t prvFormatGetClusterSize( struct xFormatSet * pxSet, | |||
|
|||
for( ; ; ) | |||
{ | |||
int32_t groupSize; | |||
uint32_t groupSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change it to ulGroupSize
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to change once this has been updated. I truly don't see the point in adding superfluous prefixes to values to identify the type when the IDE's these days can tell you that with pop-ups or other features. My 2 cents but if that is the format or flow then I suggest you add a tool to check and fix those for you since it is a simple thing to do automatically.
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
I understand you use uncrustify for this process, but it seems as though the bots for doing that aren't working.
@@ -2167,10 +2167,9 @@ int prvFFErrorToErrno( FF_Error_t xError ) | |||
|
|||
#if ( ffconfigTIME_SUPPORT == 1 ) | |||
|
|||
static uint32_t prvFileTime( FF_SystemTime_t * pxTime ) | |||
time_t prvFileTime( FF_SystemTime_t * pxTime ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here above prvFileTime()
was declared private. I don't think that the function is useful outside this module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A note about C and C++ - you only need to declare the function as static
or extern
for the declaration. So yes above it is declared as private in the declaration (where it should be). This is the definition, and in the definition you do not need to duplicate the static
or extern
.
Also for C - you can have a declaration of:
static void func(void); ///< Declaration
...
void func() ///< Definition
{
}
You can remove the void in the definition.
portable/STM32F4xx/ff_sddisk.c
Outdated
SD_state, | ||
prvSDCodePrintable( ( uint32_t ) SD_state ), | ||
xSDHandle.CardType == HIGH_CAPACITY_SD_CARD ? "SDHC" : "SD", | ||
xSDCardInfo.CardCapacity / ( 1024 * 1024 ) ); | ||
(unsigned)(xSDCardInfo.CardCapacity / ( 1024 * 1024 ) )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As CardCapacity i unsigned, use 1024U * 1024U
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that could be done in lieu of this change.
{ | ||
BaseType_t len2 = STRLEN( pxIOManager->xPartition.pxPathCache[ xIndex ].pcPath ); | ||
UBaseType_t len2 = STRLEN( pxIOManager->xPartition.pxPathCache[ xIndex ].pcPath ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And replace len2
with uxLength2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goal was not to fix the names of variables to match their types. Goal was to use the correct types.
/bot run uncrustify |
Why not create a new PR which will "uncrustify" the source code? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ci build bot for performing uncrustify is broken when merging from a fork. Please provide the proper method for executing uncrustify, or fix the bot.
I have no intention on installing uncrustify as I consider it a subset of the tools that I already use (clang-format) and have no use for it other than to fix code in freertos.
@@ -186,22 +186,16 @@ target_compile_definitions( freertos_plus_fat | |||
|
|||
target_compile_options( freertos_plus_fat | |||
PRIVATE | |||
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-array-bounds> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dachalco I also use GCC11.3.0 and had to compile with that added to ensure no errors. I treat all warnings
as errors
. So this list is merely stating what is detected by Clang and GNU when compiling with those.
If they are no longer there then feel free to delete them, but the process I typically use is:
- identify everything first the linters/compilers show up
- Remove the warnings I intend to fix,
- Fix the warnings until those compile without error.
If you have a build that confirms this is no longer there then feel free to remove once the workflow adds those.
@@ -2167,10 +2167,9 @@ int prvFFErrorToErrno( FF_Error_t xError ) | |||
|
|||
#if ( ffconfigTIME_SUPPORT == 1 ) | |||
|
|||
static uint32_t prvFileTime( FF_SystemTime_t * pxTime ) | |||
time_t prvFileTime( FF_SystemTime_t * pxTime ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A note about C and C++ - you only need to declare the function as static
or extern
for the declaration. So yes above it is declared as private in the declaration (where it should be). This is the definition, and in the definition you do not need to duplicate the static
or extern
.
Also for C - you can have a declaration of:
static void func(void); ///< Declaration
...
void func() ///< Definition
{
}
You can remove the void in the definition.
@@ -105,8 +104,8 @@ | |||
#define WEEK_DAY_SATURDAY 6 | |||
|
|||
/* Make a bitmask with a '1' for each 31-day month. */ | |||
#define _MM( month ) ( 1u << ( month - 1 ) ) | |||
#define MASK_LONG_MONTHS ( _MM( 1 ) | _MM( 3 ) | _MM( 5 ) | _MM( 7 ) | _MM( 8 ) | _MM( 10 ) | _MM( 12 ) ) | |||
#define MM_( month ) ( 1u << ( month - 1 ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@htibosch - macros and precompiler definitions that start with _
are considered reserved and should not be used.
https://clang.llvm.org/docs/DiagnosticsReference.html#wreserved-identifier
For MISRA checks - if they were run in the ci.yml then they pass. If not then I suggest if this is a requirement then you should add it to the ci.yml to check that.
@@ -141,7 +140,7 @@ | |||
|
|||
static portINLINE unsigned long ulDaysPerYear( int iYear ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I would suggest that, but out of scope of this particular PR to reduce those specific compiler warnings.
Also using size_t
and uintptr_t
for sizes and addresses is also best.
@@ -252,13 +252,13 @@ static FF_Error_t prvFormatGetClusterSize( struct xFormatSet * pxSet, | |||
|
|||
for( ; ; ) | |||
{ | |||
int32_t groupSize; | |||
uint32_t groupSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to change once this has been updated. I truly don't see the point in adding superfluous prefixes to values to identify the type when the IDE's these days can tell you that with pop-ups or other features. My 2 cents but if that is the format or flow then I suggest you add a tool to check and fix those for you since it is a simple thing to do automatically.
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
I understand you use uncrustify for this process, but it seems as though the bots for doing that aren't working.
portable/STM32F4xx/ff_sddisk.c
Outdated
SD_state, | ||
prvSDCodePrintable( ( uint32_t ) SD_state ), | ||
xSDHandle.CardType == HIGH_CAPACITY_SD_CARD ? "SDHC" : "SD", | ||
xSDCardInfo.CardCapacity / ( 1024 * 1024 ) ); | ||
(unsigned)(xSDCardInfo.CardCapacity / ( 1024 * 1024 ) )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that could be done in lieu of this change.
{ | ||
BaseType_t len2 = STRLEN( pxIOManager->xPartition.pxPathCache[ xIndex ].pcPath ); | ||
UBaseType_t len2 = STRLEN( pxIOManager->xPartition.pxPathCache[ xIndex ].pcPath ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goal was not to fix the names of variables to match their types. Goal was to use the correct types.
/bot run uncrustify |
The bot is not working I've tried, and so have others. I don't know if it has something to do with this being a merge from a fork? |
@phelter Yeah i checked. Adding changes to fix the issue in a separate PR. Will update once merged. |
/bot run uncrustify |
+1 |
@@ -35,13 +35,11 @@ | |||
#include "task.h" | |||
|
|||
/* System application includes. */ | |||
#include "FreeRTOSConfig.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be needed explicitly - including "FreeRTOS.h" is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
The first thing FreeRTOS.h does is :
/* Application specific configuration options. */
#include "FreeRTOSConfig.h"
Description ----------- #45 introduced a compilation error about implicit `FF_CreateError` function when using FAT12 support. I assume it was supposed to be `FF_createERR` macro instead so I changed it. Checklist: ---------- <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have tested my changes. No regression in existing tests. - [ ] I have modified and/or added unit-tests to cover the code changes in this Pull Request. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Fixing Clang and GNU compiler warnings along with some clang-tidy issues.
Description
Test Steps
Checklist:
Related Issue
None.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.