This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Testcase for pr37868 is broken; how shall we fix it?
- From: Mark Mitchell <mark at codesourcery dot com>
- To: "gcc-patches >> GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 05 Mar 2009 15:11:06 -0800
- Subject: Testcase for pr37868 is broken; how shall we fix it?
The test case in gcc.dg/torture/pr37868.c is clearly broken, on many
hardware platforms. It uses an "unsigned int *" to access a variable
whose alignment is not guaranteed. Depending on the hardware that might
work, generate SIGBUS, or just result in bogus results.
struct X {
unsigned char pad : 4;
unsigned int a : 32;
unsigned int b : 24;
unsigned int c : 6;
} __attribute__((packed));
int main (void)
{
struct X x;
...
bad_bits = ((unsigned int)-1) ^ *(1+(unsigned int *) &x);
}
The test also doesn't zero out x, before setting some of the fields, so
could well result in false passes, even on platforms without the
alignment problem.
We've already got a dg-skip-if for SPARC in the test. But, in general,
this test is going to fail on other strict alignment platforms as well.
ARM is an example; on ARM, this is a 9-byte structure with 1-byte
alignment and can end up with 1-byte alignment on the stack.
We don't have a strict-alignment check in target-supports. I could add
one, hard-coding a list of platforms that are strict-alignment targets,
since there's no obvious way to probe at run-time. (You can't guarantee
that you'll get a signal.) I could just hard-code more platforms to
skip into the test. I could fix the test to use char to read from the
unaligned memory location -- but it appears that the intent of the test
case was specifically to use this non-portable construct.
Recommendations?
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713