Remove dependence on -fwrapv semantics in a few places.
Nathan Bossart <nathan@postgresql.org>
Remove dependence on -fwrapv semantics in a few places. This commit attempts to update a few places, such as the money, numeric, and timestamp types, to no longer rely on signed integer wrapping for correctness. This is intended to move us closer towards removing -fwrapv, which may enable some compiler optimizations. However, there is presently no plan to actually remove that compiler option in the near future. Besides using some of the existing overflow-aware routines in int.h, this commit introduces and makes use of some new ones. Specifically, it adds functions that accept a signed integer and return its absolute value as an unsigned integer with the same width (e.g., pg_abs_s64()). It also adds functions that accept an unsigned integer, store the result of negating that integer in a signed integer with the same width, and return whether the negation overflowed (e.g., pg_neg_u64_overflow()). Finally, this commit adds a couple of tests for timestamps near POSTGRES_EPOCH_JDATE. Author: Joseph Koshakow Reviewed-by: Tom Lane, Heikki Linnakangas, Jian He Discussion: https://postgr.es/m/CAAvxfHdBPOyEGS7s%2Bxf4iaW0-cgiq25jpYdWBqQqvLtLe_t6tw%40mail.gmail.com
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/utils/adt/cash.c | modified | +7 −5 |
| src/backend/utils/adt/numeric.c | modified | +2 −2 |
| src/backend/utils/adt/numutils.c | modified | +16 −18 |
| src/backend/utils/adt/timestamp.c | modified | +4 −24 |
| src/include/common/int.h | modified | +123 −8 |
| src/interfaces/ecpg/pgtypeslib/timestamp.c | modified | +3 −8 |
| src/test/regress/expected/timestamp.out | modified | +13 −0 |
| src/test/regress/expected/timestamptz.out | modified | +13 −0 |
| src/test/regress/sql/timestamp.sql | modified | +4 −0 |
| src/test/regress/sql/timestamptz.sql | modified | +4 −0 |
Discussion
- Remove dependence on integer wrapping 85 messages · 2024-06-09 → 2024-12-09