Skip to content

Conversation

thughes
Copy link
Contributor

@thughes thughes commented Oct 3, 2025

When using clang to build for RISC-V with these configs:

CONFIG_CPP=y
CONFIG_USERSPACE=n
CONFIG_SMP=n
CONFIG_FPU_SHARING=n

we get the following warnings:

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 {
| ^

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 {
| ^

This commit adds a test with those configs to verify compilation
succeeds. Although gcc doesn't emit these warnings, we can test with gcc
as well with a BUILD_ASSERT in include/zephyr/arch/riscv/thread.h and
include/zephyr/arch/riscv/structs.h that was added in #96943.

@thughes thughes force-pushed the push-tukkmmylosnk branch from 38e5a41 to dcd2b17 Compare October 3, 2025 00:04
@thughes thughes changed the title tests: riscv: Add test to verify C++ compilation tests: lib: cpp: cxx: Add test to verify C++ compilation Oct 3, 2025
@thughes thughes marked this pull request as ready for review October 3, 2025 21:08
@zephyrbot zephyrbot added area: Tests Issues related to a particular existing or missing test area: C++ labels Oct 3, 2025
Comment on lines 81 to 91
# Verify struct _cpu_arch struct _thread_arch are compatible with C++ when
# specific configs are enabled.
cpp.main.empty_struct_size:
build_only: true
extra_configs:
- CONFIG_USERSPACE=n
- CONFIG_SMP=n
- CONFIG_FPU_SHARING=n
Copy link
Member

Choose a reason for hiding this comment

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

AFAICS, this is a RISC-V specific issue; so, this should be limited to arch_allow: riscv. Also, a RISC-V integration_platforms should be added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like integration_platforms is not overriding the common integration_platforms at the top of the file which causes CI to fail, so I had to leave out arch_allow: riscv:

INFO: Potential tag based filters: {'kernel', 'cmsis_dsp', 'posix', 'wifi', 'mcumgr', 'bluetooth', 'net', 'test_framework'}
INFO: Potential test filters...(1 changed...)
INFO: /home/runner/work/zephyr/zephyr/zephyr/scripts/twister -c -T tests/lib/cpp/cxx --save-tests _test_plan_partial.json
INFO - Using Ninja..
INFO - Zephyr version: v4.2.0-5093-gc398f976766c
INFO - Using 'zephyr' toolchain.
INFO - Selecting default platforms per testsuite scenario
INFO - Building initial testsuite list...
INFO - Writing JSON report /home/runner/work/zephyr/zephyr/zephyr/twister-out/testplan.json
INFO - Writing JSON report _test_plan_partial.json
INFO: found boards:
INFO: No twister needed or partial twister run only...
INFO: Total tests gathered: 306
INFO: Error found: cpp.main.empty_struct_size on mps2/an385 (Not in testsuite arch allow list but is one of the integration platforms)
INFO: Error found: cpp.main.empty_struct_size on qemu_cortex_a53/qemu_cortex_a53 (Not in testsuite arch allow list but is one of the integration platforms)
INFO: Total tests to be run: 306
INFO: Total nodes to launch: 1
Changed files:
=========
tests/lib/cpp/cxx/testcase.yaml
=========

Copy link

sonarqubecloud bot commented Oct 6, 2025

When using clang to build for RISC-V with these configs:

CONFIG_CPP=y
CONFIG_USERSPACE=n
CONFIG_SMP=n
CONFIG_FPU_SHARING=n

we get the following warnings:

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 {
| ^

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 {
| ^

This commit adds a test with those configs to verify compilation
succeeds. Although gcc doesn't emit these warnings, we can test with gcc
as well with a BUILD_ASSERT in include/zephyr/arch/riscv/thread.h and
include/zephyr/arch/riscv/structs.h.

Signed-off-by: Tom Hughes <[email protected]>
@thughes thughes force-pushed the push-tukkmmylosnk branch from 34f8b36 to 2f49f38 Compare October 6, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C++ area: Tests Issues related to a particular existing or missing test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants