123 Commits

Author SHA1 Message Date
Abseil Team
ed2114e8ff Stop using C++17 type traits polyfills
This will let us deprecate the declarations without triggering warnings in Abseil itself.

PiperOrigin-RevId: 894202105
Change-Id: I57bb2a1647be1fedf9b724a07042fd0f564ce074
2026-04-03 12:34:35 -07:00
Derek Bailey
78bacea21b Mark the implicit floating operators as constexpr for absl::int128 and absl::uint128
Mark the explicit floating point construct as constexpr for `absl::int128`.

PiperOrigin-RevId: 806159592
Change-Id: Ib68b34bd82c77c050fc090e0c7794761c41d22f1
2025-09-12 00:29:04 -07:00
Derek Bailey
e12f5e9bb4 Mark /, %, and * operators as constexpr when intrinsics are available.
PiperOrigin-RevId: 799584292
Change-Id: Icf941f6d20ec62142408a316d85f6ad2182dfa33
2025-08-26 08:57:06 -07:00
Abseil Team
878361312d Automated Code Change
PiperOrigin-RevId: 783054860
Change-Id: I3f84881642f2f77be5d5275983243edf6305178c
2025-07-14 15:00:34 -07:00
Derek Mauro
f8288c18a1 rotr/rotl: Fix undefined behavior when passing INT_MIN
as the number of positions to rotate by

Previously the code was negating INT_MIN, which is undefined

PiperOrigin-RevId: 770318129
Change-Id: Iff94b0e3d5777b2f488f2d48b6f8220f47bdada3
2025-06-11 14:22:33 -07:00
Jesse Rosenstock
fc0b7a083b [bits] Add tests for return types
With gcc <= 12, std::bit_width<T>() returns T, not int, so make sure the
absl:: equivalents return the correct type.

https://github.com/abseil/abseil-cpp/issues/1890

PiperOrigin-RevId: 760612745
Change-Id: Ibbbe6eaa1aab677ecd747cf40765f6443eefe628
2025-05-19 07:13:25 -07:00
Laramie Leavitt
3870e283fb Use absl::InsecureBitGen in place of std::random_device in Abseil tests.
PiperOrigin-RevId: 750721356
Change-Id: I84e8a1c2a80335983e557270ef78b8b0b4f1e452
2025-04-23 14:16:54 -07:00
Derek Mauro
67cab0c465 Cleanups related to benchmarks
* Fix many benchmarks to be cc_binary instead of cc_test
  * Add a few benchmarks for StrFormat
  * Add benchmarks for Substitute
  * Add benchmarks for Damerau-Levenshtein distance used in flags

PiperOrigin-RevId: 738448552
Change-Id: I521f4b2ef9116c9895b44c32d27e94507380bee8
2025-03-19 10:21:06 -07:00
Derek Mauro
25bce1236b bits.h: Add absl::endian and absl::byteswap polyfills
I had to remove the MSVC implementation since it is
not constexpr.
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/byteswap-uint64-byteswap-ulong-byteswap-ushort?view=msvc-170

But all major compilers understand the portable implementation
is just a bswap: https://godbolt.org/z/oMnW3xsns

Closes #1198

PiperOrigin-RevId: 734626285
Change-Id: Ibca79f408f225c894f3c2b95f7086f891627db9f
2025-03-07 11:19:37 -08:00
Derek Mauro
e59348319d int128_test: Avoid testing signed integer overflow
Signed integer overflow is undefined behavior.

Our UBSAN tests were missing `-fno-sanitize-recover`, which
means UBSAN logs a warning, but the program continues,
causing the test not to fail.

`-fno-sanitize-recover` will be added once all errors are fixed.

PiperOrigin-RevId: 733753582
Change-Id: Icd3441e5ade957461965dfe6b2f8909d585a6a76
2025-03-05 08:57:35 -08:00
Derek Mauro
1af129f1c3 Use C++17 [[nodiscard]] instead of the deprecated ABSL_MUST_USE_RESULT
In this change, //absl/status is intentionally excluded because of
complication with SWIG compatibility. This may be handled separately.

PiperOrigin-RevId: 731387819
Change-Id: I71bf2e02f3a477d65575d467f5e5ab163846d31e
2025-02-26 11:16:38 -08:00
Derek Mauro
ea9951d3a9 MSVC: Fix warnings c4244 and c4267 in the main library code
These are integer-type shortening warnings.
These warnings are still disabled in tests.

