Summary: | Alias stacked type cast interpretation regression | ||
---|---|---|---|
Product: | gcc | Reporter: | Sergei Larin <sergei_lus> |
Component: | middle-end | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | normal | CC: | alexcher, andrew, attardi, baisjing, cdfrey, chiabaut, cuerob, daniel, Dries.Decock, dvt, gael.guennebaud, gcc-bugs, gcc2eran, gray, hans.buchmann.wantuch, hazeman, honza, jacob, jsworley, lucifer_ww, mueller, myan, ricardo, rosenfeld, sb, schendel, sergei_lus, songyulu, sorenj, stillzhang, takahisa.yokota, tompa-l, vkolluri |
Priority: | P3 | ||
Version: | 4.4.0 | ||
Target Milestone: | --- | ||
Host: | x86_64-unknown-linux-gnu | Target: | x86_64-unknown-linux-gnu |
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: |
Description
Sergei Larin
2009-08-14 18:38:36 UTC
You are wrong to assume that the cast to char* changes the aliasing violation. In fact it is an access via char which is able to be done to any other type. So this: (((unsigned short *)(char *)&(ans)))[1] is an access of an float variable as an unsigned short and there is an aliasing violation there. *** This bug has been marked as a duplicate of 21920 *** First of all, I agree that a union would work better for type-punning, but... With all the respect I am not convinced that this is the case here. Even if I do something like this: tmp_ch = (char *)&ans; tmp_sh = (unsigned short *)tmp_ch; I would expect tmp_ch to be "aliased to everything", and it should in turn also hold for tmp_sh... unless you can say which standard (C99) rule says otherwise. ... but this argument aside, maybe you can explain why up to 4.3.2 GCC was "ok" with this code, and 4.4.0 explicitly changed its behavior - I could not readily track it down (could be my inability to trace it back). In a similar fashion I would appreciate a justification (C99 reference). Also, in 4.4.0 forwprop1 turns this: tmp_ch_10 = (char *) &ans; tmp_sh_11 = (short unsigned int *) tmp_ch_10; into this: tmp_sh_11 = (short unsigned int *) &ans; ...so alias analyzer does not even "see" the (char *) cast... 4.3.2 does not do this. The actual issue is that this breaks a long standing legacy code (a math library) and I see no provision to disable this new "feature" short of turning off strict aliasing all together. Thank you for your response - and information is very much appreciated. |