[cfe-dev] incorrect AST

Douglas Gregor dgregor at apple.com
Mon Sep 26 10:03:09 PDT 2011


On Sep 26, 2011, at 8:39 AM, Mark Brown wrote:

> I wrote a small Plugin that inherits the ASTConsumer and
> RecursiveASTVisitor classes and writes out the AST with ASTWriter in
> the ASTCOnsumer::HandleTranslationUnit method. When I compile down to
> Bitcode everything works fine. When I try to add trival Attributs with
> the newish VarDecl::addAttr() method (inherited by Decl) on VarDecls
> and then compile down to Bitcode I get different results. Besides from
> looking different there is no output. How can I fix this?

Adding attributes can change the generated IR, so there may be nothing to "fix" here. I suggest looking at the actual changes to see if they are expected.

> I use the VisitCallExpr(), VisitDecl() and VisitStmt() methods from
> RecursiveASTVisitor to add the attributes. Here is how I write the AST
> out. Does the AST need to be "finalized" or something?


The AST does not need to be "finalized", but if you're modifying the AST directly then you need to be certain that the resulting AST is well-formed. Adding attributes is generally fine.

	- Doug



More information about the cfe-dev mailing list