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

Fix minor unused/uninitialized warnings from GCC 12.3.0 #1786

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

earlephilhower
Copy link
Contributor

Decorate an unused parameter in the timer API and fill in all structure elements in a PIO API call that generate warnings under GCC 12.

Fixes #1785

Decorate an unused parameter in the timer API and fill in all structure
elements in a PIO API call that generate warnings under GCC 12.
@peterharperuk
Copy link
Contributor

Looks good

earlephilhower added a commit to earlephilhower/arduino-pico that referenced this pull request Aug 17, 2024
Remove the skipped error messages once the following PR merged:
raspberrypi/pico-sdk#1786
earlephilhower added a commit to earlephilhower/arduino-pico that referenced this pull request Aug 17, 2024
* Update to 2.0.0 SDK
* Board type needs to be set before earliest SDK setup
* Platform includes update
* Boot2 files
* Simple compilation issues
* Build and link
* PIO rebuild with version
* Newlib wrapper update
* Force inclusion of runtime_init_* fcns
The linker was dropping all references to the library's included
runtime_init_xxx functions and hence things like the IRQ vector
table and mutexes and alarms weren't properly set up leading to
instant crashes on start up..

Explicitly call out one function from the object file stored in
the .A to force the inclusion of all the functions.  May be a better
way, heppy to hear any ideas.
* Fix SPI GPIO calls
* Fix Ethernet GPIO
* Remove SDK warnings
Remove the skipped error messages once the following PR merged:
raspberrypi/pico-sdk#1786
* BTStack moved SBC encode/decode paths
* Platform.IO fixes
* BT No longer has special absolute mouse
* Rebuild and update OTA
* Rebuild BearSSL, too
* Update liker file to latest SDK
* Clean up libpicocmake
* Clean up LWIP/BT library names
pio_sm_config c = {0};
#if PICO_PIO_USE_GPIO_BASE
c.pinhi = -1;
#if PICO_PIO_USE_GPIO_BASE
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the warning what version of the compiler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

arm-none-eabi-gcc (GCC) 12.3.0 using -Wall -Wextra

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you give the full output off gcc --version and/or say where you got it.

I'm tempted not to fix this as this is a compiler bug (and the fix is ugly/brittle), but if i can actually get an exact compiler which has this problem, i can see if it supports suppressing the warning

Copy link
Contributor Author

@earlephilhower earlephilhower Aug 20, 2024

Choose a reason for hiding this comment

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

I don't think this is a compiler issue so much as a C vs. C++ issue.

In C++ {0} will only set the 1st member of the structure to 0 because it's taking that as a positional initializer. In C, IIRC, {0} will effectively bzero the struct, which might be where the confusion is stemming from. You can include the SDK headers in C++ code, and when that happens the warning pops up.

This is with plain Ubuntu 20.04 GCC 9, not even the ARM x-compiler using a simple example to avoid a bunch of -Is. Just a struct with >1 member being set to {0}.

earle@amd:~/Arduino/hardware/pico/rp2040$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

earle@amd:~/Arduino/hardware/pico/rp2040$ cat a.c
#include <stdio.h>
struct t {
    int a;
    int b;
};
void dummy() {
    struct t a = {0};
    printf("%d\n", a.b);
}
earle@amd:~/Arduino/hardware/pico/rp2040$ cp a.c a.cpp
earle@amd:~/Arduino/hardware/pico/rp2040$ gcc -Wall -Wextra -c  a.c
<note no warnings>
earle@amd:~/Arduino/hardware/pico/rp2040$ g++ -Wall -Wextra -c  a.c
a.c: In function ‘void dummy()’:
a.c:7:20: warning: missing initializer for member ‘t::b’ [-Wmissing-field-initializers]
    7 |     struct t a = {0};
      |       

(for completeness I see I used .c and not .cpp in the g++ line, so here that is, too:

earle@amd:~/Arduino/hardware/pico/rp2040$ g++ -Wall -Wextra -c  a.cpp
a.cpp: In function ‘void dummy()’:
a.cpp:7:20: warning: missing initializer for member ‘t::b’ [-Wmissing-field-initializers]
    7 |     struct t a = {0};
      |                    ^

and for completeness, because the SDK includes are extern "C"'d, that doesn't affect the compilation, only the name mangling:

earle@amd:~/Arduino/hardware/pico/rp2040$ cat a.cpp
#include <stdio.h>
extern "C" {
struct t {
    int a;
    int b;
};
void dummy() {
    struct t a = {0};
    printf("%d\n", a.b);
}
}
earle@amd:~/Arduino/hardware/pico/rp2040$ g++ -Wall -Wextra -c  a.cpp
a.cpp: In function ‘void dummy()’:
a.cpp:8:20: warning: missing initializer for member ‘t::b’ [-Wmissing-field-initializers]
    8 |     struct t a = {0};
      |                    ^

@kilograham kilograham changed the title Fix minor unused/uninitialized warnings from GCC 12 Fix minor unused/uninitialized warnings from GCC 12.3.0 Aug 20, 2024
@kilograham
Copy link
Contributor

An ok - I had wondered if this was a c++ thing - the {0} is valid C but had seen reports of some versions (albeit old) reporting that exact message

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.

3 participants