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

cmake: use the warnings_as_errors flag for cpp files #78419

Merged
merged 7 commits into from
Sep 23, 2024

Conversation

fabiobaltieri
Copy link
Member

@fabiobaltieri fabiobaltieri commented Sep 13, 2024

C++ file compilation is actually missing the warning-as-error handling, causing warnings in build files to be unnoticed in CI. Add a flag to handle them as well.

Fixes #78348

Pushed on https://github.com/zephyrproject-rtos/zephyr-testing/tree/vfabio-testing-branch as well

kartben
kartben previously approved these changes Sep 13, 2024
nashif
nashif previously approved these changes Sep 13, 2024
@nashif
Copy link
Member

nashif commented Sep 13, 2024

and now to all those build issues we missed previous and exposed through this change....

yperess
yperess previously approved these changes Sep 14, 2024
@yperess
Copy link
Collaborator

yperess commented Sep 14, 2024

@fabiobaltieri would you like me to make these fixes in the tree?

@fabiobaltieri
Copy link
Member Author

@fabiobaltieri would you like me to make these fixes in the tree?

That'd be cool if you have time, I'm out for the next couple of days.

tejlmand
tejlmand previously approved these changes Sep 15, 2024
nordicjm
nordicjm previously approved these changes Sep 16, 2024
pdgendt
pdgendt previously approved these changes Sep 16, 2024
@nordicjm
Copy link
Collaborator

Just noticed this is a duplicate of #69226

@fabiobaltieri
Copy link
Member Author

Thanks @nordicjm, borrowed some commits from there and added few more, still not done though but I could use a CI run, moving back to draft.

cfriedt
cfriedt previously approved these changes Sep 19, 2024
Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

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

cpp changes look fine

