[cfe-dev] RFC: Enforcing pointer type alignment in Clang
James Y Knight via cfe-dev
cfe-dev at lists.llvm.org
Thu Jan 14 15:43:22 PST 2016
Are those rules the same as the rules for what you're allowed to do with
null pointers? I think it would be pretty nice if the rules for what's
allowable to do with a null pointer, and what's allowable to do with an
unaligned pointer were the same rules. (Even if basically nobody can
actually understand what the rules are...)
E.g. apparently this is considered okay in C++, despite the apparent
dereference of "foo". (from chat on #llvm, apparently it arguably isn't
valid per the standard, but CWG232 calls that a defect, and it *is*
explicitly valid in C, per C11 6.5.3.2 paragraph 3):
int *foo = 0;
int *bar = &*foo;
So, in your rules, is this okay, or not:
int foo;
int *unaligned = (int*)(1 + (char*)(&foo));
int *bar = &*unaligned;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160114/2c678350/attachment.html>
More information about the cfe-dev
mailing list