The example below raises an UNRECOVERABLE_ERROR when compiled with optimization: gcc -c -O adr.adb This seems to be a regression in snapshot 4.3.0-20080201. It is working in 4.3.0-20080111 and older releases like 4.2.3. adr.adb ================================================ pragma Extend_System(AUX_DEC); with SYSTEM; procedure ADR is function Y(E : in INTEGER) return STRING is begin return ""; end Y; function X(C : in SYSTEM.ADDRESS) return STRING is D : INTEGER; for D use at C; begin return Y(D); end X; A : SYSTEM.ADDRESS; B : STRING := ""; begin for I in 0..1 loop B := X(SYSTEM."+"(A, I)); end loop; end ADR; ================================================
What UNRECOVERABLE_ERROR?
The exception is: TYPES.UNRECOVERABLE_ERROR : comperr.adb:398
> The exception is: > > TYPES.UNRECOVERABLE_ERROR : comperr.adb:398 Please post full the error message.
The complete output is: > gcc -c -O adr.adb adr.adb:19:04: warning: variable "A" is read but never assigned adr.adb: In function 'ADR': adr.adb:5: error: expected an SSA_NAME object adr.adb:5: error: in statement # A.36 = VDEF <A.36> { A.36 } A.36 = D.375_38; +===========================GNAT BUG DETECTED==============================+ | 4.3.0 20080201 (experimental) (i686-pc-linux-gnu) verify_ssa failed | | Error detected around adr.adb:5 | | Please submit a bug report; see http://gcc.gnu.org/bugs.html. | | Use a subject line meaningful to you and us to track the bug. | | Include the entire contents of this bug box in the report. | | Include the exact gcc or gnatmake command that you entered. | | Also include sources listed below in gnatchop format | | (concatenated together with no headers between files). | +==========================================================================+ Please include these source files with error report Note that list may not be accurate in some cases, so please double check that the problem can still be reproduced with the set of files listed. adr.adb raised TYPES.UNRECOVERABLE_ERROR : comperr.adb:398 Exit 1
4.2 works for me. This is a middle-end/tree-optimization problem.
Is it possible to create an equivalent C test case (e.g. from the initial GIMPLE dumps before the ICE)?
Investigating.
The failure mode is as follows: IVOPTS decices to turn the iteration on the value of A (variable in the code) to an iteration on its address. But there is a cast in the middle a.0_4 = (system__aux_dec__TsaB) a_3(D); D.249_5 = i_131 + a.0_4; so create_iv invokes force_gimple_operand on ADDR_EXPR<NOP_EXPR<SSA_NAME>>, which is passed to gnat_gimplify_expr. The latter creates the temporary A.36 and it is never marked for renaming. I think that the problem is in create_iv: it should make sure that the SSA form is preserved, for example by invoking force_gimple_operand_bsi instead of force_gimple_operand like some functions in tree-ssa-loop-ivopts.c. But maybe the problem is the discrepancy between force_gimple_operand and force_gimple_operand_bsi: why does the latter preserve the SSA form and not the former?
> But maybe the problem is the discrepancy between force_gimple_operand and > force_gimple_operand_bsi: why does the latter preserve the SSA form and not > the former? This would fix the problem: Index: gimplify.c =================================================================== --- gimplify.c (revision 132243) +++ gimplify.c (working copy) @@ -6629,6 +6629,14 @@ force_gimple_operand (tree expr, tree *s pop_gimplify_context (NULL); + if (*stmts && gimple_in_ssa_p (cfun)) + { + tree_stmt_iterator tsi; + + for (tsi = tsi_start (*stmts); !tsi_end_p (tsi); tsi_next (&tsi)) + mark_symbols_for_renaming (tsi_stmt (tsi)); + } + return expr; } @@ -6648,14 +6656,6 @@ force_gimple_operand_bsi (block_stmt_ite expr = force_gimple_operand (expr, &stmts, simple_p, var); if (stmts) { - if (gimple_in_ssa_p (cfun)) - { - tree_stmt_iterator tsi; - - for (tsi = tsi_start (stmts); !tsi_end_p (tsi); tsi_next (&tsi)) - mark_symbols_for_renaming (tsi_stmt (tsi)); - } - if (before) bsi_insert_before (bsi, stmts, m); else
Subject: Bug 35136 Author: ebotcazou Date: Tue Feb 12 20:49:21 2008 New Revision: 132267 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132267 Log: PR middle-end/35136 * gimplify.c (force_gimple_operand_bsi): Move SSA renaming code from here to... (force_gimple_operand): ...here. Added: trunk/gcc/testsuite/gnat.dg/loop_address.adb Modified: trunk/gcc/ChangeLog trunk/gcc/gimplify.c trunk/gcc/testsuite/ChangeLog
Thanks for reporting the problem.
Something is wrong.
I'm not sure it is a good idea to change semantics of force_gimple_operand this late in 4.3 cycle.
> I'm not sure it is a good idea to change semantics of force_gimple_operand > this late in 4.3 cycle. It's not really a change of semantics, it only bridges the gap between two functions that are supposed to behave the same, but accidentally don't. Either they both should do SSA renaming, or they both shouldn't, but there is no justification for the current status in my opinion. That being said, there is a more annoying problem with IVOPTS which is now papered over twice, instead of once previously, so I don't mind backing out the change.
So, what exactly is wrong now? And what is this IVOPTs problem? ;)
> So, what exactly is wrong now? Oh nothing, just the generated code. :-) D.375_38 = (system__aux_dec__TsaB) a_3(D); A.36 = D.375_38; A.37_35 = (system__address *) &A.36; ivtmp.34_32 = (unsigned int) A.37_35; [...] D.379_8 = (system__aux_dec__TsaB) a_3(D); A.38 = D.379_8; D.380_1 = &A.38 + 2; D.381_97 = (unsigned int) D.380_1; if (ivtmp.34_58 == D.381_97) We compare apples (address of A.36) with orange (address of A.38). > And what is this IVOPTs problem? ;) It is too optimistic about addressability.
> It is too optimistic about addressability. It takes the address of non-addressable things: base &VIEW_CONVERT_EXPR<system__address>((system__aux_dec__TsaB) a_3(D))
Subject: Bug 35136 Author: ebotcazou Date: Thu Feb 14 19:07:38 2008 New Revision: 132320 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132320 Log: PR middle-end/35136 * gimplify.c (force_gimple_operand_bsi): Revert 2008-02-12 change. (force_gimple_operand): Likewise. * tree-ssa-loop-ivopts.c (may_be_nonaddressable_p): Add new cases for TARGET_MEM_REF and CONVERT_EXPR/NON_LVALUE_EXPR/NOP_EXPR. Also recurse on the operand for regular VIEW_CONVERT_EXPRs. (find_interesting_uses_address): Check addressability and alignment of the base expression only after substituting bases of IVs into it. Modified: trunk/gcc/ChangeLog trunk/gcc/gimplify.c trunk/gcc/tree-ssa-loop-ivopts.c
Hopefully for real this time.