3 ms·
This is why I implemented two's-complement with unsigned types, that don't have UB on overflow.
by gavinhoward 3y ago
This is why I implemented two's-complement with unsigned types, that don't have UB on overflow.
- kragen 3y agolike x > 2147483547u in this case?
- gavinhoward 3y agoCorrect. It will still overflow, but it's not UB and won't be optimized away.
- kragen 3y agoby 'overflow' do you mean 'set the high bit'
- gavinhoward 3y agoCorrect. I have routines that take the unsigned values and interpret them as signed, two's-complement values. So you would write this: val = temp1 + temp2; if (y_ssize_lt(val, temp1)) y_trap(); That `y_ssize_lt()` function computes whether `val` is less than `temp1` as though they were signed, two's-complement integers. But because they are actually unsigned, the compiler cannot be malicious and delete that code.
- kragen 3y agoi see, thanks maybe we should develop a nonmalicious compiler
- gavinhoward 3y agohttps://groups.google.com/g/boring-crypto/c/48qa1kWignU/m/o8GGp2K1DAAJ https://groups.google.com/g/boring-crypto/c/48qa1kWignU/m/o8...