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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/rp2_common/hardware_pio/include/hardware/pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,10 @@ static inline void sm_config_set_mov_status(pio_sm_config *c, enum pio_mov_statu
* \return the default state machine configuration which can then be modified.
*/
static inline pio_sm_config pio_get_default_sm_config(void) {
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};
      |                    ^

pio_sm_config c = {0, 0, 0, 0, -1};
#else
pio_sm_config c = {0, 0, 0, 0};
earlephilhower marked this conversation as resolved.
Show resolved Hide resolved
#endif
sm_config_set_clkdiv_int_frac(&c, 1, 0);
sm_config_set_wrap(&c, 0, 31);
Expand Down