This becomes an AnnotateAttr on the VarDecl. There's nothing stopping you from adding this to an AST, as long as you obey the syntactic constraints on the operand.
I do not see any kind of AnnotateAttr object in VarDecl or anything it inherits, and I also dont see where AnnotateAttr inherits something for it to be inserted into the AST.
How exactly do you add a AnnotateAttr? What is it added to?
Now that they are added, how is this saved for later use?
The PrintFunctionNames example is ran by
clang -cc1 -load ~/llvm/Release+Asserts/lib/libPrintFunctionNames.so -plugin print-fns input_file.c
But how does this get stored/saved for the Pass phase? How do the new contents of llvm.var.annotation get stored/saved? “-emit-llvm -S” does not seem to help
My plugin now adds AnnotateAttr objects directly to VarDecls, and writes out the AST file. This AST file is compiled to clang, with the -S -emit-llvm options, and there is nothing about these AnnotateAttr in there. I can tell they are being add because they print to the screen before hand, but there are no traces in the IR file.
I was expecting to see my string or atleast a reference to @llvm.var.annotation.
That should work. It's possible that the attributes are not being
serialized or deserialized properly; I would check whether it works
when you don't round-trip through an AST file.
Ah, didn't read the start of the thread. The AST is effectively
immutable once built: If you change it, you might break invariants
that modules further down the road make. That's why -add-plugin
plugins run after codegen.
Ouch, this is painful. So even Annotations/Attributes are not allowed? Both seem particular useful and trivial, along with safe.
I’m asking this mostly because I’m saving the AST I modified myself and then later calling clang on it. So it seems like it doesn’t matter if CodeGen already ran the first time, its the second that counts.
Sorry if I’m still beating a dead horse about this, I’m a bit confused and cant imagine why something like this wouldn’t be much easier and a basic feature. Keep thinking I’m missing something simple.