c4244: conversion from 'type1' to 'type2', possible loss of data
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-levels-3-and-4-c4244?view=msvc-170
c4267: conversion from 'size_t' to 'type', possible loss of data
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4267?view=msvc-170

Fixes https://github.com/abseil/abseil-cpp/issues/1844

PiperOrigin-RevId: 730882892
Change-Id: Id6506d71846caf1a6a5be3375c34266299c221e1
2025-02-25 07:44:44 -08:00
Derek Mauro
feb3d276d4 Remove ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
which is longer needed with the C++17 floor

PiperOrigin-RevId: 729365281
Change-Id: Ife5e778ead193bb37150b9799099e92f53252cb4
2025-02-20 21:07:28 -08:00
Derek Mauro
90a7ba66e8 Updates to CI to support newer versions of tools
Linux "latest" containers updated to
GCC 14.2
CMake 3.31.2
Bazel 8.0.0

Included are various fixes to get these versions to work.

Bazel now references repositories by their canonical names from the
Bazel Central Registry. For example, Abseil is now @abseil-cpp instead
of @com_google_absl, and GoogleTest is now @googletest instead of
@com_google_googletest. Users still using the old WORKSPACE system may
need to use `repo_mapping` on repositories using the old names. See
`WORKSPACE.bazel` in this commit for an example.

PiperOrigin-RevId: 709102146
Change-Id: I02327ed4f8fb947766480bdeef2b1930a7f831eb
2024-12-23 10:58:05 -08:00
Markus Wick
94e64f0c5c PR #1777: Avoid std::ldexp in operator double(int128).
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1777

This patch replaces all instances of

  std::ldexp(msb, 64)

with

  msb * (2**64)

as it turns out that this optimization is not done by MSVC. Worse, it emited a function call with error checking, even if the int128 cannot hit the inf limitation.

Sadly even the constant `std::ldexp(1.0, 64)` is not inlined: https://gcc.godbolt.org/z/oGhGz77sx
Merge a21b1c9524 into 878313658e

Merging this change closes #1777

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1777 from degasus:int128_t a21b1c9524
PiperOrigin-RevId: 688968524
Change-Id: Id88cf38e241553f88bf4d97e7b001247dcd5599b
2024-10-23 08:09:57 -07:00
Samuel Benzaquen
b92128a4bd Fix bug where the high bits of __int128_t/__uint128_t might go unused in the hash function.
This fix increases the hash quality of these types.

Also, make sure that absl::(u)int128 have the same hash expansion as their intrinsic counterparts.

PiperOrigin-RevId: 685706878
Change-Id: Ib8e2e2b7a8ce24cf08f1e8d18094188a6eedbb3a
2024-10-14 07:58:17 -07:00
Abseil Team
40cab24455 Add a test to verify bit casting between signed and unsigned int128 works as expected
PiperOrigin-RevId: 684941948
Change-Id: I78a7ae6f4ec8f29e5bed414016eadf2ec95167a4
2024-10-11 13:40:46 -07:00
Derek Mauro
c1e1b47d98 Use __builtin_ctzg and __builtin_clzg in the implementations of
CountTrailingZeroesNonzero16 and CountLeadingZeroes16 when they are
available.

GCC 14 and Clang 19 adds these new builtins. The g-suffix is for
"generic". The s-suffix on __builtin_ctzs and __builtin_clzs is for
"short". GCC never implemented the short versions and #1664 reports
GCC 14 (pre-release) gives an error here, although this may be a
pre-release bug.

Fixes #1664

PiperOrigin-RevId: 630408249
Change-Id: I4aedcc82b85430f50d025f8eb1cab089c6fcd1bc
2024-05-03 09:15:27 -07:00
Pavel P
0908376f89 PR #1652: Avoid C++23 deprecation warnings from float_denorm_style
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1652

this change fixes errors emitted by MS compiler:
```
1>C:\abseil-cpp\absl\numeric\int128.h(278,20): error C4996: 'std::float_denorm_style': warning STL4042: std::float_denorm_style, std::numeric_limits::has_denorm, and std::numeric_limits::has_denorm_loss are deprecated in C++23. You can define _SILENCE_CXX23_DENORM_DEPRECATION_WARNING or _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS to suppress this warning.
```

Merge 7be9635001 into 7efc308b31

