This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Treatment of builtin that receives function pointer


I have declared a builtin that receives a function pointer in gcc 4.3.4.

While handling the builtin I want to find the assembler name of the
function the pointer points to.
My current code works if the the function is a void (*)(void), but it
doesn't work for anything else and unfortunately, casting it won't

The interesting part is that if when I handle the builtin, I call
debug_tree on the call_expr to the builtin.
With something like:
void foo(void) {...}

I get the following for call_expr:
arg 0 <addr_expr 0xb7c6c3c0
        type <pointer_type 0xb7c5ebc8 type <function_type 0xb7c16618>
            unsigned HI size <integer_cst 0xb7bff4d0 32> unit size
<integer_cst 0xb7bff4ec 2>
            align 16 symtab 0 alias set -1 canonical type 0xb7c5ebc8>
        constant invariant
        arg 0 <function_decl 0xb7c68af0 foo type <function_type 0xb7c16618>
            addressable asm_written used public static decl_5 QI file
functionsize.c line 4 col 1 align 16 initial <error_mark 0xb7bff24c>
result <result_decl 0xb7c740a0 D.1176>
            (mem:QI (symbol_ref:HI ("foo") <function_decl 0xb7c68af0
foo>) [0 S1 A16])>>

This works because I access arg0 and from the function_decl I get the
function name.

Now, if foo becomes:
void foo(int * x) { ... }

I get instead:
    arg 0 <var_decl 0xb7c122c0 foo?0?
        type <pointer_type 0xb7c69bc8 type <function_type 0xb7c21618>
            unsigned HI size <integer_cst 0xb7c0a4d0 32> unit size
<integer_cst 0xb7c0a4ec 2>
            align 16 symtab 0 alias set -1 canonical type 0xb7c69bc8>
        used unsigned ignored HI file functionsize.c line 18 col 5
size <integer_cst 0xb7c0a4d0 32> unit size <integer_cst 0xb7c0a4ec 2>
        align 16 context <function_decl 0xb7c73c40 main>
        (reg/f:HI 21 [ foo?0? ])
        chain <var_decl 0xb7c12318 D.1186 type <integer_type
0xb7c17340 unsigned int>
            used unsigned ignored QI file functionsize.c line 18 col 5
size <integer_cst 0xb7c0a310 16> unit size <integer_cst 0xb7c0a32c 1>
            align 16 context <function_decl 0xb7c73c40 main>
            (reg:QI 20 [ D.1186 ]) chain <var_decl 0xb7c12370 D.1187>>>

which doesn't contain any informtation regarding the name of foo...

Interestingly it contains an align 16 context function_decl main,
which is from where I am calling the builtin but I don't think this is
Now, I wonder in this more general case, where can I obtain the
function decl (so I can get its assembler name) for the function the
pointer is pointing to?


Paulo Jorge Matos - pocmatos at

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]