[libcxx-commits] [libcxx] [libc++] Suppress unsigned-integer-overflow warning in <charconv> (PR #225801)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Sep 28 02:46:33 PDT 2026
https://github.com/hchataing updated https://github.com/llvm/llvm-project/pull/225801
>From a88d93ffe9a397863b720247e5c83a539f657cba Mon Sep 17 00:00:00 2001
From: Henri Chataing <henrichataing at google.com>
Date: Wed, 23 Sep 2026 14:51:23 +0000
Subject: [PATCH 1/2] [libc++] Suppress unsigned-integer-overflow warning in
<charconv>
Invoking __complement with 0 as parameter triggers this runtime error:
> include/c++/v1/__charconv/traits.h:181:19: runtime error: unsigned integer overflow: 18446744073709551615 + 1 cannot be represented in type 'unsigned long'
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior include/c++/v1/__charconv/traits.h:181:19
---
libcxx/include/__charconv/traits.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/__charconv/traits.h b/libcxx/include/__charconv/traits.h
index b8c840d1ebe326..2f08dac4c2afef 100644
--- a/libcxx/include/__charconv/traits.h
+++ b/libcxx/include/__charconv/traits.h
@@ -155,7 +155,8 @@ struct _LIBCPP_HIDDEN __traits : __traits_base<_Tp> {
} // namespace __itoa
template <typename _Tp>
-inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _Tp __complement(_Tp __x) {
+inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK _Tp __complement(_Tp __x) {
static_assert(is_unsigned<_Tp>::value, "cast to unsigned first");
return _Tp(~__x + 1);
}
>From 7693c8cfe86853d9ddf1ab29bbc519e80d77ec39 Mon Sep 17 00:00:00 2001
From: Henri Chataing <henrichataing at google.com>
Date: Mon, 28 Sep 2026 09:42:45 +0000
Subject: [PATCH 2/2] Enable -fsanitize=unsigned-integer-overflow in UBsan
tests
---
libcxx/utils/libcxx/test/params.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index ef229903ea4b6b..88584f7bc563d1 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -323,8 +323,8 @@ def getSuitableClangTidy(cfg):
[
AddFlag("-g -fno-omit-frame-pointer") if sanitizer else None,
- AddFlag("-fsanitize=undefined -fno-sanitize=float-divide-by-zero -fno-sanitize-recover=all") if sanitizer == "Undefined" else None,
- AddFeature("ubsan") if sanitizer == "Undefined" else None,
+ AddFlag("-fsanitize=undefined -fsanitize=unsigned-integer-overflow -fno-sanitize=float-divide-by-zero -fno-sanitize-recover=all") if sanitizer == "Undefined" else None,
+ AddFeature("ubsan") if sanitizer == "Undefined" else None,
AddFlag("-fsanitize=address") if sanitizer == "Address" else None,
AddFeature("asan") if sanitizer == "Address" else None,
More information about the libcxx-commits
mailing list