mirror of https://github.com/YosysHQ/abc.git
Fix strict aliasing violations
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 commit is contained in:
parent
4c08da846a
commit
cfd526afd0
|
|
@ -233,7 +233,7 @@ static inline Hop_Obj_t * Hop_ManFetchMemory( Hop_Man_t * p )
|
||||||
if ( p->pListFree == NULL )
|
if ( p->pListFree == NULL )
|
||||||
Hop_ManAddMemory( p );
|
Hop_ManAddMemory( p );
|
||||||
pTemp = p->pListFree;
|
pTemp = p->pListFree;
|
||||||
p->pListFree = *((Hop_Obj_t **)pTemp);
|
memcpy(&p->pListFree, pTemp, sizeof(Hop_Obj_t *));
|
||||||
memset( pTemp, 0, sizeof(Hop_Obj_t) );
|
memset( pTemp, 0, sizeof(Hop_Obj_t) );
|
||||||
if ( p->vObjs )
|
if ( p->vObjs )
|
||||||
{
|
{
|
||||||
|
|
@ -245,8 +245,8 @@ static inline Hop_Obj_t * Hop_ManFetchMemory( Hop_Man_t * p )
|
||||||
}
|
}
|
||||||
static inline void Hop_ManRecycleMemory( Hop_Man_t * p, Hop_Obj_t * pEntry )
|
static inline void Hop_ManRecycleMemory( Hop_Man_t * p, Hop_Obj_t * pEntry )
|
||||||
{
|
{
|
||||||
pEntry->Type = AIG_NONE; // distinquishes dead node from live node
|
pEntry->Type = AIG_NONE; // distinguishes dead node from live node
|
||||||
*((Hop_Obj_t **)pEntry) = p->pListFree;
|
memcpy(pEntry, &p->pListFree, sizeof(Hop_Obj_t *));
|
||||||
p->pListFree = pEntry;
|
p->pListFree = pEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,14 +88,16 @@ void Hop_ManStopMemory( Hop_Man_t * p )
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
void Hop_ManAddMemory( Hop_Man_t * p )
|
void Hop_ManAddMemory( Hop_Man_t * p )
|
||||||
{
|
{
|
||||||
char * pMemory;
|
Hop_Obj_t * pMemory;
|
||||||
|
char *PMemAlign = 0;
|
||||||
int i, nBytes;
|
int i, nBytes;
|
||||||
assert( sizeof(Hop_Obj_t) <= 64 );
|
assert( sizeof(Hop_Obj_t) <= 64 );
|
||||||
assert( p->pListFree == NULL );
|
assert( p->pListFree == NULL );
|
||||||
// assert( (Hop_ManObjNum(p) & IVY_PAGE_MASK) == 0 );
|
// assert( (Hop_ManObjNum(p) & IVY_PAGE_MASK) == 0 );
|
||||||
// allocate new memory page
|
// allocate new memory page
|
||||||
nBytes = sizeof(Hop_Obj_t) * (1<<IVY_PAGE_SIZE) + 64;
|
nBytes = sizeof(Hop_Obj_t) * (1<<IVY_PAGE_SIZE) + 64;
|
||||||
pMemory = ABC_ALLOC( char, nBytes );
|
PMemAlign = PMemAlign + 64 - (((int)(ABC_PTRUINT_T)PMemAlign) & 63);
|
||||||
|
pMemory = (Hop_Obj_t *)PMemAlign;
|
||||||
Vec_PtrPush( p->vChunks, pMemory );
|
Vec_PtrPush( p->vChunks, pMemory );
|
||||||
// align memory at the 32-byte boundary
|
// align memory at the 32-byte boundary
|
||||||
pMemory = pMemory + 64 - (((int)(ABC_PTRUINT_T)pMemory) & 63);
|
pMemory = pMemory + 64 - (((int)(ABC_PTRUINT_T)pMemory) & 63);
|
||||||
|
|
@ -105,10 +107,12 @@ void Hop_ManAddMemory( Hop_Man_t * p )
|
||||||
p->pListFree = (Hop_Obj_t *)pMemory;
|
p->pListFree = (Hop_Obj_t *)pMemory;
|
||||||
for ( i = 1; i <= IVY_PAGE_MASK; i++ )
|
for ( i = 1; i <= IVY_PAGE_MASK; i++ )
|
||||||
{
|
{
|
||||||
*((char **)pMemory) = pMemory + sizeof(Hop_Obj_t);
|
Hop_Obj_t *NextPtr = pMemory + 1;
|
||||||
pMemory += sizeof(Hop_Obj_t);
|
memcpy(pMemory, &NextPtr, sizeof(Hop_Obj_t *));
|
||||||
|
pMemory += 1;
|
||||||
}
|
}
|
||||||
*((char **)pMemory) = NULL;
|
Hop_Obj_t *NullPtr = NULL;
|
||||||
|
memcpy(pMemory, &NullPtr, sizeof(Hop_Obj_t *));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue