<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Aug 2, 2017 at 7:02 AM Peter Lawrence <<a href="mailto:peterl95124@sbcglobal.net">peterl95124@sbcglobal.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Paul,<br>
The proposition under discussion is this<br>
<br>
Deleting UB, rather than warning about UB, should not be the default,<br>
as this is contrary to the essentially universal software engineering<br>
practice of writing software that is compiler warning free, static<br>
analyzer warning free, and dynamic analyzer warning free.<br></blockquote><div><br>There seems to be disagreement between you & most/everyone else who've discussed this.<br><br>I (& I believe others) don't see a contrtadiction here. Deleting UB code is based on the assumption that someone is writing code that is warning, static analysis, and dynamic analysis warning free. The belief is that the code is dead, that's why it's deleted. & not that the user wrote dead code, but it's contextually dead based on inlining, etc - as examples have been given (& one can question/discuss the validity of those examples - but they're certainly proof of existence of steps where benign/good/reasonable code still produces UB-dead code after optimizations that can be removed by the compiler while maintaining the developers intend and potentially improving the performance, code size, etc, of the program).<br><br>If I understand correctly, you disagree that this happens in practice (that the only time UB code is ever removed is because the user's code was buggy in the first place) - there are some paths (suggested) to discover whether that's the case.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
This is based on the assumption that in order for llvm to be useful to its<br>
users it should mitigate rather than exacerbate the problems inherent<br>
in the language w.r.t. UB.<br>
<br>
No one is debating in this thread what the standard does or should say.<br>
<br>
After suggesting that the user should have an opt-in option for deleting<br>
UB it was suggested that this would be awkward to implement in llvm.<br>
I disagree, but it seems that the burden of proof falls on me, so in the<br>
fullness of time I will do this. (In particular I believe there should be a<br>
UBCE pass, just like there is a DCE pass).<br>
<br>
<br>
Peter Lawrence.<br>
<br>
<br>
<br>
<br>
<br>
> On Aug 2, 2017, at 6:29 AM, Robinson, Paul <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>> wrote:<br>
><br>
>> Saying “The C++ language lets me assume that that won’t happen, &<br>
>> optimize on that basis” is an assumption that that’s what the user<br>
>> wants, but you haven’t asked you’ve just assumed, and AFAICT it is an<br>
>> incorrect assumption.<br>
><br>
> Well, by using C++, the programmer agrees that the rules of the language<br>
> apply to their program, and the rules of the language say that the<br>
> compiler can do whatever it likes. So whether the user wants it or not,<br>
> that's what they have effectively agreed to.<br>
><br>
> undefined behavior<br>
> behavior for which this International Standard imposes no requirements<br>
> [ Note: Undefined behavior may be expected when this International<br>
> Standard omits any explicit definition of behavior or when a program<br>
> uses an erroneous construct or erroneous data. Permissible undefined<br>
> behavior ranges from ignoring the situation completely with<br>
> unpredictable results, to behaving during translation or program<br>
> execution in a documented manner characteristic of the environment<br>
> (with or without the issuance of a diagnostic message), to terminating<br>
> a translation or execution (with the issuance of a diagnostic message).<br>
> Many erroneous program constructs do not engender undefined behavior;<br>
> they are required to be diagnosed.<br>
> —end note ]<br>
><br>
> If you want to argue that it is *more useful* to the programmer to have<br>
> diagnostics for undefined behavior as represented in their source code,<br>
> I expect you would get essentially universal agreement. But what I am<br>
> understanding from this thread is an argument that it's a *requirement*<br>
> to diagnose UB, and that is just not what the language requires, and<br>
> consequently not what the user is entitled to.<br>
><br>
> If I'm misunderstanding, I'd love to be corrected.<br>
> Thanks,<br>
> --paulr<br>
<br>
</blockquote></div></div>