Merging this change closes #1652

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1652 from pps83:float_denorm_style-warn 7be9635001
PiperOrigin-RevId: 626124710
Change-Id: I5fc2b5758dcb3956164dbec1e8559f241a0d7bf7
2024-04-18 13:02:03 -07:00
Benjamin Barenblat
192e959b16 Add operator<=> support to absl::int128 and absl::uint128
PiperOrigin-RevId: 626080616
Change-Id: If434be2371c1e28f9fd0133f411596bdc38bd222
2024-04-18 10:37:56 -07:00
Derek Mauro
34604d5b1f Remove deprecated symbol absl::kuint128max
absl::kuint128max should be replaced with absl::Uint128Max()
PiperOrigin-RevId: 606279299
Change-Id: Ib67b5431f14891f56bb706e62f183d0de75d335f
2024-02-12 09:45:21 -08:00
Shahriar Rouf
780bfc194d Replace testonly = 1 with testonly = True in abseil BUILD files.
https://bazel.build/build/style-guide#other-conventions

PiperOrigin-RevId: 603084345
Change-Id: Ibd7c9573d820f88059d12c46ff82d7d322d002ae
2024-01-31 10:08:35 -08:00
Abseil Team
04d8afe7a3 Remove code pieces for no longer supported MSVC versions.
The current support policy is `_MSC_VER >= 1920`.

PiperOrigin-RevId: 599833619
Change-Id: I9cf7393a5b659d1680765e37e0328539ccb870fa
2024-01-19 07:53:58 -08:00
Derek Mauro
0ef3ef4329 Bazel: Enable the header_modules feature
PiperOrigin-RevId: 572575394
Change-Id: Ic1c5ac2423b1634e50c43bad6daa14e82a8f3e2c
2023-10-11 07:58:06 -07:00
Derek Mauro
143e983739 Bazel: Support layering_check and parse_headers
The layering_check feature ensures that rules that include a header
explicitly depend on a rule that exports that header. Compiler support
is required, and currently only Clang 16+ supports diagnoses
layering_check failures.

The parse_headers feature ensures headers are self-contained by
compiling them with -fsyntax-only on supported compilers.

PiperOrigin-RevId: 572350144
Change-Id: I37297f761566d686d9dd58d318979d688b7e36d1
2023-10-10 13:30:24 -07:00
Abseil Team
6c6b2733f8 Removed Google-only #ifdefs.
PiperOrigin-RevId: 565040001
Change-Id: I1c2e715c97375754c8d863132be2c388265ca4ad
2023-09-13 07:09:00 -07:00
Derek Mauro
9a6d9c6eae Use Abseil's implementation of absl::rotl and absl::rotr for libc++
prior to 18.0 to workaround libc++ having the wrong signature for
these functions.

Upstream issue: https://github.com/llvm/llvm-project/issues/64544

The preprocessor conditions were inverted for readability as the
conditions became more complex.

PiperOrigin-RevId: 557559472
Change-Id: Ibf7a2651e13a0d2a91846bc0d72ba3a44f56747b
2023-08-16 12:01:08 -07:00
Eric Fiselier
bba65bd115 Refactor bit tests to allow for the testing of more types
PiperOrigin-RevId: 544107572
Change-Id: I8016ee690ad5df78bf80ba0786e528fba4e51907
2023-06-28 11:10:23 -07:00
Derek Mauro
e6c09ae4b2 Fix the check for #include <bit>
Previously this was guarded with macros that are defined by <bit> itself.

Note that libc++ also had a bug that was fixed last week
a4f0764aef

PiperOrigin-RevId: 543511181
Change-Id: I1b8efa32f721ad450f8d1803c6c6c8373ad0371c
2023-06-26 12:31:42 -07:00
Tsige Solomon
34eb767645 Support for int128 to string type conversion.
PiperOrigin-RevId: 542269673
Change-Id: Ib6f7e9a57f83d73dd6fb9c45fc9f85ff0fdd75fe
2023-06-21 08:53:52 -07:00
Derek Mauro
bb6f5ff1c0 Remove redundant redeclarations causing -Wredundant-decls warnings
Fixes #1469

PiperOrigin-RevId: 538534014
Change-Id: Iab84f73c0a0665355b614e85c62f686dc54c8671
2023-06-07 10:51:09 -07:00
Patrick Xia
65109ecdf0 trivial: format some files using clang-format
PiperOrigin-RevId: 527598377
Change-Id: I0ae1505db595b7f3a420f2f608c6e02f8800f138
2023-04-27 09:24:32 -07:00
Derek Mauro
d79361faf6 Changes necessary to support clang-cl
This change fixes -Wimplicit-const-int-float-conversion warnings
by making the conversions explicit.

