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

Feature/fixing clang gnu compiler warnings #45

Merged

Conversation

phelter
Copy link
Contributor

@phelter phelter commented May 1, 2023

Fixing Clang and GNU compiler warnings along with some clang-tidy issues.

Description

  • Upkeep/maintenance - fixed a bunch of the compiler warnings that were previously ignored. See lists in CMakeLists.txt for ones fixed.

Test Steps

  • None - re-run test suite.

Checklist:

  • [x ] I have tested my changes. No regression in existing tests.
  • [x ] I have modified and/or added unit-tests to cover the code changes in this Pull Request.

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.

@phelter phelter requested a review from a team as a code owner May 1, 2023 20:03
include/ff_error.h Outdated Show resolved Hide resolved
@@ -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>
Copy link
Contributor Author

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

Copy link

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.

Copy link

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.

Copy link
Contributor Author

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:

  1. identify everything first the linters/compilers show up
  2. Remove the warnings I intend to fix,
  3. 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.

@phelter
Copy link
Contributor Author

phelter commented May 1, 2023

/bot run uncrustify

dachalco
dachalco previously approved these changes May 3, 2023
@@ -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>
Copy link

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

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.

@dachalco
Copy link

dachalco commented May 3, 2023

@phelter
I tried to push a commit to fix the failing formatting checks but did not have permissions for this PR.
To fix the failing formatting checks, the failing files need to be uncrustified (v0.69).

htibosch
htibosch previously approved these changes May 3, 2023
Copy link
Contributor

@htibosch htibosch left a 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++ )
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Change it to ulGroupSize?

Copy link
Contributor Author

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.

ff_ioman.c Show resolved Hide resolved
ff_stdio.c Show resolved Hide resolved
@@ -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 )
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@htibosch

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.

include/ff_stdio.h Show resolved Hide resolved
include/ff_error.h Outdated Show resolved Hide resolved
portable/ATSAM4E/ff_sddisk.c Outdated Show resolved Hide resolved
SD_state,
prvSDCodePrintable( ( uint32_t ) SD_state ),
xSDHandle.CardType == HIGH_CAPACITY_SD_CARD ? "SDHC" : "SD",
xSDCardInfo.CardCapacity / ( 1024 * 1024 ) );
(unsigned)(xSDCardInfo.CardCapacity / ( 1024 * 1024 ) ));
Copy link
Contributor

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?

Copy link
Contributor Author

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 );
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@htibosch
Copy link
Contributor

htibosch commented May 3, 2023

/bot run uncrustify

@htibosch
Copy link
Contributor

htibosch commented May 3, 2023

Why not create a new PR which will "uncrustify" the source code?

Copy link
Contributor Author

@phelter phelter left a 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>
Copy link
Contributor Author

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:

  1. identify everything first the linters/compilers show up
  2. Remove the warnings I intend to fix,
  3. 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 )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@htibosch

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.

ff_stdio.c Show resolved Hide resolved
@@ -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 ) )
Copy link
Contributor Author

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 )
Copy link
Contributor Author

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;
Copy link
Contributor Author

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.

ff_ioman.c Show resolved Hide resolved
SD_state,
prvSDCodePrintable( ( uint32_t ) SD_state ),
xSDHandle.CardType == HIGH_CAPACITY_SD_CARD ? "SDHC" : "SD",
xSDCardInfo.CardCapacity / ( 1024 * 1024 ) );
(unsigned)(xSDCardInfo.CardCapacity / ( 1024 * 1024 ) ));
Copy link
Contributor Author

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 );
Copy link
Contributor Author

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.

@moninom1
Copy link
Member

/bot run uncrustify

@phelter
Copy link
Contributor Author

phelter commented May 10, 2023

@moninom1

/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?

@moninom1
Copy link
Member

@phelter Yeah i checked. Adding changes to fix the issue in a separate PR. Will update once merged.

@moninom1
Copy link
Member

/bot run uncrustify

@amazonKamath amazonKamath requested review from htibosch and moninom1 May 11, 2023 07:17
@htibosch
Copy link
Contributor

+1
Just to make sure, I approve @phelter's PR, let's merge it.
Thank you

@moninom1 moninom1 self-requested a review May 11, 2023 16:37
@moninom1 moninom1 requested review from n9wxu and htibosch and removed request for htibosch May 11, 2023 17:04
@@ -35,13 +35,11 @@
#include "task.h"

/* System application includes. */
#include "FreeRTOSConfig.h"
Copy link
Member

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.

Copy link
Contributor

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"

@n9wxu n9wxu merged commit 08d0cff into FreeRTOS:main May 16, 2023
AniruddhaKanhere pushed a commit that referenced this pull request Jan 30, 2024
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.
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.

9 participants