[clang] [Clang] Fix constexpr __builtin_(add|sub|mul)_overflow bugs (PR #192568)

via cfe-commits cfe-commits at lists.llvm.org
Thu May 7 12:54:26 PDT 2026


================
@@ -1964,6 +1964,53 @@ namespace I128Mul {
 }
 #endif
 
+namespace OverflowOps {
+  constexpr bool add_bool() {
+    bool r = false;
+    return __builtin_add_overflow(1u, 1u, &r) && r == false;
----------------
widberg wrote:

Personally, I would expect that to compile, as it does right now. At least based on my understanding of the docs https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins. Also, GCC isn't happy because it explicitly forbids bools (https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html), whereas Clang explicitly allows them.

https://github.com/llvm/llvm-project/pull/192568


More information about the cfe-commits mailing list