[cfe-dev] Likely problem in canonical declaration

Douglas Gregor dgregor at apple.com
Mon Jan 18 10:32:21 PST 2010


On Jan 14, 2010, at 9:44 AM, Abramo Bagnara wrote:

>
> 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



More information about the cfe-dev mailing list