PiperOrigin-RevId: 520707623
Change-Id: Ib6917469120cd7458257195cbf39beb3fd397543
2023-03-30 12:10:15 -07:00
Abseil Team
0390de901b absl int128: avoid shifting signed integer by a number of bits greater than or equal to the precision of the operand
PiperOrigin-RevId: 519808237
Change-Id: I9123b167b606d609b8f3924d6f4fd298fa866a90
2023-03-27 13:10:39 -07:00
Copybara-Service
a53d0916ec Merge pull request #1409 from georgthegreat:explicit-inserts
PiperOrigin-RevId: 513430584
Change-Id: I944a4868565564f32133dbff8b7a952221bb8b88
2023-03-01 21:29:47 -08:00
Yuriy Chernyshov
f8d47820dc Fix compiling int128.cc against certain STLs 2023-02-27 00:39:06 +03:00
Copybara-Service
ae2f0378dc Merge pull request #1387 from AtariDreams:patch-1
PiperOrigin-RevId: 509581648
Change-Id: Ia60053f1172e0e64569e9555524812fc4788e24f
2023-02-14 11:04:36 -08:00
Rose
b7a8491fbd Remove Workarounds for Old Clang Bug
https://bugs.llvm.org/show_bug.cgi?id=38289 has been addressed since 2019.

We just have to check to see if the clang being used to compile with is any version before major version 9.
2023-02-14 10:51:42 -05:00
Derek Mauro
8caa47cfcd bits_benchmark: Fix typo to benchmark the intended function
PiperOrigin-RevId: 496788919
Change-Id: I8867f8b884b81aa2f7b6d08dabd90c75965d1939
2022-12-20 17:23:00 -08:00
Derek Mauro
553491a54c Only build the section of flag_benchmark used for viewing the
disassembly under LLVM. Due to the issue described in
https://github.com/abseil/abseil-cpp/issues/1340 and
8545dfb3ea
it no longer builds under GCC.

The other changes are necessary to fix the build using the latest benchmark snapshot

Fixes #1340

PiperOrigin-RevId: 494809290
Change-Id: I4a03b2e2dcbdc273e59f1f09f204322e388e7cea
2022-12-12 13:16:33 -08:00
Marcin Kowalczyk
a23d720c30 Cosmetic reformatting in a test.
PiperOrigin-RevId: 492219541
Change-Id: Iee5d7941e413c8b960365e60fa0254536dd20e49
2022-12-01 09:38:15 -08:00
Abseil Team
f073fe8ee5 Fix "unsafe narrowing" warnings in absl, 12/12.
Addresses failures with the following, in some files:
-Wshorten-64-to-32
-Wimplicit-int-conversion
-Wsign-compare
-Wsign-conversion
-Wtautological-unsigned-zero-compare

(This specific CL enables these warnings and fixes the remaining known issues.)

Bug: chromium:1292951
PiperOrigin-RevId: 480981210
Change-Id: I92d5023c6833e24d6aa29b10d433116329972f41
2022-10-13 14:13:57 -07:00
Abseil Team
188138facb Change bit_width(T) to return int rather than T.
This matches std::bit_width().

Bug: chromium:1292951
PiperOrigin-RevId: 468495319
Change-Id: I0e428addb6a7353abbf2063c5c2f5820c3bae789
2022-08-18 10:45:18 -07:00
Thomas Köppe
4b551344e6 Revert change "Fix "unsafe narrowing" warnings in absl, 4/n.".
The change breaks existing code by changing the return type of absl::bit_width.

PiperOrigin-RevId: 465295951
Change-Id: Id4ce7c2ac3699ce22aa2b4851a949f9e0104a3d7
2022-08-04 06:15:05 -07:00
Abseil Team
751ade00ee Fix "unsafe narrowing" warnings in absl, 3/n.
Addresses failures with the following, in some files:
-Wshorten-64-to-32
-Wimplicit-int-conversion
-Wsign-compare
-Wsign-conversion
-Wtautological-unsigned-zero-compare

(This specific CL focuses on .cc files in dirs n-t, except string.)

Bug: chromium:1292951
PiperOrigin-RevId: 465287204
Change-Id: I0fe98ff78bf3c08d86992019eb626755f8b6803e
2022-08-04 05:20:40 -07:00
Abseil Team
07360899e6 Fix "unsafe narrowing" warnings in absl, 4/n.
Addresses failures with the following, in some files:
-Wshorten-64-to-32
-Wimplicit-int-conversion
-Wsign-compare
-Wsign-conversion
-Wtautological-unsigned-zero-compare

