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

Remove extraneous zero initializers to clean up Qurt compiler warnings #28634

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

katzfey
Copy link
Contributor

@katzfey katzfey commented Nov 15, 2024

Extraneous zero initializers for global / static variables were removed to get rid of the following Qurt compiler warnings:

../../libraries/AP_RCProtocol/spm_srxl.cpp:78:36: warning: suggest braces around initialization of subobject [-Wmissing-braces]
SrxlTelemetryData srxlTelemData = {0};
^
{}
../../libraries/AP_RCProtocol/spm_srxl.cpp:83:34: warning: suggest braces around initialization of subobject [-Wmissing-braces]
static SrxlDevice srxlThisDev = {0};
^
{}
../../libraries/AP_RCProtocol/spm_srxl.cpp:91:36: warning: suggest braces around initialization of subobject [-Wmissing-braces]
static SrxlReceiverStats srxlRx = {0};
^
{}
../../libraries/AP_RCProtocol/spm_srxl.cpp:91:36: warning: suggest braces around initialization of subobject [-Wmissing-braces]
static SrxlReceiverStats srxlRx = {0};
^
{}

Since this data will end up in .bss and be zeroed out it does not need explicit zero initializers.

@andyp1per
Copy link
Collaborator

This is an external library, modifying it makes it hard to integrate newer versions - that's why these have not been fixed previously

@katzfey
Copy link
Contributor Author

katzfey commented Nov 15, 2024

Shoot! I have 3 PR's with changes to the spm_srxl files. Unfortunately, it's a C file that was copied over and given the cpp extension. Then the C++ compiler gives warnings because it has C specific stuff in it.

@katzfey
Copy link
Contributor Author

katzfey commented Nov 15, 2024

@andyp1per Take a look at PR28643: #28643

If that is a more reasonable way to deal with these compiler warnings then I can close this PR.

@tridge
Copy link
Contributor

tridge commented Nov 19, 2024

This is an external library, modifying it makes it hard to integrate newer versions - that's why these have not been fixed previously

I think we just need to wear that cost next time we update, more important to get rid of clang warnings I think

@tridge
Copy link
Contributor

tridge commented Nov 20, 2024

@katzfey what is a bit surprising is this doesn't seem to save any flash space. I would have expected variables to move from DATA to BSS with a corresponding flash saving

@peterbarker
Copy link
Contributor

Alternate forumation, same as we use in LUA:

--- a/libraries/AP_RCProtocol/spm_srxl.cpp
+++ b/libraries/AP_RCProtocol/spm_srxl.cpp
@@ -22,6 +22,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 */
 
+#if ARDUPILOT_BUILD
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmissing-braces"
+#endif
+
 #include <string.h>
 #include <stdint.h>
 
@@ -1428,3 +1433,7 @@ bool srxlUpdateCommStats(bool isFade)
     // Return true while we're in hold condition (failsafe)
     return srxlRx.lossCountdown == 0;
 }
+
+#if ARDUPILOT_BUILD
+#pragma GCC diagnostic pop
+#endif

.... but the compiler warning is pointing out a bug, so I reckong we just accept this PR.

If we lock the error in with a -Werror then the next person to freshen this file from its source gets to fix the bugs again :-)

@tridge
Copy link
Contributor

tridge commented Nov 20, 2024

@andyp1per my preference is not to use the ifdefs, and just fix the code, I think the cost of updating these quite small files at some point in the future will be low, and clang is correct about the initialisers being wrong for these nested structures

@tridge
Copy link
Contributor

tridge commented Nov 20, 2024

I'd like @andyp1per to have a chance to comment before merge

@katzfey
Copy link
Contributor Author

katzfey commented Nov 20, 2024

@tridge My understanding is that the compiler sees that you are initializing with 0 and puts them in bss anyways so shouldn't change anything there.

Copy link
Collaborator

@andyp1per andyp1per left a comment

Choose a reason for hiding this comment

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

This looks ok to me - what testing have you done?

@katzfey
Copy link
Contributor Author

katzfey commented Dec 12, 2024

I have only tested on my Qurt based drone so it isn't actually exercising any of the changed code. But, in theory, this doesn't actually change anything.

@katzfey
Copy link
Contributor Author

katzfey commented Dec 12, 2024

In fact, the object file is identical after the change.

@andyp1per andyp1per merged commit 3501bb7 into ArduPilot:master Dec 12, 2024
99 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.

6 participants