This is the mail archive of the gcc@gcc.gnu.org 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]

loop_latch_edge is NULL during jump threading


In linaro-4.9-branch, with the following (reduced) test case, I run into
a situation where loop_latch_edge is NULL during jump threading. I am
wondering if this  a possible during jump threading or the error lies
some where else? I can't reproduce it with the trunk.

int a;
fn1() {
  enum { UQSTRING, SQSTRING, QSTRING } b = UQSTRING;
  while (1)
    switch (a) {
    case '\'':
      b = QSTRING;
    default:
      switch (b)
      case UQSTRING:
      return;
      b = SQSTRING;
    }
}

x.c:2:1: internal compiler error: Segmentation fault
 fn1() {
 ^
0x83694f crash_signal
	/home/kugan.vivekanandarajah/work/sources/gcc-fsf/linaro/gcc/toplev.c:337
0x96d8a8 thread_block_1
	/home/kugan.vivekanandarajah/work/sources/gcc-fsf/linaro/gcc/tree-ssa-threadupdate.c:797
0x96da3e thread_block
	/home/kugan.vivekanandarajah/work/sources/gcc-fsf/linaro/gcc/tree-ssa-threadupdate.c:941
0x96e59c thread_through_all_blocks(bool)
	/home/kugan.vivekanandarajah/work/sources/gcc-fsf/linaro/gcc/tree-ssa-threadupdate.c:1866
0x9d77e9 finalize_jump_threads
	/home/kugan.vivekanandarajah/work/sources/gcc-fsf/linaro/gcc/tree-vrp.c:9709
0x9d77e9 execute_vrp
	/home/kugan.vivekanandarajah/work/sources/gcc-fsf/linaro/gcc/tree-vrp.c:9864
0x9d77e9 execute
	/home/kugan.vivekanandarajah/work/sources/gcc-fsf/linaro/gcc/tree-vrp.c:9938
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.

If I apply the following patch, segfault goes away. Is this aright approach?

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index d1b289f..0bcef35 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -794,6 +794,8 @@ thread_block_1 (basic_block bb, bool noloop_only,
bool joiners)
   if (loop->header == bb)
     {
       e = loop_latch_edge (loop);
+      if (!e)
+	return false;
       vec<jump_thread_edge *> *path = THREAD_PATH (e);

       if (path
@@ -1114,6 +1116,8 @@ thread_through_loop_header (struct loop *loop,
bool may_peel_loop_headers)
   basic_block tgt_bb, atgt_bb;
   enum bb_dom_status domst;

+  if (!latch)
+    return false;
   /* We have already threaded through headers to exits, so all the
threading
      requests now are to the inside of the loop.  We need to avoid creating
      irreducible regions (i.e., loops with more than one entry block), and


Thanks,
Kugan


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