Bug 44808 - [4.6 Regression] ICE: tree check: expected var_decl, have result_decl in gimplify_modify_expr
Summary: [4.6 Regression] ICE: tree check: expected var_decl, have result_decl in gimp...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-04 12:50 UTC by Marc Glisse
Modified: 2010-07-12 10:38 UTC (History)
1 user (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-07-05 10:55:02


Attachments
gcc46-pr44808.patch (534 bytes, patch)
2010-07-05 11:04 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Glisse 2010-07-04 12:50:01 UTC
The following code produces the error:

$ c++    -c triangles_test.cpp  -O9
triangles_test.cpp: In member function ‘virtual Halfedge_handle Ovl_visitor::insert_at_vertices()’:
triangles_test.cpp:12:24: internal compiler error: tree check: expected var_decl, have result_decl in gimplify_modify_expr, at gimplify.c:4571
Please submit a full bug report,

I checked with a snapshot from the 3rd of July, so this shouldn't be the same as bug 44706 (the closest thing I could find in bugzilla).

struct Halfedge_handle
{
	void *a,*b;
	int c;
};

struct Ovl_visitor
{
	virtual Halfedge_handle insert_at_vertices ()
	{
		Halfedge_handle res;
		Halfedge_handle he = res;
		return res;
	}
};

Ovl_visitor               visitor ;
Comment 1 Richard Biener 2010-07-04 14:38:16 UTC
Confirmed.

The value-expr is odd:

;; Function virtual Halfedge_handle Ovl_visitor::insert_at_vertices() (null)
;; enabled by -tree-original


{
  struct Halfedge_handle res [value-expr: <retval>];
  struct Halfedge_handle he;

  (void) 0;
    struct Halfedge_handle he;
  <<cleanup_point <<< Unknown tree: expr_stmt
  (void) (he = TARGET_EXPR <D.1722, <retval>>) >>>
>>;
  <<cleanup_point return <retval>>>;
}

so are assignments from <retval> anyway.  Because <retval> has DECL_IGNORED_P
set we try to

  /* Try to alleviate the effects of the gimplification creating artificial
     temporaries (see for example is_gimple_reg_rhs) on the debug info.  */
  if (!gimplify_ctxp->into_ssa
      && DECL_P (*from_p)
      && DECL_IGNORED_P (*from_p)
      && DECL_P (*to_p)
      && !DECL_IGNORED_P (*to_p))
    {
      if (!DECL_NAME (*from_p) && DECL_NAME (*to_p))
        DECL_NAME (*from_p)
          = create_tmp_var_name (IDENTIFIER_POINTER (DECL_NAME (*to_p)));
      DECL_DEBUG_EXPR_IS_FROM (*from_p) = 1;
      SET_DECL_DEBUG_EXPR (*from_p, *to_p);

which requires a VAR_DECL as *from_p.
Comment 2 Jakub Jelinek 2010-07-05 10:55:02 UTC
I don't see anything odd on the value-expr (the variable res has been NRVed in the FE to the RESULT_DECL) nor on the assignments from RESULT_DECL.

So, I think either we should guard this hunk in gimplify.c with TREE_CODE (*from_p) == VAR_DECL instead of DECL_P (*from_p), or change the check in
tree.h in {,SET_}DECL_DEBUG_EXPR from VAR_DECL_CHECK to DECL_COMMON_CHECK.
There is nothing VAR_DECL specific on the lookups (all it needs is DECL_UID, which RESULT_DECL and PARM_DECLs etc. have too).  var-tracking will unlikely use it though.
Comment 3 Jakub Jelinek 2010-07-05 11:04:59 UTC
Created attachment 21091 [details]
gcc46-pr44808.patch

Untested fix.
Comment 4 Jakub Jelinek 2010-07-05 14:42:48 UTC
Subject: Bug 44808

Author: jakub
Date: Mon Jul  5 14:42:20 2010
New Revision: 161838

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161838
Log:
	PR c++/44808
	* gimplify.c (gimplify_modify_expr): Only SET_DECL_DEBUG_EXPR if
	*from_p is VAR_DECL.

	* g++.dg/opt/nrv16.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/opt/nrv16.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimplify.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Jakub Jelinek 2010-07-12 10:38:14 UTC
Fixed.