[llvm] 0c324f1 - [Support] Fix the return type of AddOverflow, SubOverflow, and MulOverflow (#223217)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 07:12:09 PDT 2026


Author: Kazu Hirata
Date: 2026-09-13T07:12:04-07:00
New Revision: 0c324f10322b490d66de738d73458f6f65460cdb

URL: https://github.com/llvm/llvm-project/commit/0c324f10322b490d66de738d73458f6f65460cdb
DIFF: https://github.com/llvm/llvm-project/commit/0c324f10322b490d66de738d73458f6f65460cdb.diff

LOG: [Support] Fix the return type of AddOverflow, SubOverflow, and MulOverflow (#223217)

This patch fixes the return type of the 3-argument overloads of
AddOverflow, SubOverflow, and MulOverflow to bool.

Without this patch, these functions are declared with a return type
of T:

  template <typename T>
std::enable_if_t<std::is_signed_v<T>, T> AddOverflow(T X, T Y, T
&Result);

even though they return a boolean indicating whether an overflow
occurred, as stated in the comment:

/// Add two signed integers, computing the two's complement truncated
result,
  /// returning true if overflow occurred.

Assisted-by: Antigravity

Added: 
    

Modified: 
    llvm/include/llvm/Support/MathExtras.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index 2324565852815..e41e64fad0db6 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -717,7 +717,7 @@ AddOverflow(T X, T Y) {
 /// Add two signed integers, computing the two's complement truncated result,
 /// returning true if overflow occurred.
 template <typename T>
-std::enable_if_t<std::is_signed_v<T>, T> AddOverflow(T X, T Y, T &Result) {
+std::enable_if_t<std::is_signed_v<T>, bool> AddOverflow(T X, T Y, T &Result) {
 #if __has_builtin(__builtin_add_overflow)
   return __builtin_add_overflow(X, Y, &Result);
 #else
@@ -754,7 +754,7 @@ SubOverflow(T X, T Y) {
 /// Subtract two signed integers, computing the two's complement truncated
 /// result, returning true if an overflow occurred.
 template <typename T>
-std::enable_if_t<std::is_signed_v<T>, T> SubOverflow(T X, T Y, T &Result) {
+std::enable_if_t<std::is_signed_v<T>, bool> SubOverflow(T X, T Y, T &Result) {
 #if __has_builtin(__builtin_sub_overflow)
   return __builtin_sub_overflow(X, Y, &Result);
 #else
@@ -798,7 +798,7 @@ MulOverflow(T X, T Y) {
 /// Multiply two signed integers, computing the two's complement truncated
 /// result, returning true if an overflow occurred.
 template <typename T>
-std::enable_if_t<std::is_signed_v<T>, T> MulOverflow(T X, T Y, T &Result) {
+std::enable_if_t<std::is_signed_v<T>, bool> MulOverflow(T X, T Y, T &Result) {
 #if __has_builtin(__builtin_mul_overflow)
   return __builtin_mul_overflow(X, Y, &Result);
 #else


        


More information about the llvm-commits mailing list