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

Strict aliasing build errors in unit test code #1984

Closed
jphickey opened this issue Oct 1, 2021 · 0 comments · Fixed by #1986 or #2001
Closed

Strict aliasing build errors in unit test code #1984

jphickey opened this issue Oct 1, 2021 · 0 comments · Fixed by #1986 or #2001
Assignees
Milestone

Comments

@jphickey
Copy link
Contributor

jphickey commented Oct 1, 2021

Describe the bug
When using strict aliasing in combination with tests (i.e. ENABLE_UNIT_TESTS=true), additional aliasing warnings are produced by GCC 10.3.

To Reproduce
Build CFE with tests enabled along with strict aliasing compiler settings (-O3 -fstrict-aliasing -Wstrict-aliasing=2), build will fail with errors such as:

<top>/cfe/modules/core_api/ut-stubs/src/cfe_es_handlers.c: In function ‘UT_DefaultHandler_CFE_ES_GetAppID’:
<top>/cfe/modules/core_api/ut-stubs/src/cfe_es_handlers.c:136:60: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
  136 |         UT_GetDataBuffer(UT_KEY(CFE_ES_GetAppID), (void **)&IdBuff, &BuffSize, &Position);
      |                                                            ^~~~~~~
<top>/cfe/modules/core_api/ut-stubs/src/cfe_es_handlers.c: In function ‘UT_DefaultHandler_CFE_ES_GetTaskID’:
<top>/cfe/modules/core_api/ut-stubs/src/cfe_es_handlers.c:170:61: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
  170 |         UT_GetDataBuffer(UT_KEY(CFE_ES_GetTaskID), (void **)&IdBuff, &BuffSize, &Position);
      |                                                             ^~~~~~~

Expected behavior
Should build cleanly

System observed on:
Ubuntu 21.04 (w/gcc 10.3)

Additional context
Most of these are related to (void**) casts, which is easily resolved by making another local void* variable to temporarily hold the pointer.

Reporter Info
Joseph Hickey, Vantage Systems, Inc.

@jphickey jphickey self-assigned this Oct 1, 2021
@jphickey jphickey added the bug label Oct 1, 2021
jphickey added a commit to jphickey/cFE that referenced this issue Oct 1, 2021
Use an actual `void*` value when invoking functions
that output an opaque pointer value.  If necessary
the value of this pointer can then be assigned to
the real pointer type to dereference.
astrogeco added a commit to astrogeco/cFE that referenced this issue Oct 28, 2021
@astrogeco astrogeco self-assigned this Oct 28, 2021
@skliper skliper added this to the Draco milestone Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants