<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 30, 2019 at 3:51 AM Myria <<a href="mailto:myriachan@gmail.com">myriachan@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>This document doesn't mention another possible behavior of signed overflow: saturation. Saturation arithmetic supposedly is what many DSPs do on overflow, but I wouldn't know.</div><div><br></div><div>I call the three cases of when there is implementation-defined behavior as "snap", "trap" and "wrap" for the alliteration. I suppose the "can't happen" / undefined case could be "crap". =^-^=<br></div><div><br></div><div><br></div><div>I just noticed a problem in the document's example: fixed-size types. This is problematic because of integer promotion. Imagine a system in which "int" were 64 bits. Then this code:</div><div><br></div><div>auto const ret = a + 100u;</div><div><br></div><div>would actually generate a result of type "const unsigned int", which is 64 bits on such a platform. Then the overflow check does not work, and the result won't saturate as intended.<br></div><div><br></div><div>This clouds the actual issue you're trying to get at. Using simply "int" and "unsigned int" for the example solves the problem.<br></div></div></div></blockquote><div>I'm inclined to point the finger at "auto" here. Although this code would also not have been written if we taught to avoid relying on the "modulo" behaviour. The (I believe Google) check while processing JF's paper was that even unsigned overflow was often a bug.<br></div><div><br></div><div>I am also going to ask the author if there is a response to a reaction that this encourages breaking the language into dialects.</div><div>I would also like the author's take on the intended treatment of the well-formedness of signed overflow in constexpr. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div></div><div><br></div><br><div>Another example of how using fixed-sized types can cloud issues due to promotion:</div><div><br></div><div>std::uint16_t x = 65535u;</div><div>x *= x; // undefined behavior on most of today's platforms because of promotion to signed int<br></div><div><br></div><div>Melissa</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 29, 2019 at 6:04 PM Scott Schurr <<a href="mailto:s.scott.schurr@gmail.com" target="_blank">s.scott.schurr@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Greeting again SG12,</div><div dir="ltr"><br></div><div>Here's another email that I think got trapped for moderation yesterday but apparently can get through now. Sorry for the additional noise.</div><div dir="ltr"><br clear="all"><div><div dir="ltr" class="gmail-m_-317497393611677615gmail-m_7006456163629885157gmail_signature">Scott Schurr<br><a href="mailto:S.Scott.Schurr@gmail.com" target="_blank">S.Scott.Schurr@gmail.com</a></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 28, 2019 at 10:13 AM Scott Schurr <<a href="mailto:s.scott.schurr@gmail.com" target="_blank">s.scott.schurr@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi John,<div><br></div><div>Nice to hear from you. Thanks for your interest in the paper.</div><div><br></div><div>Regarding whether "can't happen" is a behavior, I'm expecting to hear varied well studied opinions (like yours) during the paper discussion. My perspective is that "can't happen" cannot be defined in a mechanistic way. It's not like, "The gear used to turn left but now turns right." However I think that "can't happen" can be defined in the sense that the result of an explosion can be quite well defined. Given an explosion of sufficient yield at a certain location there is a high probability that the building will collapse, but we're uncertain where the individual bricks will fall. We still understand the outcome sufficiently well to be able to talk about it.</div><div><br></div><div>My feeling is that it's not that different from talking about race conditions. We really don't know what the consequence of a race condition will be. But we can define a race condition.</div><div><br></div><div>Thanks for your thoughts.</div><div><br clear="all"><div><div dir="ltr" class="gmail-m_-317497393611677615gmail-m_7006456163629885157gmail-m_-8062042179736955175gmail_signature">Scott Schurr<br><a href="mailto:S.Scott.Schurr@gmail.com" target="_blank">S.Scott.Schurr@gmail.com</a></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 26, 2019 at 2:13 AM John McFarlane <<a href="mailto:john@mcfarlane.name" target="_blank">john@mcfarlane.name</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>When I read that title, I also had the reaction "you have the wrong target" but in my case, I assumed the target was SG20. I think it's a great paper to send to that study group.<br></div><div><br></div><div>My main concern, though, boils down to the idea that "Can't happen" is somehow a behaviour. It seems to be suggested, for example, that overflow as it occurs in current implementations can realistically be defined. I'm not sure that's practical because such behaviour is highly sensitive to many non-obvious factors. Overflow at a single point in the code may produce wildly different 'behaviours' depending on factors such as: from where it's invoked, various toolchain options and minor revisions to the implementation. And even with this information at hand, the write-up might well be onerous to the implementer and worse than useless for the user because it would involve describing in much detail the optimization algorithms involved. So I don't think implementation-defined is a straight-forward solution to the problem.<br></div><div><br></div><div>Generally, I agree I'd like to see effort put toward thinking of the correct way to deliver the idea of UB. It's the wrong wording to give to users of the language. It's implementor speak. Like a bailiff using legalese to explain why somebody has just lost their home, it causes confusion and anger.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail-m_-317497393611677615gmail-m_7006456163629885157gmail-m_-8062042179736955175gmail-m_-5861978000361409311gmail_attr">On Sat, 26 Jan 2019 at 08:54 Marc Glisse <<a href="mailto:marc.glisse@inria.fr" target="_blank">marc.glisse@inria.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
just a couple points missing from the paper:<br>
<br>
1) with g++-7 -O2 -Wall, the motivating example on the left produces:<br>
<br>
<source>: In function 'int32_t add_100_without_wrap(int32_t)':<br>
<source>:8:3: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow]<br>
if (ret < a)<br>
<br>
However, we removed the warning from gcc-8 because it was too noisy and <br>
impossible to work around when the optimization is what you actually want.<br>
<br>
2) At least with gcc, -ftrapv doesn't really work. You need <br>
-fsanitize=signed-integer-overflow -fsanitize-undefined-trap-on-error for <br>
something roughly equivalent to what -ftrapv is supposed to do.<br>
<br>
<br>
Now my opinion: you have the wrong target. Compilers that have a -fwrapv <br>
option (or -ftrapv or ubsan or ...) already indirectly describe the <br>
default behavior as undefined (and the standard already describes it as <br>
undefined), so it is already documented. Adding a sentence or 2 in the <br>
standard and on pages that nobody reads won't help. It seems that you want <br>
to talk either to teachers, so they warn their students more about the <br>
properties of signed overflow, or to compiler writers, to convince them to <br>
change the default to -fwrapv or -ftrapv (I hope they don't) or add more <br>
warnings.<br>
<br>
-- <br>
Marc Glisse<br>
_______________________________________________<br>
ub mailing list<br>
<a href="mailto:ub@isocpp.open-std.org" target="_blank">ub@isocpp.open-std.org</a><br>
<a href="http://www.open-std.org/mailman/listinfo/ub" rel="noreferrer" target="_blank">http://www.open-std.org/mailman/listinfo/ub</a><br>
</blockquote></div>
</blockquote></div></div>
</blockquote></div></div>
_______________________________________________<br>
ub mailing list<br>
<a href="mailto:ub@isocpp.open-std.org" target="_blank">ub@isocpp.open-std.org</a><br>
<a href="http://www.open-std.org/mailman/listinfo/ub" rel="noreferrer" target="_blank">http://www.open-std.org/mailman/listinfo/ub</a><br>
</blockquote></div></div>
_______________________________________________<br>
ub mailing list<br>
<a href="mailto:ub@isocpp.open-std.org" target="_blank">ub@isocpp.open-std.org</a><br>
<a href="http://www.open-std.org/mailman/listinfo/ub" rel="noreferrer" target="_blank">http://www.open-std.org/mailman/listinfo/ub</a><br>
</blockquote></div></div>