From 6f2ba390aeb310887314db61d9c4876ac7801474 Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <mkuvyrkov@ispras.ru>
Date: Tue, 13 Jun 2006 08:50:53 +0000
Subject: [PATCH] re PR target/27863 (ICE in check_cfg, at haifa-sched.c:4615)

2006-06-13  Maxim Kuvyrkov  <mkuvyrkov@ispras.ru>

	* haifa-sched.c (unlink_other_notes, unlink_line_notes): Fix the patch
	for PR target/27863.

2006-06-13  Maxim Kuvyrkov  <mkuvyrkov@ispras.ru>

	* gcc.c-torture/compile/20060609-1.c: New test.

	PR target/27863
	* gcc.c-torture/compile/pr27863.c: New test.

From-SVN: r114604
---
 gcc/ChangeLog                                 |  5 +++
 gcc/haifa-sched.c                             | 32 +++++++++++--------
 gcc/testsuite/ChangeLog                       |  7 ++++
 .../gcc.c-torture/compile/20060609-1.c        |  7 ++++
 gcc/testsuite/gcc.c-torture/compile/pr27863.c | 28 ++++++++++++++++
 5 files changed, 66 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/20060609-1.c
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr27863.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index deaac82e1eb6..c5f37aa23563 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2006-06-13  Maxim Kuvyrkov  <mkuvyrkov@ispras.ru>
+
+	* haifa-sched.c (unlink_other_notes, unlink_line_notes): Fix the patch
+	for PR target/27863.
+
 2006-06-13  Richard Guenther  <rguenther@suse.de>
 
 	PR middle-end/27536
diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index 8bd65c276da4..70c13b1133af 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -1251,13 +1251,16 @@ unlink_other_notes (rtx insn, rtx tail)
       if (next)
 	PREV_INSN (next) = prev;
 
-      /* Basic block can begin with either LABEL or
-         NOTE_INSN_BASIC_BLOCK.  */
-      gcc_assert (BB_HEAD (bb) != insn);
+      if (bb)
+        {
+          /* Basic block can begin with either LABEL or
+             NOTE_INSN_BASIC_BLOCK.  */
+          gcc_assert (BB_HEAD (bb) != insn);
 
-      /* Check if we are removing last insn in the BB.  */
-      if (BB_END (bb) == insn)
-        BB_END (bb) = prev;
+          /* Check if we are removing last insn in the BB.  */
+          if (BB_END (bb) == insn)
+            BB_END (bb) = prev;
+        }
 
       /* See sched_analyze to see how these are handled.  */
       if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_EH_REGION_BEG
@@ -1283,7 +1286,7 @@ unlink_line_notes (rtx insn, rtx tail)
 {
   rtx prev = PREV_INSN (insn);
 
-  while (insn != tail && NOTE_P (insn))
+  while (insn != tail && NOTE_NOT_BB_P (insn))
     {
       rtx next = NEXT_INSN (insn);
 
@@ -1297,13 +1300,16 @@ unlink_line_notes (rtx insn, rtx tail)
 	  if (next)
 	    PREV_INSN (next) = prev;
 
-          /* Basic block can begin with either LABEL or
-             NOTE_INSN_BASIC_BLOCK.  */
-          gcc_assert (BB_HEAD (bb) != insn);
+          if (bb)
+            {
+              /* Basic block can begin with either LABEL or
+                 NOTE_INSN_BASIC_BLOCK.  */
+              gcc_assert (BB_HEAD (bb) != insn);
 
-          /* Check if we are removing last insn in the BB.  */
-          if (BB_END (bb) == insn)
-            BB_END (bb) = prev;
+              /* Check if we are removing last insn in the BB.  */
+              if (BB_END (bb) == insn)
+                BB_END (bb) = prev;
+            }
 
 	  /* Record line-number notes so they can be reused.  */
 	  LINE_NOTE (insn) = insn;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fa0ecd5fb7c2..04c639aea2a3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2006-06-13  Maxim Kuvyrkov  <mkuvyrkov@ispras.ru>
+
+	* gcc.c-torture/compile/20060609-1.c: New test.
+	
+	PR target/27863
+	* gcc.c-torture/compile/pr27863.c: New test.
+
 2006-06-13  Richard Guenther  <rguenther@suse.de>
 
 	PR tree-optimization/27830
diff --git a/gcc/testsuite/gcc.c-torture/compile/20060609-1.c b/gcc/testsuite/gcc.c-torture/compile/20060609-1.c
new file mode 100644
index 000000000000..a8152c8a5706
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/20060609-1.c
@@ -0,0 +1,7 @@
+/* This test used to ICE on IA64.  */
+int __strspn_c2 (__const char *__s, int __accept1, int __accept2)
+{
+  register long unsigned int __result = 0;
+  while (__s[__result] == __accept1 || __s[__result] == __accept2)
+  return __result;
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr27863.c b/gcc/testsuite/gcc.c-torture/compile/pr27863.c
new file mode 100644
index 000000000000..86abc06860d2
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr27863.c
@@ -0,0 +1,28 @@
+/* This test used to ICE on IA64.  */
+long stack[100];
+int main(int argc,char**argv,char **envp)
+{
+  long *esp=stack;
+  static void* jarray[]={ &&KeyCtrlKV };
+ *++esp=(long)&&_loc0;
+ goto SetTermStruc;
+ _loc0:;
+ *++esp=(long)&&_loc1;
+ _loc1:;
+*++esp=(long)&&_loc35;
+ _loc35:;
+goto *(*esp--);
+*++esp=(long)&&_loc36;
+ _loc36:;
+*++esp=(long)&&_loc37;
+ _loc37:;
+KeyCtrlKV:
+*++esp=(long)&&_loc66;
+_loc66:;
+*++esp=(long)&&_loc106;
+ _loc106:;
+*++esp=(long)&&_loc119;
+ _loc119:;
+SetTermStruc:
+ goto *(*esp--);
+}
-- 
GitLab