[cfe-dev] incorrect AST

Mark Brown mbrowncu98 at gmail.com
Mon Sep 26 17:19:53 PDT 2011


The output of llvm-dis is below. For some reason they are different
enough to cause problems. I do not understand what is going on. When I
comment out all code that adds attributes it works fine.

function @qv_assignHook_0x7fff99c1d8c0 exists only in left module
function @qv_callHook_0x7fff99c1d8c0 exists only in left module
function @llvm.var.annotation exists only in right module
in function main:
  in block %entry:
    <   %"Arg: Shadow" = bitcast i32 (i32)** @"Shadow Variable" to i8*
    <   %"Arg: Value" = bitcast i32 (i32)* @f1 to i8*
        %"Arg: Pointer" = bitcast i32 (i32)** %ptr1 to i8*
    >   call void @llvm.var.annotation(i8* %ptr11, i8* getelementptr
inbounds ([24 x i8]* @.str6, i32 0, i32 0), i8* getelementptr inbounds
([45 x i8]* @.str7, i32 0, i32 0), i32 9)
    <   %"Arg: Function" = bitcast i32 ()* @main to i8*
    <   %"Shadow check" = icmp ne i32 (i32)** @"Shadow Variable", %ptr1
    <   store i32 (i32)* @f1, i32 (i32)** @"Shadow Variable"
    <   call void @qv_assignHook_0x7fff99c1d8c0(i8* %"Arg: Shadow",
i8* %"Arg: Value", i8* %"Arg: Pointer", i8* %"Arg: Function")
        store i32 (i32)* @f1, i32 (i32)** %ptr1, align 8
        %tmp = load i32 (i32)** %ptr1, align 8
    <   %"Arg: Shadow1" = bitcast i32 (i32)** @"Shadow Variable" to i8*
    <   %"Arg: Value2" = bitcast i32 (i32)* %tmp to i8*
    <   %"Arg: Pointer3" = bitcast i32 (i32)* %tmp to i8*
    <   %"Arg: Function4" = bitcast i32 ()* @main to i8*
    <   call void @qv_callHook_0x7fff99c1d8c0(i8* %"Arg: Shadow1", i8*
%"Arg: Value2", i8* %"Arg: Pointer3", i8* %"Arg: Function4")

On Mon, Sep 26, 2011 at 1:03 PM, Douglas Gregor <dgregor at apple.com> wrote:
>
> 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