[cfe-dev] Where do attributes get merged?

Robinson, Paul Paul_Robinson at playstation.sony.com
Wed Dec 10 10:32:53 PST 2014


> -----Original Message-----
> From: aaron.ballman at gmail.com [mailto:aaron.ballman at gmail.com] On Behalf
> Of Aaron Ballman
> Sent: Wednesday, December 10, 2014 5:50 AM
> To: David Majnemer
> Cc: Robinson, Paul; cfe-dev at cs.uiuc.edu Developers (cfe-dev at cs.uiuc.edu)
> Subject: Re: [cfe-dev] Where do attributes get merged?
> 
> Yes, you're looking for Sema::mergeDeclAttributes. You're also correct
> that the current behavior only works when the attributes are on the
> same declaration.

Awesome, thanks guys. Exactly what I needed.
 
> However, from memory, I don't think that situation of yours should
> result in well-formed code. IIRC, the definition must not attempt to
> declare new attributes (aside from some keyword-like ones) that do not
> also appear on the declaration.

Hmm I poked around in online docs for both clang and gcc, I'm not finding
any statement like that.  Looking at the code, the behavior seems to be:
- If we've already seen a definition, a new declaration can't add any
  attributes. Except for a couple of special cases.
- Otherwise, attributes that are on the old declaration, and are inheritable,
  are propagated to the new declaration (again with a few special cases).

The use case for __attribute__((optnone)) is such that having it on the
definition but not the declaration would be the normal case.  I think it
would be reasonable to say that when optnone conflicts with something else,
the attribute on the definition wins.

How does that sound?
--paulr

> 
> ~Aaron
> 
> On Wed, Dec 10, 2014 at 12:13 AM, David Majnemer
> <david.majnemer at gmail.com> wrote:
> > IIRC, attribute merging largely happens in mergeDeclAttribute:
> > http://llvm.org/viewvc/llvm-
> project/cfe/trunk/lib/Sema/SemaDecl.cpp?revision=222906&view=markup#l2124
> >
> > On Tue, Dec 9, 2014 at 6:27 PM, Robinson, Paul
> > <Paul_Robinson at playstation.sony.com> wrote:
> >>
> >> I'm starting to look into Aaron Ballman's request to diagnose the cases
> >> where the OptimizeNone attribute "wins" over things like MinSize.  This
> >> is leading me through a maze of twisty little passages all different.
> >>
> >> One case that came up in my experiments is when you have (say)
> >> always_inline
> >> on a function declaration, and optnone on the function's definition.
> The
> >> existing detection logic seems to work only when the conflicting
> >> attributes
> >> are on the same declaration. Seems like there would have to be some
> place
> >> where attributes from the two declarations would be mashed together,
> but
> >> I'm
> >> not finding it; could somebody please point me in the right direction?
> >> Thanks,
> >> --paulr
> >>
> >>
> >> _______________________________________________
> >> cfe-dev mailing list
> >> cfe-dev at cs.uiuc.edu
> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> >
> >
> >
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> >




More information about the cfe-dev mailing list