This is an archive of the discontinued LLVM Phabricator instance.

Avoid UB in maxIntN(64).
ClosedPublic

Authored by jlebar on Jul 16 2016, 3:20 PM.

Details

Summary

Previously we were relying on 2's complement underflow in an int64_t.
Now we cast to a uint64_t so we explicitly get the behavior we want.

Diff Detail

Event Timeline

jlebar updated this revision to Diff 64237.Jul 16 2016, 3:20 PM
jlebar retitled this revision from to Avoid UB in maxIntN(64)..
jlebar updated this object.
jlebar added a reviewer: rnk.
jlebar added subscribers: llvm-commits, dylanmckay.
compnerd accepted this revision.Jul 16 2016, 6:35 PM
compnerd added a reviewer: compnerd.
This revision is now accepted and ready to land.Jul 16 2016, 6:35 PM
majnemer added inline comments.
include/llvm/Support/MathExtras.h
348

I'd just rewrite it as:

(UINT64_C(1)<<(N-1)) - 1
jlebar updated this revision to Diff 64242.Jul 16 2016, 11:26 PM
jlebar marked an inline comment as done.
jlebar edited edge metadata.

Simplify the expression.

jlebar added inline comments.Jul 17 2016, 12:03 AM
include/llvm/Support/MathExtras.h
348

Oy. Done, thank you.

This revision was automatically updated to reflect the committed changes.