site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=sGK1Jb+9QaFiOhAZzuR8TQn56Cme8RmtF+dYsdUT+nG4QkskP4qeKBE4B7Ht+KlO8shUzLNmIQgl7I7qEXE+wJDPnQOzs85NlXaRANbG2ZBQV4cihc1vTlqnqVK5VATz/EU/NJ72JUhRYdSI+KLFbEzxXPAnlnQQAY+rFFRfnpM= There is a bug in the gcc optimizer that only shows up with the darwin build, not on the 4.0.1 I download from gnu and use on a non-mac. The following C code snippet: #include <inttypes.h> #include <stdlib.h> #define ALIGN_PTR(p,a) ((void *)( (((size_t)(p))+(a)-1)&~((size_t)(a)-1))) void *foo(void) { float x[13]; return ALIGN_PTR(x,16); } is designed to align 'x' on a 16-byte boundary. This code is for illustrative purposes only (I know you can't return local variables from a function, and if you align a array of 13 4-byte elements, the most you can use is 10 elements)... etc. The problem is that with '-O1', gcc will discard the alignment instructions. I figured out that gcc is using '-mpreferred-stack-boundary=4' to assume the stack frame is automatically aligned on a 16-byte boundary. That's great, however that says nothing about the variables declared inside the stack frame. In this case, 'x' is only aligned on a 4-byte boundary, not 16-byte. I can fix this one of two ways: using '-mpreferred-stack-boundary=2' will cause gcc to emit the correct code, however that causes other problems (called functions will no longer able to assume a nice stack alignment). The other way is to add '__attribute__((aligned(16)))'. Since the stack frame is already aligned, gcc can force the alignment of the variable for me. The real problem is that gcc should not assume that the variable is aligned in the first place! Is this the right place for the bug report, or should I forward it somewhere else? -- Scott _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com