<br><br><div class="gmail_quote">On Sun, Feb 24, 2013 at 8:52 AM, Timo Sirainen <span dir="ltr"><<a href="mailto:tss@iki.fi" target="_blank">tss@iki.fi</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I was excited to find out about this feature and trying it out on my code.<br>
<br>
The first problem was that I had been using -1U instead of UINT_MAX a lot. I think it's pretty obvious that -1U is meant as UINT_MAX instead of overflowing the integer. Anyway, I switched them to UINT_MAX so this isn't really an issue.<br>

<br>
The main problem is with code like:<br>
<br>
        unsigned int foo = 1000; // always a positive number<br>
        int diff = -1; // positive or negative number that doesn't overflow/underflow foo<br>
<br>
        printf("%u\n", foo + diff);<br>
<br>
Because diff gets translated to UINT_MAX here, which then overflows the calculation. Couldn't these type of calculations somehow be skipped over? Or alternatively could the compiler give a warning when it's mixing up signed and unsigned integer calculations so these could at least be found easily at compile stage?<br>

<br></blockquote><div>Well, the problem with such a warning is that the code is perfectly Standard compliant and the behavior is very precisely dictated by the Standard; as such there is a probably LOT of code that has been written this way (mind you, with positive values of diff) and works like a charm, developers on this code are unlikely to be willing to see warnings on this... and Clang's rule of thumb for warnings is that if it cannot be on by default, then it's probably not worth it.<br>
 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I see someone else already asked about disabling the checks for some specific calculations. Will Dietz replied about planning to soon add "safe attributes" to do that. Is this implemented yet?</blockquote><div>
<br>The discussion is still on as to the syntax, the agreement should come soon though. Of course, no planned date for the change then landing.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 Or can I use some #pragma to remove the checks from md5/sha code files (I'd rather not want to mess with automake for this). I was also wondering about the possibility of doing this in a somewhat standard way by explicitly using modulo on the result, such as:<br>

<br>
printf("%u\n", (UINT_MAX + 5) % UINT_MAX);<br>
<br>
or even any modulo:<br>
<br>
printf("%u\n", (UINT_MAX + 5) % 2);<br>
<br>
I think these make it clear that modulo arithmetic is intended and an overflow can't be a bug.<br>
<br>
<br></blockquote><div>I am actually surprised that there is a trap on overflow on unsigned types, where it's perfectly defined.<br><br>-- Matthieu<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br>