Likely problem in canonical declaration

Compiling this snippet:

void foo() {
  int i;
  __sync_fetch_and_add(&i, 1);
  __sync_fetch_and_add(&i, 1);

I get for builtin call to __sync_fetch_and_add_4 two different Decl* and
although I found this a bit strange I've thought this is not a big problem.

What I think dangerous is that these two Decl* does not have neither the
same value for getCanonicalDecl(), so I guess they're considered two
distinct functions.

Do you confirm that this behaviour is symptom of a bug?

Yes, this is the symptom of a bug. It's okay (but certainly not ideal!) to have two different Decl*'s for this builtin, but when there are multiple Decl*'s for the same thing, they must share the same canonical type. It looks like Sema::SemaBuiltinAtomicOverloaded needs to be taught to look for previous, compatible declarations of a given atomic builtin before building a new declaration.

  - Doug

I've filed this here:

so we don't forget about it.

  - Doug