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

[PATCH] Fix ICEs in expand_builtin_expect (PR middle-end/31959)


Hi!

http://gcc.gnu.org/ml/gcc-patches/2006-11/msg00718.html
patch removed the RTL NOTE_INSN_EXPECTED_VALUE notes and
asserted that if flag_guess_branch_prob expand_builtin_expect
is not called (as strip_builtin_expect in pass_profile
should nuke them).  But, pass_profile isn't gated only
on flag_guess_branch_prob, but also on the common
pass_all_early_optimizations conditions (optimize > 0
and no errors or sorrycount), as the attached two testcases
prove.
Either we can extend the assert as done in this patch,
or we could just nuke the assert.

Ok for trunk?

2007-06-19  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/31959
	* builtins.c: Include diagnostic.h.
	(expand_builtin_expect): Make gcc_assert more permissive.
	* Makefile.in (builtins.o): Depend on $(DIAGNOSTIC_H).

	* gcc.dg/pr31959-1.c: New test.
	* gcc.dg/pr31959-2.c: New test.

	* Makefile.in (omega.o): Depend on $(DIAGNOSTIC_H).

--- gcc/builtins.c.jj	2007-06-19 11:02:31.000000000 +0200
+++ gcc/builtins.c	2007-06-19 18:45:15.000000000 +0200
@@ -50,6 +50,7 @@ Software Foundation, 51 Franklin Street,
 #include "tree-mudflap.h"
 #include "tree-flow.h"
 #include "value-prof.h"
+#include "diagnostic.h"
 
 #ifndef PAD_VARARGS_DOWN
 #define PAD_VARARGS_DOWN BYTES_BIG_ENDIAN
@@ -5121,7 +5122,8 @@ expand_builtin_expect (tree exp, rtx tar
 
   target = expand_expr (arg, target, VOIDmode, EXPAND_NORMAL);
   /* When guessing was done, the hints should be already stripped away.  */
-  gcc_assert (!flag_guess_branch_prob);
+  gcc_assert (!flag_guess_branch_prob
+	      || optimize == 0 || errorcount || sorrycount);
   return target;
 }
 
--- gcc/Makefile.in.jj	2007-06-19 11:02:31.000000000 +0200
+++ gcc/Makefile.in	2007-06-19 18:47:15.000000000 +0200
@@ -2172,7 +2172,7 @@ tree-browser.o : tree-browser.c tree-bro
    $(TREE_H) $(TREE_INLINE_H) $(DIAGNOSTIC_H) $(HASHTAB_H) \
    $(TM_H) coretypes.h
 omega.o : omega.c omega.h $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
-   errors.h $(GGC_H) $(TREE_H) diagnostic.h varray.h tree-pass.h 
+   errors.h $(GGC_H) $(TREE_H) $(DIAGNOSTIC_H) varray.h tree-pass.h 
 tree-chrec.o: tree-chrec.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
    $(GGC_H) $(TREE_H) $(REAL_H) $(SCEV_H) tree-pass.h $(PARAMS_H) \
    $(DIAGNOSTIC_H) $(CFGLOOP_H) $(TREE_FLOW_H)
@@ -2329,7 +2329,7 @@ builtins.o : builtins.c $(CONFIG_H) $(SY
    $(EXPR_H) $(OPTABS_H) insn-config.h $(RECOG_H) output.h typeclass.h \
    hard-reg-set.h toplev.h hard-reg-set.h except.h $(TM_P_H) $(PREDICT_H) \
    libfuncs.h $(REAL_H) langhooks.h $(BASIC_BLOCK_H) tree-mudflap.h \
-   $(BUILTINS_DEF) $(MACHMODE_H)
+   $(BUILTINS_DEF) $(MACHMODE_H) $(DIAGNOSTIC_H)
 calls.o : calls.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
    $(TREE_H) $(FLAGS_H) $(EXPR_H) $(OPTABS_H) langhooks.h $(TARGET_H) \
    libfuncs.h $(REGS_H) toplev.h output.h $(FUNCTION_H) $(TIMEVAR_H) $(TM_P_H) \
--- gcc/testsuite/gcc.dg/pr31959-1.c.jj	2007-06-19 18:44:16.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr31959-1.c	2007-06-19 18:49:57.000000000 +0200
@@ -0,0 +1,26 @@
+/* PR middle-end/31959 */
+/* { dg-do compile } */
+/* { dg-options "-Werror -O2" } */
+/* { dg-message "warnings being treated as errors" "" {target "*-*-*"} 0 } */
+
+struct A { int i; };
+
+static inline struct A *
+baz (struct A *x)
+{
+  return x;
+}
+static inline struct A *
+bar (const struct A *x)
+{
+  return baz ((struct A *) x);	/* { dg-error "discards qualifiers" } */
+}
+
+void *
+foo (struct A *x, int y)
+{
+  void *p = (void *) 0;
+  if (__builtin_expect (y >= 6, 0))
+    p = bar (x);
+  return p;
+}
--- gcc/testsuite/gcc.dg/pr31959-2.c.jj	2007-06-19 18:44:18.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr31959-2.c	2007-06-19 18:37:04.000000000 +0200
@@ -0,0 +1,20 @@
+/* PR middle-end/31959 */
+/* { dg-do compile } */
+/* { dg-options "-O0 -fguess-branch-probability" } */
+
+struct A { int i; };
+
+static inline struct A *
+bar (struct A *x)
+{
+  return x;
+}
+
+void *
+foo (struct A *x, int y)
+{
+  void *p = (void *) 0;
+  if (__builtin_expect (y >= 6, 0))
+    p = bar (x);
+  return p;
+}

	Jakub


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