Jump to content

Struct Code That Fails To Generate Expression


Recommended Posts

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Boost C Compiler Bugs 6.8.1
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////// BUG /////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

#define s8 signed char
#define s16 signed int
#define s32 signed long

#define us8 unsigned char
#define us16 unsigned int
#define us32 unsigned long

typedef union {
us8 value;
} uus8;

typedef struct {
uus8 lo;
uus8 hi;
} sus16;

typedef union {
us16 value;
sus16 parts;
} uus16;

typedef struct {
uus16 lo;
uus16 hi;
} sus32;

typedef union {
us32 value;
sus32 parts;
} uus32;


void write(us8 value, us32 address);
void write_uus32(us8 value, uus32 address);

//This code work's okay

void original_code(uus32 value, us32 address)
{
write(value.parts.hi.parts.hi.value, address + 0 );
write(value.parts.hi.parts.lo.value, address + 1 );
write(value.parts.lo.parts.hi.value, address + 2 );
write(value.parts.lo.parts.lo.value, address + 3 );
}

// But, this code does not.


void failing_code(uus32 value, us32 address)
{
write_uus32(value.parts.hi.parts.hi.value, (uus32)(address + 0) );
write_uus32(value.parts.hi.parts.lo.value, (uus32)(address + 1) ); // fails to generate expression
write_uus32(value.parts.lo.parts.hi.value, (uus32)(address + 2) ); // fails to generate expression
write_uus32(value.parts.lo.parts.lo.value, (uus32)(address + 3) ); // fails to generate expression
}

// Work around 1

void work_around_1(uus32 value, uus32 address)
{
write_uus32( value.parts.hi.parts.hi.value, address );
address.value++;
write_uus32( value.parts.hi.parts.lo.value, address );
address.value++;
write_uus32( value.parts.lo.parts.hi.value, address );
address.value++;
write_uus32( value.parts.lo.parts.lo.value, address );
}

// Work around 2

void work_around_2(uus32 value, uus32 address)
{
write_uus32( value.parts.hi.parts.hi.value, (uus32)(address.value++) );
write_uus32( value.parts.hi.parts.lo.value, (uus32)(address.value++) );
write_uus32( value.parts.lo.parts.hi.value, (uus32)(address.value++) );
write_uus32( value.parts.lo.parts.lo.value, (uus32)(address.value++) );
}

 

Jacob Christ

www.pontech.com

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...