@zephyrbot zephyrbot added the area: Base OS Base OS Library (lib/os) label Sep 19, 2024
@@ -63,13 +63,13 @@ struct z_device_mmio_rom {

#define Z_DEVICE_MMIO_ROM_INITIALIZER(node_id) \
{ \
.phys_addr = DT_REG_ADDR(node_id), \
.phys_addr = UINT32_C(DT_REG_ADDR(node_id)), \
Copy link
Member Author

@fabiobaltieri fabiobaltieri Sep 19, 2024

Choose a reason for hiding this comment

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

tempted to have this as part of DT_REG_ADDR (and potentially DT_REG_SIZE too) macro itself but that would be a substantial change, definitely worth its own PR, I propose to patch this one up for now. Somewhat surprised CI does not hit more cases of this warning though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks really odd to me offhand, is the ADDR a 32 bit unsigned or not? If it is, then the DT macro should ensure that's the type being provided. If its not, then .phys_addr should have its type corrected. This looks a bit like a quick fix at the wrong place.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's a quick fix, that's pretty much what I meant in the comment above

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please create an issue for this then, if its meant to be revisited

Copy link
Collaborator

Choose a reason for hiding this comment

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

There already exist an issue:
#53505
I gave it a shot, but gave up:
#70761

Copy link
Member Author

Choose a reason for hiding this comment

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

@jeppenodgaard what was wrong with that? CI errors? I was considering giving it a go as well

Copy link
Collaborator

Choose a reason for hiding this comment

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

@fabiobaltieri see this closing comment:
#70761 (comment)

Copy link
Collaborator

@teburd teburd left a comment

Choose a reason for hiding this comment

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

Some answers I think are needed for some of the more suspicious changes to appease the compiler, or perhaps some inline comments for the really odd ones (void)foo; looks like a no-op

@@ -63,13 +63,13 @@ struct z_device_mmio_rom {

#define Z_DEVICE_MMIO_ROM_INITIALIZER(node_id) \
{ \
.phys_addr = DT_REG_ADDR(node_id), \
.phys_addr = UINT32_C(DT_REG_ADDR(node_id)), \
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks really odd to me offhand, is the ADDR a 32 bit unsigned or not? If it is, then the DT macro should ensure that's the type being provided. If its not, then .phys_addr should have its type corrected. This looks a bit like a quick fix at the wrong place.

@@ -42,7 +42,7 @@ struct i2c_target_callbacks emulated_callbacks[FORWARD_COUNT] = {
DT_FOREACH_PROP_ELEM(CONTROLLER_LABEL, forwards, DEFINE_EMULATED_CALLBACK)};

#define DEFINE_EMULATED_TARGET_CONFIG(node_id, prop, n) \
[n] = { \
{ \
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like its doing something completely different than it was before? Confused by this change, why is "[n] = " no longer needed, why was it needed before?

Copy link
Member Author

Choose a reason for hiding this comment

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

no idea why it was introduced originally, I guess to do something with that n variable? regardless, the compiler does not like it, the alternative would be to shut off that warning, happy with either. @yperess?

Fix a type mismatch compiler warning in the c++ tests.

Signed-off-by: Yuval Peress <peress@google.com>
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
@teburd teburd removed the size: XS A PR changing only a single line of code label Sep 19, 2024
@teburd
Copy link
Collaborator

teburd commented Sep 19, 2024

Dropped the XS tag as its a bit more than one line, hopefully no one is offended by this.

Add a dummy byte to struct mspi_timing_cfg, for C++ compatibility, same
as what's done in include/zephyr/arch/structs.h,
include/zephyr/arch/arm/structs.h, include/zephyr/kernel/thread.h and
others.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Fix the compiler error:

comparison of integer expressions of different signedness: ‘const int’
and ‘unsigned int’

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
On some architecture (qemu_x86) this tests generate an unused reference
warning for the PM device structure, as nothing in the structure macro
definition is referencing itself.

Reference the struct in the device define, keep the compiler happy.

Also change one of the device priority to dodge a

'__device_dts_ord_8' causes a section type conflict with
'__device_dts_ord_9'

error with llvm.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Drop the array dasignators as they generate a

warning: array designators are a C99 extension

warning when compiling with clang. Not too sure if this is an actual
problem or if the warning should be disabled instead but since it's just
a test it should be fine to just drop them.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Add an explicit unsigned literal suffix (U) for addresses obtained from
devicetree, this is to work around a specific warning:

zephyrproject/zephyr/include/zephyr/arch/arm/cortex_a_r/timer.h:40:2:
warning: this decimal constant is unsigned only in ISO C90

When compling

west build -p -b qemu_cortex_a9 -T tests/lib/cpp/cxx/cpp.main.cpp98

Argueably all devicetree addresses and sizes should be unsigned but this
is enough to make CI pass, may look into changing the device.h macro as
a followup.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
C++ file compilation is actually missing the warning-as-error handling,
causing warnings in build files to be unnoticed in CI. Add a flag to
handle them as well.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
@fabiobaltieri
Copy link
Member Author

Ok this is interesting now:

$ export ZEPHYR_TOOLCHAIN_VARIANT=llvm
$ west build -p -b native_sim -T tests/lib/cpp/cxx/cpp.main.minimal
...
zephyr/tests/lib/cpp/cxx/src/main.cpp:154:1: error: '__device_dts_ord_8' causes a section type conflict with '__device_dts_ord_9'

Only on LLVM, seems to not like the two devices one with PM data one without at the same priority, this is the expanded definition if anyone wants to have a go at figuring what is going on

static __attribute__((__aligned__(__alignof(struct device_state)))) struct device_state __devstate_dts_ord_9 __attribute__((__section__(".z_devstate"))); static_assert(sizeof("\"dev1\"") <= 48U, "" "DEVICE_NAME_GET(\"dev1\")" " too long"); static const struct device_dt_nodelabels __dev_dt_nodelabels_dts_ord_9 = { .num_nodelabels = 1, .nodelabels = { "test_dev1_dfr", }, }; static const struct device_dt_metadata __dev_dt_meta_dts_ord_9 = { .nl = &__dev_dt_nodelabels_dts_ord_9, };; const __attribute__((__aligned__(__alignof(struct device)))) struct device __device_dts_ord_9 __attribute__((section("." "_device" "." "static" "." "3_33_"))) __attribute__((__used__)) = { .name = "dev1", .config = (__null), .api = (__null), .state = (&__devstate_dts_ord_9), .data = (__null), .pm_base = (__null), .dt_meta = &__dev_dt_meta_dts_ord_9, }; static const __attribute__((__aligned__(__alignof(struct init_entry)))) struct init_entry __attribute__((__used__)) __attribute__((__section__(".z_deferred_init"))) __init___device_dts_ord_9 = { .init_fn = {.dev = (__null)}, .dev = &__device_dts_ord_9, };;

static int fake_pm_action(const struct device *dev,
  enum pm_device_action pm_action) { return -1; }
; static struct pm_device __pm_device_dts_ord_8 = { .base = { .flags = (((0 << PM_DEVICE_FLAG_WS_CAPABLE) | (0 << PM_DEVICE_FLAG_RUNTIME_AUTO) | (0 << PM_DEVICE_FLAG_PD)) | (0 ? (1UL << (PM_DEVICE_FLAG_ISR_SAFE)) : 0)), .state = PM_DEVICE_STATE_ACTIVE, .action_cb = fake_pm_action, .domain = __null, }, .lock = { .wait_q = { { {(&(&(__pm_device_dts_ord_8.lock).wait_q)->waitq)}, {(&(&(__pm_device_dts_ord_8.lock).wait_q)->waitq)} } }, .count = (1), .limit = (1), }, .event = { .wait_q = { { {(&(&__pm_device_dts_ord_8.event.wait_q)->waitq)}, {(&(&__pm_device_dts_ord_8.event.wait_q)->waitq)} } }, .events = 0 }, };

static __attribute__((__aligned__(__alignof(struct device_state)))) struct device_state __devstate_dts_ord_8 __attribute__((__section__(".z_devstate"))); static_assert(sizeof("\"dev0\"") <= 48U, "" "DEVICE_NAME_GET(\"dev0\")" " too long"); static const struct device_dt_nodelabels __dev_dt_nodelabels_dts_ord_8 = { .num_nodelabels = 1, .nodelabels = { "test_dev0_boot", }, }; static const struct device_dt_metadata __dev_dt_meta_dts_ord_8 = { .nl = &__dev_dt_nodelabels_dts_ord_8, };; const __attribute__((__aligned__(__alignof(struct device)))) struct device __device_dts_ord_8 __attribute__((section("." "_device" "." "static" "." "3_33_"))) __attribute__((__used__)) = { .name = "dev0", .config = (__null), .api = (__null), .state = (&__devstate_dts_ord_8), .data = (__null), .pm_base = (((struct pm_device_base *)&__pm_device_dts_ord_8)), .dt_meta = &__dev_dt_meta_dts_ord_8, }; static const __attribute__((__aligned__(__alignof(struct init_entry)))) struct init_entry __attribute__((__used__)) __attribute__((__section__( ".z_init_" "POST_KERNEL" "33""_" "00008""_"))) __init___device_dts_ord_8 = { .init_fn = {.dev = (__null)}, .dev = &__device_dts_ord_8, };;

I'll change the priority for now, no doubt it'll come to bite me back down the road anyway.

@fabiobaltieri
Copy link
Member Author

Dug a bit more, seems like having that field set moves the device structure from rodata to data, with different prio and no pm:

        0x00000000 - 0x000000fe is .text
...
        0x00000130 - 0x00000180 is .bss
...
        0x00000388 - 0x000003a0 is .rodata
        0x000003a0 - 0x000003bc is ._device.static.3_33_
        0x000003bc - 0x000003c4 is .z_deferred_init
        0x000003c4 - 0x000003e0 is ._device.static.3_34_
        0x000003e0 - 0x000003e8 is .z_init_POST_KERNEL33_00008_
        0x000003e8 - 0x000003ec is .init_array

with pm:

        0x00000000 - 0x00000102 is .text
...
        0x00000134 - 0x00000184 is .bss
...
        0x0000038c - 0x000003a4 is .rodata
        0x000003a4 - 0x000003c0 is ._device.static.3_33_
        0x000003c0 - 0x000003c8 is .z_deferred_init
        0x000003c8 - 0x00000428 is .data
        0x00000428 - 0x00000444 is ._device.static.3_34_
        0x00000444 - 0x0000044c is .z_init_POST_KERNEL33_00008_
        0x0000044c - 0x00000450 is .init_array

no idea why it's doing that, does not look right to me but I'll just add it to the ever growing list of c++ stuff I don't understand.

@teburd
Copy link
Collaborator

teburd commented Sep 20, 2024

Dug a bit more, seems like having that field set moves the device structure from rodata to data, with different prio and no pm:

        0x00000000 - 0x000000fe is .text
...
        0x00000130 - 0x00000180 is .bss
...
        0x00000388 - 0x000003a0 is .rodata
        0x000003a0 - 0x000003bc is ._device.static.3_33_
        0x000003bc - 0x000003c4 is .z_deferred_init
        0x000003c4 - 0x000003e0 is ._device.static.3_34_
        0x000003e0 - 0x000003e8 is .z_init_POST_KERNEL33_00008_
        0x000003e8 - 0x000003ec is .init_array

with pm:

        0x00000000 - 0x00000102 is .text
...
        0x00000134 - 0x00000184 is .bss
...
        0x0000038c - 0x000003a4 is .rodata
        0x000003a4 - 0x000003c0 is ._device.static.3_33_
        0x000003c0 - 0x000003c8 is .z_deferred_init
        0x000003c8 - 0x00000428 is .data
        0x00000428 - 0x00000444 is ._device.static.3_34_
        0x00000444 - 0x0000044c is .z_init_POST_KERNEL33_00008_
        0x0000044c - 0x00000450 is .init_array

no idea why it's doing that, does not look right to me but I'll just add it to the ever growing list of c++ stuff I don't understand.

Unsolved Mysteries of C++, maybe one of the people who wished to add C++ can help here, I have no idea either.

@fabiobaltieri
Copy link
Member Author

Yeah, anyway CI seems to be happy again so at least the workarounds are working around.

Copy link
Collaborator

@teburd teburd left a comment

Choose a reason for hiding this comment

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

Noted issue exists for the unsigned dt stuff, all other mysterious things look better. Seems good to me.

@nashif nashif merged commit 56dcafe into zephyrproject-rtos:main Sep 23, 2024
24 checks passed
@fabiobaltieri fabiobaltieri deleted the warning-error-cpp branch February 28, 2025 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

twister missing build warning in cpp files