[compiler-rt] f61f6ff - [compiler-rt] [builtin] Switch the return type of __atomic_compare_exchange_##n to bool

Kamil Rytarowski via llvm-commits llvm-commits at lists.llvm.org
Wed May 13 05:09:29 PDT 2020


Author: Kamil Rytarowski
Date: 2020-05-13T14:09:02+02:00
New Revision: f61f6ffe1126869b05a6f0b8fdee7b24c02d24f3

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

LOG: [compiler-rt] [builtin] Switch the return type of __atomic_compare_exchange_##n to bool

Summary:
Synchronize the function definition with the LLVM documentation.

https://llvm.org/docs/Atomics.html#libcalls-atomic

GCC also returns bool for the same atomic builtin.

Reviewers: theraven

Reviewed By: theraven

Subscribers: theraven, dberris, jfb, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79845

Added: 
    

Modified: 
    compiler-rt/lib/builtins/atomic.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/atomic.c b/compiler-rt/lib/builtins/atomic.c
index 32b3a0f9ad23..8634a72e77d1 100644
--- a/compiler-rt/lib/builtins/atomic.c
+++ b/compiler-rt/lib/builtins/atomic.c
@@ -23,6 +23,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <stdbool.h>
 #include <stdint.h>
 #include <string.h>
 
@@ -293,8 +294,8 @@ OPTIMISED_CASES
 #undef OPTIMISED_CASE
 
 #define OPTIMISED_CASE(n, lockfree, type)                                      \
-  int __atomic_compare_exchange_##n(type *ptr, type *expected, type desired,   \
-                                    int success, int failure) {                \
+  bool __atomic_compare_exchange_##n(type *ptr, type *expected, type desired,  \
+                                     int success, int failure) {               \
     if (lockfree)                                                              \
       return __c11_atomic_compare_exchange_strong(                             \
           (_Atomic(type) *)ptr, expected, desired, success, failure);          \
@@ -303,11 +304,11 @@ OPTIMISED_CASES
     if (*ptr == *expected) {                                                   \
       *ptr = desired;                                                          \
       unlock(l);                                                               \
-      return 1;                                                                \
+      return true;                                                             \
     }                                                                          \
     *expected = *ptr;                                                          \
     unlock(l);                                                                 \
-    return 0;                                                                  \
+    return false;                                                              \
   }
 OPTIMISED_CASES
 #undef OPTIMISED_CASE


        


More information about the llvm-commits mailing list