jfb added a comment.

In https://reviews.llvm.org/D47229#1112549, @jakehehrlich wrote:

> This is causing breaks in fuchsia,
>
> Code that looks like this
>
>   uintptr_t last_unlogged =
>        atomic_load_explicit(&unlogged_tail, memory_order_acquire);
>    do { 
>        if (last_unlogged == 0)
>            return;
>    } while (!atomic_compare_exchange_weak_explicit(&unlogged_tail,
>                                                    &last_unlogged, 0,
>                                                    memory_order_acq_rel,
>                                                    memory_order_relaxed));
>   
>
> Where unlogged_tail is somewhere on the stack. And 
> 'atomic_compare_exchange_weak_explicit' is an #define alias for 
> '__c11_atomic_compare_exchange_weak'
>
> Full context here: 
> https://fuchsia.googlesource.com/zircon/+/master/third_party/ulib/musl/ldso/dynlink.c#822


Here's a repro for what seems to be happening:

  #include <stdatomic.h>
  void foo() {
    atomic_int s;
    int a;
    atomic_compare_exchange_weak_explicit(&s, &a, 0, memory_order_acq_rel, 
memory_order_relaxed);
  }

Yields:

  ./foo.c:5:3: warning: null passed to a callee that requires a non-null 
argument [-Wnonnull]
    atomic_compare_exchange_weak_explicit(&s, &a, 0, memory_order_acq_rel, 
memory_order_relaxed);
    ^                                             ~
  /s/llvm1/llvm/debug/lib/clang/7.0.0/include/stdatomic.h:144:47: note: 
expanded from macro 'atomic_compare_exchange_weak_explicit'
  #define atomic_compare_exchange_weak_explicit 
__c11_atomic_compare_exchange_weak
                                                ^

The problem is that my patch checks that the "desired" value is non-null, but 
that's incorrect because it's not a pointer. I'll do a follow-up fix. Thanks 
for catching this!


Repository:
  rL LLVM

https://reviews.llvm.org/D47229



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

Reply via email to