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

Enabling user control of compiler analysis for non ISO statements #1140

Merged
merged 5 commits into from May 6, 2024

Conversation

thirtytwobits
Copy link
Contributor

Description

This change replaces the GCC-specific fix for -pedantic in FreeRTOS_Sockets.c with a configurable solution. The change has no functional impact.

Test Steps

Compiles with GCC, -pedantic, and -Werror

Checklist:

  • 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.
  • I have tested by changes but have not run the existing tests.

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.

Conflicts:

source/FreeRTOS_Sockets.c

Description

Test Steps

Checklist:

  • 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.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Description
-----------
This change replaces the GCC-specific fix for -pedantic in FreeRTOS_Sockets.c with a configurable solution. The change has no functional impact.

Test Steps
-----------
Compiles with GCC, -pedantic, and -Werror

Checklist:
----------
- [ ] 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.
- [x] I have tested by changes but have not run the existing tests.

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.

# Conflicts:
#	source/FreeRTOS_Sockets.c
@thirtytwobits thirtytwobits requested a review from a team as a code owner April 26, 2024 16:54
@thirtytwobits thirtytwobits mentioned this pull request Apr 26, 2024
3 tasks
Copy link
Member

@jasonpcarroll jasonpcarroll left a comment

Choose a reason for hiding this comment

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

Looks good! I will get someone else to also take a look. You will need to update the formatting per the CI check, but that can easily be done by applying the git patch found under Artifacts->formattingChanges on the summary page of the CI run.

source/include/FreeRTOSIPConfigDefaults.h Outdated Show resolved Hide resolved
Co-authored-by: jasonpcarroll <23126711+jasonpcarroll@users.noreply.github.com>
@thirtytwobits
Copy link
Contributor Author

Forgot semicolons. Will update sometime today.

@tony-josi-aws
Copy link
Member

@thirtytwobits

Thanks for this PR. As we discussed in #1135, what is your thought on using memcpy to avoid the warning instead of adding macros that translate to compiler specific code in the common source code?

@thirtytwobits
Copy link
Contributor Author

memcpy is a pretty heavy hand to get around some macros. For example:

https://godbolt.org/z/WePM9W85f

The macros avoid any trickery in the compiler stage isolating it to the pre-processing stage. My assumption was you'd prefer to write idiomatic and typesafe C and accept some macros as a wart rather than the inverse? Even looking at the difference between my lighter-weight hack and the current code -> https://godbolt.org/z/M1soG7rfh <- you're still generating extra instructions at -O0 (should be identical for any other level of optimization) which does show this is actively thwarting the type system for every compiler whereas the macros have no effect until/unless the user adds directives specific to their compiler.

But I'll do this either way. It's your project. I'm just visiting ;-)

@htibosch
Copy link
Contributor

@thirtytwobits

Thanks for this PR. As we discussed in #1135, what is your thought on using memcpy to avoid the warning instead of adding macros that translate to compiler specific code in the common source code?

I also thought of using memcpy(), but a problem will still occur when a function pointer is larger than a void pointer.

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.

The following assignment seems to be a mortal sin:

    typedef void (* SocketWakeupCallback_t )( Socket_t * pxSocket );
    SocketWakeupCallback_t pxUserWakeCallback;

    pxUserWakeCallback = ( SocketWakeupCallback_t ) pvOptionValue;

The problem is that we treat a function pointer as if it were a void pointer. The reason for this is that FreeRTOS_setsockopt() uses a void parameter:

    BaseType_t FreeRTOS_setsockopt( Socket_t xSocket,
                                    int32_t lLevel,
                                    int32_t lOptionName,
                                    const void * pvOptionValue,
                                    size_t uxOptionLength );

The option FREERTOS_SO_WAKEUP_CALLBACK will bind a user function to a socket.
On some platforms, the two pointers (void* versus function*) should be treated in a different way.

Thanks for this PR, I approve it.

@htibosch
Copy link
Contributor

memcpy is a pretty heavy hand to get around some macros. For example:

https://godbolt.org/z/WePM9W85f

The socket option is rarely set, and most memcpy()s are optimised to copy 4 or 8 bytes in a few instructions.
But as I said, the use of void * is the problem.

@thirtytwobits
Copy link
Contributor Author

The socket option is rarely set, and most memcpy()s are optimised to copy 4 or 8 bytes in a few instructions. But as I said, the use of void * is the problem.

but you'd add a bl statement; you would modify the runtime to work around a compiler front-end diagnostic. This seems like the wrong bias.

@tony-josi-aws tony-josi-aws merged commit 0b9a497 into FreeRTOS:main May 6, 2024
10 checks 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.

None yet

6 participants