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

testsuite: coverage: fix -Wcast-align warning #53832

Merged
merged 1 commit into from
Jan 19, 2023

Conversation

nmeum
Copy link
Contributor

@nmeum nmeum commented Jan 16, 2023

While porting the coverage.c file from RIOT to Zephyr (which employs different compiler flags) I noticed the following -Wcast-align GCC warnings on arm:

coverage.c: In function 'buff_write_u64':
coverage.c: error: cast increases required alignment of target type [-Werror=cast-align]
   64 |         *((uint32_t *)((uint8_t *)buffer + *off) + 0) = (uint32_t)(v & MASK_32BIT);
      |           ^
coverage.c: error: cast increases required alignment of target type [-Werror=cast-align]
   65 |         *((uint32_t *)((uint8_t *)buffer + *off) + 1) = (uint32_t)((v >> 32) &
      |           ^
coverage.c: In function 'buff_write_u32':
coverage.c: error: cast increases required alignment of target type [-Werror=cast-align]
   75 |         *((uint32_t *)((uint8_t *)buffer + *off)) = v;
      |           ^

I think, as is, the current implementation may perform unaligned memory accesses which may not be supported on certain platforms. To workaround that, I have rewritten the code for RIOT using byte-wise writes using memcpy. Proposing a backport of this change as I figured it might be useful for Zephyr as well. If you are not interested in this change feel free to close this PR.

@nmeum nmeum requested a review from nashif as a code owner January 16, 2023 12:31
@nmeum nmeum changed the title testsuite: coverage: fix -Wcast-align error testsuite: coverage: fix -Wcast-align warning Jan 16, 2023
@zephyrbot zephyrbot added the area: Testsuite Testsuite label Jan 16, 2023
@nmeum nmeum force-pushed the coverage-memcpy branch 2 times, most recently from 2901f24 to 6b9761f Compare January 16, 2023 13:30
While porting the coverage.c file from RIOT to Zephyr, which employs
different compiler flags, I noticed several -Wcast-align GCC warnings on
arm. I think, as is, the current implementation may perform unaligned
memory accesses which may not be supported on certain platforms. To
workaround that, I have rewritten the code for RIOT using
bytewise-writes with `memcpy`.

Signed-off-by: Sören Tempel <tempel@uni-bremen.de>
@nashif nashif merged commit cf34afd into zephyrproject-rtos:main Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants