[PATCH] D79504: [Clang] Wrong return type of atomic_is_lock_free

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 6 12:26:03 PDT 2020


jfb added a comment.

In D79504#2023274 <https://reviews.llvm.org/D79504#2023274>, @rsmith wrote:

> Clang's `<stdatomic.h>` uses the builtin as follows:
>
>   #define atomic_is_lock_free(obj) __c11_atomic_is_lock_free(sizeof(*(obj)))
>
>
> ... which, combined with the builtin returning `int`, results in a call having the wrong type. So there's definitely a bug *somewhere*.
>
> I think what happened here is: the return type of the GCC `__atomic_is_lock_free` / `__atomic_always_lock_free` builtins was `int` in GCC 4.6 and earlier, and changed to `_Bool` in GCC 4.7 and later. Clang's implementation followed GCC's behavior at the time, so returned `int`, and no-one noticed that GCC changed its behavior in version 4.7. So we still provide the old GCC behavior.
>
> Then, when `__c11_atomic_is_lock_free` was added, it got an `int` return type as (I think) a copy-paste error. The `__c11` builtins are intended to exactly match the semantics of the C11 atomic functions, so this was always wrong.
>
> I think we should make this change, to all three affected builtin functions.


This sounds sensible to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79504/new/

https://reviews.llvm.org/D79504





More information about the cfe-commits mailing list