3 ms·
1. It is so perfectly clear that no two C programmers can agree to a common set of rules. 2. A machine independent interpretation would prevent any memory safe
by gpderetta 10y ago
1. It is so perfectly clear that no two C programmers can agree to a common set of rules.
2. A machine independent interpretation would prevent any memory safety santiizer to do its job, which it seems to me much more useful than allowing such shenanigans.
3. The best resolution for everyone involved is for the program to abort as soon as it detect a rule violation. "Working" for some ill defined definition of working is not useful to anyone.
- kazinator 10y agoNo two C programmers can possibly disagree about what that code should do if it were to be defined. There are many ways of adding requirements to make it defined (and those ways will differ in what else they make defined). > The best resolution for everyone involved is for the program to abort as soon as it detect a rule violation. The pointer cast in the code makes it clear that the aliasing between the identically structured struct is intentional. (If we remove the cast, we have a diagnosable constraint violation: no need to whip out the memory sanitizers). At least we seem to agree as far as that optimizing based on the assumption that aliasing does not take place is one of the worst things that could happen. The rule violation is not diagnosed, and the obvious meaning doesn't occur either, but rather some weird result. For instance, garbage is accessed because the underlying struct is not yet initialized (on grounds that it's not necessary to initialize something before an improperly typed access to it).
- gpderetta 10y ago"No two C programmers can possibly disagree about what that code should do if it were to be defined." The whole point is that there is no agreement on how they should be defined. "At least we seem to agree as far as that optimizing based on the assumption that aliasing does not take place is one of the worst things that could happen" I do want the compiler to optimize assuming no aliasing but first I want: a) the rules to be clarified beyond the current mess; b) have a strict compilation mode (possibly on by default) that will enforce the rules so that mistakes can be caught. Such mode would necessarily be very slow as the C language is very unfriendly to such an analysis (in the worst case you need a shadow type map for every memory location), but given the nature of aliasing violations, even a debug only mode should catch the large majority of mistakes.