Skip to content

Fix strict aliasing violations#519

Open
heshpdx wants to merge 1 commit into
berkeley-abc:masterfrom
heshpdx:master
Open

Fix strict aliasing violations#519
heshpdx wants to merge 1 commit into
berkeley-abc:masterfrom
heshpdx:master

Conversation

@heshpdx

@heshpdx heshpdx commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

The cast to char** is a violation of strict aliasing rules. Compilers may generate incorrect code due to this issue. Using memcpy to avoid the issue. Not expecting perf difference.

This was found via testing in SPEC CPU's 729.abc_r.

The cast to char** is a violation of strict aliasing rules.
Compilers may generate incorrect code due to this issue.
Using memcpy to avoid the issue. Not expecting perf difference.
Comment thread src/aig/hop/hopMem.c
// allocate new memory page
nBytes = sizeof(Hop_Obj_t) * (1<<IVY_PAGE_SIZE) + 64;
pMemory = ABC_ALLOC( char, nBytes );
PMemAlign = PMemAlign + 64 - (((int)(ABC_PTRUINT_T)PMemAlign) & 63);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

PMemAlign is initialized to zero at this point, so this is incorrect.
That's likely also the reason why the CI is failing.

The strict-aliasing issues are only in the type-punning accesses:

*((Hop_Obj_t **)pTemp)
*((char **)pMemory)

The surrounding allocation/alignment code can and should stay the same.

Proposed change:

 char * pMemory;
 Hop_Obj_t * pEntry, * pNext;
 ...
 pMemory = ABC_ALLOC( char, nBytes );
 Vec_PtrPush( p->vChunks, pMemory );

 pMemory = pMemory + 64 - (((int)(ABC_PTRUINT_T)pMemory) & 63);
 Vec_PtrPush( p->vPages, pMemory );

 pEntry = (Hop_Obj_t *)pMemory;
 p->pListFree = pEntry;
 for ( i = 1; i <= IVY_PAGE_MASK; i++ )
 {
     pNext = pEntry + 1;
     memcpy( pEntry, &pNext, sizeof(Hop_Obj_t *) );
     pEntry++;
 }
 pNext = NULL;
 memcpy( pEntry, &pNext, sizeof(Hop_Obj_t *) );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants