-
Notifications
You must be signed in to change notification settings - Fork 7.3k
arch: riscv: Fix warning when C++ is enabled #88734
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
base: main
Are you sure you want to change the base?
Conversation
When compiling with C++ enabled (CONFIG_CPP), add an unused member to prevent an empty struct; this makes the struct size the same for both C and C++. Fixes the following warnings: In file included from include/zephyr/drivers/gpio.h:22: In file included from include/zephyr/tracing/tracing.h:9: In file included from include/zephyr/kernel.h:17: In file included from include/zephyr/kernel_includes.h:32: In file included from include/zephyr/kernel_structs.h:29: In file included from include/zephyr/arch/structs.h:29: include/zephyr/arch/riscv/structs.h:11:1: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat] 11 | struct _cpu_arch { | ^ In file included from include/zephyr/drivers/gpio.h:22: In file included from include/zephyr/tracing/tracing.h:9: In file included from include/zephyr/kernel.h:17: In file included from include/zephyr/kernel_includes.h:36: In file included from include/zephyr/arch/cpu.h:25: In file included from include/zephyr/arch/riscv/arch.h:18: include/zephyr/arch/riscv/thread.h:68:1: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat] 68 | struct _thread_arch { | ^ Signed-off-by: Tom Hughes <[email protected]>
Hi, thanks for this PR! Unfortunately, I can't seem to reproduce this warning using the following command:
Could you perhaps create an issue with information on how to reproduce this warning? |
There are two things in my setup that are different than the way you're testing:
It should be reproducible if you use LLVM and make sure that the relevant configs are disabled that make Here's an example of what the failure looks like in CI when building with LLVM in another part of the code: #87088 (comment) |
Right. This is a configuration that, as far as I’m aware, is unsupported by Zephyr out of the box.
Unfortunately, I can’t access the link without signing in, but I assume you had to at least add a CMake script in This is something we’re not testing right now in CI, and I’d rather we add this configuration to our suite as well and make it much more easily accessible for maintainers to test and use. |
LLVM is officially supported and tested with CI: #85542. For example, see #87088 (comment). However, the CI is currently only building for
https://crrev.com/c/6349236 is publicly accessible. No sign in is required to view it. I'll see if I can create an upstream change to cover this path in CI. At the very least, it should be possible to demonstrate the size issue with gcc using |
When compiling with C++ enabled (CONFIG_CPP), add an unused member to
prevent an empty struct; this makes the struct size the same for both C
and C++.
Fixes the following warnings:
In file included from include/zephyr/drivers/gpio.h:22:
In file included from include/zephyr/tracing/tracing.h:9:
In file included from include/zephyr/kernel.h:17:
In file included from include/zephyr/kernel_includes.h:32:
In file included from include/zephyr/kernel_structs.h:29:
In file included from include/zephyr/arch/structs.h:29:
include/zephyr/arch/riscv/structs.h:11:1: error: empty struct has size 0
in C, size 1 in C++ [-Werror,-Wextern-c-compat]
11 | struct _cpu_arch {
| ^
In file included from include/zephyr/drivers/gpio.h:22:
In file included from include/zephyr/tracing/tracing.h:9:
In file included from include/zephyr/kernel.h:17:
In file included from include/zephyr/kernel_includes.h:36:
In file included from include/zephyr/arch/cpu.h:25:
In file included from include/zephyr/arch/riscv/arch.h:18:
include/zephyr/arch/riscv/thread.h:68:1: error: empty struct has size 0
in C, size 1 in C++ [-Werror,-Wextern-c-compat]
68 | struct _thread_arch {
| ^