This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: more m68k breakage on m68k-linux
Andreas Schwab wrote:
Bernardo Innocenti <bernie@develer.com> writes:
I'm convinced that argptr missing from FIXED_REGISTERS was an anomaly,
but I still don't quite understand how it would affect init_reg_sets().
Could you elaborate?
memcpy (fixed_regs, initial_fixed_regs, sizeof fixed_regs);
memcpy (call_used_regs, initial_call_used_regs, sizeof call_used_regs);
sizeof fixed_regs > sizeof initial_fixed_regs
sizeof call_used_regs > sizeof initial_call_used_regs
Oh, I see. I had been thinking about memory trashing,
not uninitialized memory.
I apologize for being the root cause of such a subtle
bug.
To make sure this particular case will never show up again
on any backend, I'd like to add some static sanity checks.
We can't use the preprocessor because it doesn't know about
structure sizes.
Woundn't it be nice to have something like BOOST's static
assert for C? I've come up with this hack:
#define __STATIC_ASSERT_PASTE2(x,y) x ## y
#define __STATIC_ASSEET_PASTE(x,y) __PASTE2(x,y)
#define STATIC_ASSERT(EXPR) \
typedef struct { \
char ASSERTION_FAILED[(EXPR) ? 1 : -1]; \
} __STATIC_ASSERT_PASTE(__assertion_, __LINE__)
Here is a test case to show how it works:
int main(void)
{
static const int a = 42;
STATIC_ASSERT(sizeof(short) == sizeof(long)); // ERROR!
STATIC_ASSERT(sizeof(short) * 2 == sizeof(long)); OK
STATIC_ASSERT(10 > 30); // ERROR!
STATIC_ASSERT(a > 10); // OK
STATIC_ASSERT(a > 50); // OK??? Is this a GCC bug?
return 0;
}
Do you think we could include something like this
somewhere in GCC?
--
// Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/ http://www.develer.com/