(This specific CL focuses on .cc files in strings/, except /internal/.)

Bug: chromium:1292951
PiperOrigin-RevId: 465285043
Change-Id: I37e9d1b4c4e9aa655b720da1467927af2aba995e
2022-08-04 05:05:57 -07:00
Derek Mauro
9eff97861b Fix C++17 constexpr storage deprecation warnings
This change introduces the symbol
ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
to guard redundant declarations of static constexpr data
members that are needed prior to C++17.

This change also introduces the symbol
ABSL_INTERNAL_CPLUSPLUS_LANG, which is supposed to be set
to the same value as __cplusplus, except it uses _MSVC_LANG
on MSVC so that the value is correct on MSVC.

Neither of these new symbols should be used outside of Abseil.

Fixes #1191

PiperOrigin-RevId: 453923908
Change-Id: I1316c52c19fa0c168b93cced0c817e4cb7c9c862
2022-06-09 07:50:21 -07:00
Ben Niu
4c015dbb49 Exclude unsupported x64 intrinsics from ARM64EC (#1135)
ARM64EC is a Microsoft-designed ARM64 ABI compatible with AMD64
applications on ARM64 Windows 11. The ARM64EC does not support
_umul128 and __rdtsc as x64 intrinsics, though it provides inline
function implementations for them, by emulation. Since the code
already has portable code paths without using the intrinsics,
instead of using the emulated intrinsic implementations, we use
the said portable code paths for ARM64EC.
2022-03-18 16:10:10 -04:00
Abseil Team
5e4ea1ce09 Export of internal Abseil changes
--
7473df9e4922c589f6b27cf546aad097381ae552 by Martijn Vels <mvels@google.com>:

Make ABSL_ASSUME publicly available

PiperOrigin-RevId: 430540224
Change-Id: I760e2d86e3a0b676cd2a6d26e0225a77381e948f

--
c83e38bc421f715b3c1e20150c2f1ffe8e633028 by Abseil Team <absl-team@google.com>:

Alias absl::bind_front to std::bind_front if available

This avoids ambiguity between the two when enabling C++20.

PiperOrigin-RevId: 430486679
GitOrigin-RevId: 7473df9e4922c589f6b27cf546aad097381ae552
Change-Id: I1e9bba09a8946480ce10ddd28e86b6c86191d38c
2022-02-24 12:28:55 -05:00
Abseil Team
c59e7e59f5 Export of internal Abseil changes
--
0db7f4046f9b59c0f8c3df2f0eb7fd88fc328439 by Abseil Team <absl-team@google.com>:

Revise documentation of bit_cast:

* Removes inappropriate examples (round-tripping pointers, serialization), for which reinterpret_cast is more appropriate.
* Removes mention of "bit representation", which is not an explicit notion in C++. The best we get is "byte representation".
* Removes a circular defition of "bitcast" as itself, and instead explains what it does.
* Removes the mathism "for some values of", which is probably not totally accessible to a general audience, and in any case needless verbiage.
* Fixes comments in the example.
* Replaces some colloquialisms with simpler, more direct language.

PiperOrigin-RevId: 421791786

--
e04e64df55d93c1b9a09c0483b97cc4d8763260d by Derek Mauro <dmauro@google.com>:

Update Docker image to use GCC 11.2, Clang 14 (prerelease),
CMake 3.22.1, and Bazel 4.2.2

PiperOrigin-RevId: 421658559

--
d002bb3dc5cd1fc5b4cbd79a450efc894caa567c by Chris Kennelly <ckennelly@google.com>:

Add a small microbenchmark for absl::bit_width.

PiperOrigin-RevId: 421604852

--
131b057d1b76ecd7170421b48d661bb958ff676b by Evan Brown <ezb@google.com>:

Adds a disabled test for EBO in nested `CompressedTuple`s.

PiperOrigin-RevId: 421413134

--
e34c7876d3a1212d90c73c030ccae6169b682d43 by Jorg Brown <jorg@google.com>:

Show users a better error message if they pass a pointer to absl::Uniform.

PiperOrigin-RevId: 421090472
GitOrigin-RevId: 0db7f4046f9b59c0f8c3df2f0eb7fd88fc328439
Change-Id: I5a004e8d17e974fa4897a09d1466ae8fc65dfdbb
2022-01-14 10:07:25 -05:00