Getting started writing a GIMPLE analysis plugin
Florian Weimer
fweimer@redhat.com
Tue Sep 18 12:50:00 GMT 2012
Is there some simple example plugin which contains a simple GIMPLE
analysis pass which doesn't change anything? I have written something
very much like the warn_unused_result pass, iterating over
gimple_body(current_function_decl), and the compiler crashes much later
in the compilation process.
The gcc-python plugin (which is much more complex) seems to work in my
GCC installation, but it's not clear to me what I'm doing differently,
so that my own plugin registration doesn't work.
Here's the backtrace I eventually get when I call gimple_call_fndecl on
a GIMPLE_CALL statement from my pass:
==1089== Invalid read of size 4
==1089== at 0x657F60: dom_info_available_p(cdi_direction)
(dominance.c:1479)
==1089== by 0x985F98: cleanup_tree_cfg() (tree-cfgcleanup.c:674)
==1089== by 0x86543A: execute_function_todo(void*) (passes.c:1756)
==1089== by 0x8659E6: do_per_function(void (*)(void*), void*)
(passes.c:1646)
==1089== by 0x865B92: execute_todo(unsigned int) (passes.c:1834)
==1089== by 0x868C41: execute_one_pass(opt_pass*) (passes.c:2180)
==1089== by 0x868EEE: execute_pass_list(opt_pass*) (passes.c:2212)
==1089== by 0x61AA58: cgraph_analyze_function(cgraph_node*)
(cgraphunit.c:663)
==1089== by 0x61D3F5: cgraph_analyze_functions() (cgraphunit.c:937)
==1089== by 0x61E6DD: finalize_compilation_unit() (cgraphunit.c:2080)
==1089== by 0x4F31C6: c_write_global_declarations() (c-decl.c:10116)
==1089== by 0x9603E2: compile_file() (toplev.c:560)
If I call gimple_call_fndecl on the same statements, I get this instead:
==1699== Invalid read of size 8
==1699== at 0x979391: verify_gimple_in_cfg(function*) (tree-cfg.c:4544)
==1699== by 0x865562: execute_function_todo(void*) (passes.c:1801)
==1699== by 0x8659E6: do_per_function(void (*)(void*), void*)
(passes.c:1646)
==1699== by 0x865B92: execute_todo(unsigned int) (passes.c:1834)
==1699== by 0x868C41: execute_one_pass(opt_pass*) (passes.c:2180)
==1699== by 0x868EEE: execute_pass_list(opt_pass*) (passes.c:2212)
==1699== by 0x61AA58: cgraph_analyze_function(cgraph_node*)
(cgraphunit.c:663)
==1699== by 0x61D3F5: cgraph_analyze_functions() (cgraphunit.c:937)
==1699== by 0x61E6DD: finalize_compilation_unit() (cgraphunit.c:2080)
==1699== by 0x4F31C6: c_write_global_declarations() (c-decl.c:10116)
==1699== by 0x9603E2: compile_file() (toplev.c:560)
==1699== by 0x961F67: toplev_main(int, char**) (toplev.c:1863)
==1699== Address 0x0 is not stack'd, malloc'd or (recently) free'd
This happens with GCC 4.7.0 from Fedora 17, and with GCC 4.8 trunk. I
tried to compile the latter with --enable-checking=all, but I don't get
any illuminating results, either. For GCC 4.7, it doesn't matter if I
compile the plugin in C or C++ mode.
Any idea what might be the cause?
I've attached the plugin source code for reference.
--
Florian Weimer / Red Hat Product Security Team
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plugin.cpp
Type: text/x-c++src
Size: 2514 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20120918/4796c45d/attachment.bin>
More information about the Gcc-help
mailing list