<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Looking through the gcc testsuite turned up an interesting edge case. Let's assume our target leaves a hole for alignment in struct x, as do x86 and powerpc. Do you think the following code can validly abort?</div><div><br class="webkit-block-placeholder"></div><div><div> struct x { char c; short s; };</div><div> int i; char *p;</div></div><div> memset(&X, 0, sizeof(struct x));</div><div> memset(&Y, 22, sizeof(struct x));</div><div> X = Y;</div><div> for (i=0, p=(char *)&X; i<sizeof(struct x); i++, p++)</div><div> if (*p != 22)</div><div> abort();</div><div><br class="webkit-block-placeholder"></div><div>The memset's and char-by-char comparison are clearly valid references; the questionable bit is the struct copy, which llvm-gcc currently does field-by-field, skipping the hole. C99 says</div><div><br class="webkit-block-placeholder"></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Times; ">In <i>simple assignment</i><span style="font: 12.0px Helvetica"> </span>(<span style="font: 12.0px Courier"><b>=</b></span>), the value of the right operand is converted to the type of the<span style="font: 12.0px Helvetica"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Times; ">assignment expression and replaces the value stored in the object designated by the left<span style="font: 12.0px Helvetica"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Times; ">operand.<span style="font: 12.0px Helvetica"> </span></div><div><br class="webkit-block-placeholder"></div><div>I would take "replaces the value" to mean "replaces the entire value", but it could be read otherwise, I suppose. </div><div><br class="webkit-block-placeholder"></div><div>The current code seems to me to assume holes in structs can't ever be validly accessed, which isn't right, as we see here. They are often nondeterministic (this is explicit for initialization in C99) but not always.</div><div><br></div>
</div></body></html>