clang does not respect __attribute__((aligned(X))) for X >= 32 on arm64
| Originator: | sdefresne | ||
| Number: | rdar://16223901 | Date Originated: | 04-Mar-2014 07:09 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Reproducible: | Always |
Summary:
When declaring a variable on the stack with a field with a custom alignment, the custom alignment is ignored if it is greater than 32 (I'm not sure if the alignment is respected when smaller, it may be random chance).
Steps to Reproduce:
Compile the following code for armv7 or arm64:
template < size_t bytes, size_t alignment >
class Aligned {
private:
uint8_t __attribute__((aligned(alignment))) data_[bytes];
public:
uint8_t* data() {
return data_;
}
};
#define CHECK_ALIGNMENT(ALIGNMENT) \
{ Aligned<8, ALIGNMENT> raw ## ALIGNMENT; \
BOOL aligned = ((uintptr_t)(raw ## ALIGNMENT.data()) & (ALIGNMENT - 1)) == 0; \
NSLog(@"raw%d is aligned? %@", ALIGNMENT, aligned ? @"YES" : @"NO"); \
} while (0)
void TestAlignment() {
CHECK_ALIGNMENT(4);
CHECK_ALIGNMENT(8);
CHECK_ALIGNMENT(16);
CHECK_ALIGNMENT(32);
CHECK_ALIGNMENT(64);
CHECK_ALIGNMENT(128);
CHECK_ALIGNMENT(256);
CHECK_ALIGNMENT(512);
}
Expected Results:
Output on armv7:
2014-03-04 19:07:34.518 EmptyApplication[5452:60b] raw4 is aligned? YES
2014-03-04 19:07:34.519 EmptyApplication[5452:60b] raw8 is aligned? YES
2014-03-04 19:07:34.520 EmptyApplication[5452:60b] raw16 is aligned? YES
2014-03-04 19:07:34.520 EmptyApplication[5452:60b] raw32 is aligned? YES
2014-03-04 19:07:34.521 EmptyApplication[5452:60b] raw64 is aligned? YES
2014-03-04 19:07:34.521 EmptyApplication[5452:60b] raw128 is aligned? YES
2014-03-04 19:07:34.522 EmptyApplication[5452:60b] raw256 is aligned? YES
2014-03-04 19:07:34.522 EmptyApplication[5452:60b] raw512 is aligned? YES
Actual Results:
Output on arm64:
2014-03-04 18:59:12.068 EmptyApplication[5356:60b] raw4 is aligned? YES
2014-03-04 18:59:12.070 EmptyApplication[5356:60b] raw8 is aligned? YES
2014-03-04 18:59:12.071 EmptyApplication[5356:60b] raw16 is aligned? YES
2014-03-04 18:59:12.072 EmptyApplication[5356:60b] raw32 is aligned? NO
2014-03-04 18:59:12.073 EmptyApplication[5356:60b] raw64 is aligned? NO
2014-03-04 18:59:12.073 EmptyApplication[5356:60b] raw128 is aligned? NO
2014-03-04 18:59:12.074 EmptyApplication[5356:60b] raw256 is aligned? NO
2014-03-04 18:59:12.074 EmptyApplication[5356:60b] raw512 is aligned? NO
Version:
Xcode: Version 5.0.2 (5A3005)
OS X: Version 10.9.2, Build 13C64
clang: Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Notes:
Configuration:
Always occurs
Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!