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 ;
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.
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.
Created attachment 21091 [details] gcc46-pr44808.patch Untested fix.
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
Fixed.