pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Remove dependence on -fwrapv semantics in a few places.
2+ messages / 1 participants
[nested] [flat]

* pgsql: Remove dependence on -fwrapv semantics in a few places.
@ 2024-08-15 20:49  Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Nathan Bossart @ 2024-08-15 20:49 UTC (permalink / raw)
  To: pgsql-committers@lists.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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9e9a2b7031f64e49fcaf28f21a4e70eb1212165f

Modified Files
--------------
src/backend/utils/adt/cash.c               |  12 +--
src/backend/utils/adt/numeric.c            |   4 +-
src/backend/utils/adt/numutils.c           |  34 ++++----
src/backend/utils/adt/timestamp.c          |  28 +-----
src/include/common/int.h                   | 131 +++++++++++++++++++++++++++--
src/interfaces/ecpg/pgtypeslib/timestamp.c |  11 +--
src/test/regress/expected/timestamp.out    |  13 +++
src/test/regress/expected/timestamptz.out  |  13 +++
src/test/regress/sql/timestamp.sql         |   4 +
src/test/regress/sql/timestamptz.sql       |   4 +
10 files changed, 189 insertions(+), 65 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Remove dependence on -fwrapv semantics in jsonb.
@ 2024-08-16 16:27  Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Nathan Bossart @ 2024-08-16 16:27 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Remove dependence on -fwrapv semantics in jsonb.

This commit updates a couple of places in the jsonb code to no
longer rely on signed integer wrapping for correctness.  Like
commit 9e9a2b7031, 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.

This commit makes use of the newly introduced pg_abs_s32() routine
to negate a signed integer (that is known to be negative) for
comparison with an unsigned integer.  In passing, change one use of
INT_MIN to the more portable PG_INT32_MIN.

Reported-by: Alexander Lakhin
Author: Joseph Koshakow
Reviewed-by: Jian He
Discussion: https://postgr.es/m/CAAvxfHdBPOyEGS7s%2Bxf4iaW0-cgiq25jpYdWBqQqvLtLe_t6tw%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/108d2adb9e9e084cd57bf514d06ef4b954719ffa

Modified Files
--------------
src/backend/utils/adt/jsonfuncs.c   |  7 ++++---
src/test/regress/expected/jsonb.out | 18 ++++++++++++++++++
src/test/regress/sql/jsonb.sql      |  3 +++
3 files changed, 25 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-08-16 16:27 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-08-15 20:49 pgsql: Remove dependence on -fwrapv semantics in a few places. Nathan Bossart <nathan@postgresql.org>
2024-08-16 16:27 pgsql: Remove dependence on -fwrapv semantics in jsonb. Nathan Bossart <nathan@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox