I am writing a gcc plugin and am trying to detect if a value assigned by a
function call, is a global variable or not.  Unfortunately, all calls to
'is_global_var' with a DECL type are returning false.

My pass executes after alias analysis, and ipa analysis.  The
cfun->gimple_df->ipa_pta is set to true, so I know the pta analysis should have
resolved global information. 


Plugin code:
    if (is_gimple_call(stmt))
    {
        gimple_debug_bb(stmt);
        tree lhs = gimple_call_lhs(stmt);
        if (lhs && is_global_var(SSA_NAME_VAR(lhs)))
          printf("Global detected\n");
    }


Source code (in Go):
    package main

    type T struct {id int}
    var myglobal *T;

    func fn() *T {
        myglobal = new(T); // Should be detected as global
        return myglobal;
    }

    func main() {
        t := fn();
    }


Basic Block dump as my plugin code executes for function 'fn':
    <bb 2>:
    # .MEM_4 = VDEF <.MEM_3(D)>
    main.myglobal.13_1 = __go_new_nopointers (4);
    # .MEM_5 = VDEF <.MEM_4>
    main.myglobal = main.myglobal.13_1;
    # VUSE <.MEM_5>
    D.186_2 = main.myglobal;
    return D.186_2;
    

Any insight would be helpful.
Thanks!

-Matt

Reply via email to