Open Quuxplusone opened 4 years ago
Bugzilla Link | PR45607 |
Status | NEW |
Importance | P normal |
Reported by | Pascal Cuoq (cuoq@trust-in-soft.com) |
Reported on | 2020-04-19 07:07:52 -0700 |
Last modified on | 2020-04-21 10:55:32 -0700 |
Version | 10.0 |
Hardware | PC Linux |
CC | alexey.salmin@gmail.com, blitzrakete@gmail.com, dgregor@apple.com, efriedma@quicinc.com, erik.pilkington@gmail.com, florian_hahn@apple.com, lebedev.ri@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, sbansal@iitd.ac.in, yuanfang.chen@sony.com |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
I'm pretty sure this is UB, and is a classical example of strict aliasing rules
violation,
i.e. not a miscompile. Have you read
https://gist.github.com/shafik/848ae25ee209f698763cffee272a58f8 ?
@Roman
Apparently I must have read it, since I provided feedback on it when it was in draft form. I don't see where it specifically addresses the question at play here.
I have also put in writing the claim that memory reuse is allowed in C, in the article cited as [25] in Shafik's post, so if it turns out that I was wrong all this time, I shall be disappointed that no-one bothered to tell me so.
Important: Note that this bug report is against the C compiler Clang.
See http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_236.htm
Note the somewhat disappointing response from WG14: the committee response says this is undefined behavior, but the rationale does not correspond to any wording in the C standard. :(
What do the C++ rules look like these days? I was trying to decipher [intro.object], but the "implicitly creating objects" rules aren't well-organized.
In C++, pointers point to specific objects, not just to storage, and objects are only created by explicit source syntax (new-expressions, declarations, temporaries that create objects, assignments that are syntactically performed through union members).
Under the C++ rules, it's valid to reorder even a store past a store if their TBAA information is different and there are no intervening lifetime events on that storage.
(In reply to Richard Smith from comment #4)
> See http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_236.htm
>
> Note the somewhat disappointing response from WG14: the committee response
> says this is undefined behavior, but the rationale does not correspond to
> any wording in the C standard. :(
Thanks Richard for sharing this response from WG14. Even though they provide a
clear response, they do say that "The current situation requires more
consideration". I am wondering if any follow-up discussion took place on this,
or was it not considered? The conclusion of the committee does seem to run
contrary to the textual and formal specifications (e.g., Michael Norrish's
formalization) of C available in the literature.