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

Possible alias warning on certain compiler versions #1971

Closed
jphickey opened this issue Sep 21, 2021 · 0 comments · Fixed by #1972 or #1967
Closed

Possible alias warning on certain compiler versions #1971

jphickey opened this issue Sep 21, 2021 · 0 comments · Fixed by #1972 or #1967
Assignees
Milestone

Comments

@jphickey
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When getting the address of a memory pool buffer directly as a CFE_SB_BufferD_t * type, it may trigger an alias warning in certain compilers/configurations.

Example when using -O3 -fstrict-aliasing -Wstrict-aliasing=2 on GCC 10.3:

cfe/modules/sb/fsw/src/cfe_sb_buf.c: In function ‘CFE_SB_GetBufferFromPool’:
cfe/modules/sb/fsw/src/cfe_sb_buf.c:115:54: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
  115 |     stat1 = CFE_ES_GetPoolBuf((CFE_ES_MemPoolBuf_t *)&bd, CFE_SB_Global.Mem.PoolHdl, AllocSize);
      |                                                      ^~~
cfe/modules/sb/fsw/src/cfe_sb_buf.c: In function ‘CFE_SB_GetDestinationBlk’:
cfe/modules/sb/fsw/src/cfe_sb_buf.c:221:53: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
  221 |     Stat = CFE_ES_GetPoolBuf((CFE_ES_MemPoolBuf_t *)&Dest, CFE_SB_Global.Mem.PoolHdl, sizeof(CFE_SB_DestinationD_t));
      |                                                     ^~~~~

Describe the solution you'd like
Should build clean

Additional context
Using a local CFE_ES_MemPoolBuf_t intermediate value should avoid this.

Requester Info
Joseph Hickey, Vantage Systems, Inc.

@jphickey jphickey self-assigned this Sep 21, 2021
jphickey added a commit to jphickey/cFE that referenced this issue Sep 21, 2021
Use an intermediate variable of type CFE_ES_MemPoolBuf_t to store
the address.
astrogeco added a commit that referenced this issue Sep 22, 2021
Fix #1971, avoid alias warning on some compilers
astrogeco added a commit that referenced this issue Sep 22, 2021
Fix #1971, avoid alias warning on some compilers
@skliper skliper added this to the 7.0.0 milestone Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants