problem with the new AnnotateAttr

Hi!

Yesterday(?) the Attrs part of Clang was significantly changed and after
the update I adapted my plugin to the changes. Unfortunately it doesn't
work any more. Either I'm using the new infrastructure in a wrong way or
it's buggy.

Attached to this mail are two files

Consumer.cpp => HandleTranslationUnit method to demonstrate the issue
test.cpp => small source for the demonstration

When run this is the output:

$ cidplug ../anon.cpp
Typedef

Var
via getAttr: "blah" [4]
via attr_iterator: "" [0]

Var
via getAttr: "bluh2" [5]
via attr_iterator: "" [0] "" [4294967292]

LLVM ERROR: IO failure on output stream.

I already gave the debugger a try, but have not found anything yet. Can
somebody confirm this weird behavior? Should I file a bug for it?

Regards, Jan.

Consumer.cpp (938 Bytes)

test.cpp (119 Bytes)

Whoa, this is weird!

I'll take a look at it. It definitely looks like something is wrong here.

Sean

Dereferencing the attr on this line should solve it. It seems there's a bug in dyn_cast for multi-level pointers - isa works on them and then cast does not, so you get garbage back.

Also, you may want to look at the new specific_attr_iterator interface, which does the downcasting automatically.

Sean

Sean Hunt meinte am 20.08.2010 20:17:

      dyn_cast<clang::AnnotateAttr>(attr)) {

Dereferencing the attr on this line should solve it.

It does indeed. Thanks a lot! :slight_smile:

It seems there's a bug in dyn_cast for multi-level pointers - isa
works on them and then cast does not, so you get garbage back.

That explains what I saw in the debugger - the address seems to be OK
(i.e. the same Sema put in the list) before the cast. But the whole
casting stuff Clang does is a little over my head for now. I'm quite new
to C++ anyway and even the iterators are something I have to get used to.

Also, you may want to look at the new specific_attr_iterator interface,
which does the downcasting automatically.

Thanks for the hint, but I do need to iterate over all attributes and
just give the annotations a little extra treat.

Regards, Jan.