Skip to content

Builder incorrectly inserts global values into IR #19

Open
@MasonProtter

Description

@MasonProtter

Ran into this today:

julia> using CodeInfoTools

julia> x = 1 #global variable
1

julia> f(y) = x + y;

julia> code_info(f, Int)
CodeInfo(
1%1 = Main.x + y
└──      return %1
)

julia> for (v, st)  Builder(ans)
           @show st
       end
st = :((+)(1, _2))
st = :(return %1)

Here, we can see that the global variable x's value got embedded directly into the IR from the Builder, rather than a reference to it. This can cause subtle and hard to track down errors in code generated with Builder.

IMO x and + should both be GlobalRefs here.

julia> let b = Builder(code_info(f, Int))
           for (v, st)  b
               b[v] = b[v]
           end
           finish(b)
       end
CodeInfo(
    @ REPL[8]:1 within `f`
1%1 = (+)(1, y)
└──      return %1
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions