Bug 40780 - [4.4/4.5 Regression] ICE in gimplify_conversion
Summary: [4.4/4.5 Regression] ICE in gimplify_conversion
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: 4.4.1
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-16 23:49 UTC by Jakub Jelinek
Modified: 2009-07-17 10:57 UTC (History)
2 users (show)

See Also:
Host:
Target: i686-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-07-17 08:42:41


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2009-07-16 23:49:22 UTC
template <class T1, typename T2, typename T3>
struct A
{
  typedef T2 (T1::*m) (T3);
  A (m) {}
};
struct B;
struct C
{
  void foo (B *);
};
typedef A <C, void, B *> D;
typedef void (C::*E) (B *);
struct F;
typedef void (C::*G) (F);
D d ((E) (G) & C::foo);

ICEs with -m32:
rh511229.ii: In function 'void __static_initialization_and_destruction_0(int, int)':
rh511229.ii:16:22: internal compiler error: tree check: expected class 'expression', have 'constant' (ptrmem_cst) in gimplify_conversion, at gimplify.c:1831
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

The ICE started between r140129 and r140150.
Comment 1 Jakub Jelinek 2009-07-17 00:08:53 UTC
r140145 in particular.
Comment 2 Dodji Seketeli 2009-07-17 08:15:18 UTC
Richard, could you please have a look at this one ?
Thanks in advance :-)
Comment 3 Jakub Jelinek 2009-07-17 08:42:40 UTC
I believe we should do:
--- gimplify.c.jj72009-07-08 11:28:03.000000000 +0200
+++ gimplify.c2009-07-17 10:40:56.000000000 +0200
@@ -1826,7 +1826,7 @@ gimplify_conversion (tree *expr_p)
 
   /* If we have a conversion to a non-register type force the
      use of a VIEW_CONVERT_EXPR instead.  */
-  if (!is_gimple_reg_type (TREE_TYPE (*expr_p)))
+  if (CONVERT_EXPR_P (*expr_p) && !is_gimple_reg_type (TREE_TYPE (*expr_p)))
     *expr_p = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (*expr_p),
    TREE_OPERAND (*expr_p, 0));
 

which fixes the testcase (see earlier ifs in gimplify_conversion which also test CONVERT_EXPR_P (*expr_p), as each step might turn the conversion into something different and blindly using TREE_OPERAND (*expr_p, 0) on something that doesn't have operands is wrong.
Comment 4 Richard Biener 2009-07-17 09:14:29 UTC
Yes, looks obvious.  Thus, the patch is ok if it bootstraps/tests.
Comment 5 Jakub Jelinek 2009-07-17 10:40:39 UTC
Subject: Bug 40780

Author: jakub
Date: Fri Jul 17 10:40:09 2009
New Revision: 149740

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149740
Log:
	PR c++/40780
	* gimplify.c (gimplify_conversion): Don't change non-conversions into
	VIEW_CONVERT_EXPR.

	* g++.dg/template/ptrmem19.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/template/ptrmem19.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimplify.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 Jakub Jelinek 2009-07-17 10:46:00 UTC
Subject: Bug 40780

Author: jakub
Date: Fri Jul 17 10:45:40 2009
New Revision: 149741

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149741
Log:
	PR c++/40780
	* gimplify.c (gimplify_conversion): Don't change non-conversions into
	VIEW_CONVERT_EXPR.

	* g++.dg/template/ptrmem19.C: New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/ptrmem19.C
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/gimplify.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog

Comment 7 Jakub Jelinek 2009-07-17 10:57:31 UTC
Fixed.