[cfe-commits] Emit annotate attributes for function declarations

Job Noorman jobnoorman at gmail.com
Thu Jun 27 07:44:30 PDT 2013


I finally found some time to work on this patch again. Attached is a new 
version that adds two things.

First, as Dmitri suggested, I added test cases.

Second, I found a problem with my initial patch that leads to crashes in 
situations like the following:

1. __attribute__((annotate("foo"))) void foo();
2. void bar(){foo();}
3. void foo() {}

I'll try to explain what I *think* happens here when my original patch is 
applied (note the *think*, I'm by no means a Clang expert so please be gentle 
when I get this completely wrong :-))

1. A declaration is created for a function "foo" having an unspecified number 
of arguments. This declaration is not emitted but queued for deferred 
emission. My patch *did* create an annotation referring to this declaration, 
though.
2. The call site triggers emission of the declaration of "foo".
3. Now "foo" has zero arguments and the original declaration is replaced by a 
new function. Since the added annotation still refers to the deleted 
declaration, this causes a crash.

So, what my patch does is make sure the annotations are only created right 
before they are emitted and annotations referring to non-existing values are 
ignored.

On Monday 28 January 2013 17:09:41 Job Noorman wrote:
> Hi Dmitri,
> 
> Yes, I will add a testcase if someone can confirm the behavior introduced by
> this patch would be accepted. Just to not waste my time writing a testcase
> for a feature that will never make it into Clang :-)
> 
> Job
> 
> On Monday 28 January 2013 16:59:21 Dmitri Gribenko wrote:
> > On Mon, Jan 28, 2013 at 3:35 PM, Job Noorman <jobnoorman at gmail.com> wrote:
> > > Attached is a patch that makes sure that annotate attributes are also
> > > emitted for function declarations. It simply calls
> > > CodeGenModule::AddGlobalAnnotations in
> > > CodeGenModule::SetFunctionAttributes
> > > instead of in CodeGenModule::EmitGlobalFunctionDefinition.
> > > 
> > > See
> > > http://lists.cs.uiuc.edu/pipermail/cfe-users/2013-January/000046.html
> > > for a yet unanswered question I asked about this.
> > 
> > Hello Job,
> > 
> > I don't know the answer for your question, but the patch should
> > include a testcase.
> > 
> > Dmitri
-------------- next part --------------
A non-text attachment was scrubbed...
Name: annotate-decl.diff
Type: text/x-patch
Size: 4690 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130627/0ebf0b2b/attachment.bin>


More information about the cfe-commits mailing list