Look at this simple plugins code ( All sources are at the end of this mail ) bug.cpp compile with g++ -shared -I/usr/local/lib/gcc/i686-pc-linux-gnu/4.5.0/plugin/include -DUNIX -g -Wall -Werror -O0 -fPIC -DPIC -o libbug.so bug.cpp than ran this plugins on example.cpp with g++ -S -fplugin=libbug.so example.cpp the output starting libbug processing example.cpp unused_f2 0 <------- decl saved tree is null unused_f 0xb7409ad4 main 0xb7496c90 function_1 0xb7496c78 now add a function at the end of the file like example2.cpp and run the plugins on it starting libbug processing example2.cpp unused_f3 0 <----------- DECL_SAVED_TREE null unused_f2 0xb754be28 <----------- DECL_SAVED_TREE != null unused_f 0xb74bead4 main 0xb754bc90 function_1 0xb754bc78 It seem that the last (on file) / first (on list) function_decl has always DECL_SAVED_TREE == null Source codes /* bug.cpp */ // GCC header includes to get the parse tree // declarations. The order is important and // doesn't follow any kind of logic. // #include "config.h" /* Needed to undef because gcc-plugins redefine them */ #undef PACKAGE_BUGREPORT #undef PACKAGE_NAME #undef PACKAGE_STRING #undef PACKAGE_TARNAME #undef PACKAGE_VERSION #include <stdlib.h> #include <gmp.h> #include <set> #include <cstdlib> // Include before GCC poisons // some declarations. extern "C" { #include "gcc-plugin.h" #include "plugin-version.h" #include "system.h" #include "coretypes.h" #include "tree.h" #include "intl.h" #include "tm.h" #include "diagnostic.h" #include "c-common.h" #include "c-pragma.h" #include "cp/cp-tree.h" } #include <iostream> #include "tree-iterator.h" int plugin_is_GPL_compatible; void collect (tree ns) { tree decl; cp_binding_level* level (NAMESPACE_LEVEL (ns)); // Collect declarations. // for (decl = level->names; decl != 0; decl = TREE_CHAIN (decl)) { if (DECL_IS_BUILTIN (decl)) continue; if (TREE_CODE(decl) == FUNCTION_DECL) std::cerr << IDENTIFIER_POINTER(DECL_NAME(decl)) << " " << DECL_SAVED_TREE(decl) << "\n"; } } extern "C" void gate_callback (void*, void*) { // If there were errors during compilation, // let GCC handle the exit. // if (errorcount || sorrycount) return; int r (0); // // Process AST. Issue diagnostics and set r // to 1 in case of an error. // std::cerr << "processing " << main_input_filename << "\n"; collect (global_namespace); exit (r); } extern "C" int plugin_init (plugin_name_args* info, plugin_gcc_version* ver) { if (!plugin_default_version_check (ver, &gcc_version)) return 1; int r (0); std::cerr << "starting " << info->base_name << "\n"; // // Parse options if any. // // Disable assembly output. // asm_file_name = HOST_BIT_BUCKET; // Register callbacks. // register_callback (info->base_name, PLUGIN_OVERRIDE_GATE, &gate_callback, 0); return r; } /* example.cpp */ int test; double var; int function_1(int param1, int param2) { param1 = param1 * param2; param2 = param1 + param2; return param1 + param2; } int main(int argc, char **argv) { int var = 0; double test = 0; test = 5 * var + 7; return 0; } int unused_f(int p1, int p2) { return p1 + p2; } int unused_f2(int p1) { p1 = p1 * p1; return p1; } /* example2.cpp */ int test; double var; int function_1(int param1, int param2) { param1 = param1 * param2; param2 = param1 + param2; return param1 + param2; } int main(int argc, char **argv) { int var = 0; double test = 0; test = 5 * var + 7; return 0; } int unused_f(int p1, int p2) { return p1 + p2; } int unused_f2(int p1) { p1 = p1 * p1; return p1; } int unused_f3(int p1) { p1 = p1 / 2; return p1; } _________________________________________________________________ Il tuo mondo MSN a portata di clic. Scarica IE8 per MSN http://events.it.msn.com/internet-explorer-8