I am trying to write a new GCC pass in gcc-4.1.2. This is my first attempt and I am trying to print lines of code for a function gcc is compiling. So I added the below code. Note if I remove code in execute_gimple_manipulation method the issue does not occur :
gcc/gcc-4.1.2 1223> cat gcc/gimple-manipulation.c #include "config.h" #include "system.h" #include "coretypes.h" #include "tm.h" #include "ggc.h" #include "flags.h" #include "tree.h" #include "basic-block.h" #include "tree-flow.h" #include "tree-pass.h" #include "tree-dump.h" #include "timevar.h" #include "diagnostic.h" #include "cfgloop.h" #include "tree-scalar-evolution.h" #include "tree-ssa-propagate.h" #include "tree-chrec.h" static void execute_gimple_manipulation (void); static bool gate_gimple_manipulation (void); /*------------------------- The main driver function. -------------------------*/ static void execute_gimple_manipulation (void) { basic_block bb = ENTRY_BLOCK_PTR; int bbcounter=0, stmtcounter; tree stmt; block_stmt_iterator si; /* traverse each basic block and print all statements */ FOR_EACH_BB (bb){ /* in any order */ bbcounter++; printf("\n-> entering bb # %d (internal #: %d)\n", bbcounter, bb->index); stmtcounter=0; for(si = bsi_start(bb); !bsi_end_p(si); bsi_next(&si)){ stmtcounter++; printf(" encountering statement #%2d: ", stmtcounter); stmt = bsi_stmt(si); print_generic_stmt (stderr, stmt, 0); } } } /* ------------------------------------------ Return true if we should execute our pass. ------------------------------------------*/ static bool gate_gimple_manipulation (void) { /* return (flag_unit_at_a_time != 0 && flag_ipa_gimple_manipulation Don't bother doing anything if the program has errors. && !(errorcount || sorrycount));*/ return (/*optimize >= 1*/ /* Don't bother doing anything if the program has errors. */ /*&&*/ !(errorcount || sorrycount)); } struct tree_opt_pass pass_gimple_manipulation = { "gm_pass_simple", /* name */ gate_gimple_manipulation, /* gate */ execute_gimple_manipulation, /* execute */ NULL, /* sub */ NULL, /* next */ 0, /* static pass number */ 0, /* tv_id */ PROP_cfg | PROP_ssa | PROP_alias, /* properties required */ 0, /* properties provided */ 0, /* properties destroyed */ 0, /* todo_flags start */ TODO_dump_func, /* todo_flags finish */ 0 /* letter */ }; My code compilation goes fine for the new file goes fine: gcc -c -g -O2 -DIN_GCC -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -pedantic -Wno-long-long -Wno-variadic-macros -Wold-style-definition -Wmissing-format-attribute -DHAVE_CONFIG_H -I. -I. -I../.././gcc -I../.././gcc/. -I../.././gcc/../include -I../.././gcc/../libcpp/include ../.././gcc/gimple-manipulation.c -o gimple-manipulation.o But the compilation process fails further on: gcc/gcc-4.1.2/host-x86_64-unknown-linux-gnu/gcc/xgcc -Bgcc/gcc-4.1.2/host-x86_64-unknown-linux-gnu/gcc/ -B/usr/local/x86_64-unknown-linux-gnu/bin/ -B/usr/local/x86_64-unknown-linux-gnu/lib/ -isystem /usr/local/x86_64-unknown-linux-gnu/include -isystem /usr/local/x86_64-unknown-linux-gnu/sys-include -O2 -O2 -g -O2 -DIN_GCC -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -msse -c \ ../.././gcc/config/i386/crtfastmath.c \ -o crtfastmath.o ../.././gcc/config/i386/crtfastmath.c:110: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. make[2]: *** [crtfastmath.o] Error 1 make[2]: Leaving directory `gcc/gcc-4.1.2/host-x86_64-unknown-linux-gnu/gcc' make[1]: *** [all-gcc] Error 2 make[1]: Leaving directory `gcc/gcc-4.1.2' make: *** [all] Error 2 gcc/gcc-4.1.2 1223> Any help – why the issue is occurring and how can I achieve the objective?