rsmith added a comment.

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.



================
Comment at: clang/include/clang/Basic/Builtins.def:756
 BUILTIN(__atomic_signal_fence, "vi", "n")
 BUILTIN(__atomic_always_lock_free, "izvCD*", "n")
+BUILTIN(__atomic_is_lock_free, "bzvCD*", "n")
----------------
This one is also wrong, and should return *bool*.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79504



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to