Bug 29976

Summary: [4.2/4.3 regression] ICE on optional arg
Product: gcc Reporter: Francois-Xavier Coudert <fxcoudert>
Component: fortranAssignee: Paul Thomas <pault>
Status: RESOLVED FIXED    
Severity: normal CC: eedelman, gcc-bugs, paulthomas2, pinskia
Priority: P3 Keywords: ice-on-valid-code
Version: 4.3.0   
Target Milestone: 4.2.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2006-11-27 22:25:28
Bug Depends on:    
Bug Blocks: 29975    

Description Francois-Xavier Coudert 2006-11-25 14:08:55 UTC
The following code:

SUBROUTINE pw_sumup (alpha_im)
  REAL, INTENT(in), OPTIONAL :: alpha_im
  COMPLEX :: my_alpha_c
  IF (PRESENT(alpha_im)) THEN
     my_alpha_c = CMPLX(0.,alpha_im)
  END IF
END SUBROUTINE pw_sumup

ICEs on both 4.2 and 4.3, but compiles fine on 4.1.2. The ICE for 4.3 is:
foo.f90: In function ‘pw_sumup’:
foo.f90:1: internal compiler error: in build_int_cst_wide, at tree.c:852

The ICE for 4.2 is:
foo.f90: In function ‘pw_sumup’:
foo.f90:5: internal compiler error: in immed_double_const, at emit-rtl.c:464

CCing Paul and Erik, because he commited some "optional args" patch recently if I remember correctly.
Comment 1 Andrew Pinski 2006-11-25 21:19:38 UTC
The problem for the trunk is ovbious:
#4  0x080c38c1 in gfc_conv_missing_dummy (se=0xbf926cf4, arg=0x9ea1228, ts=
      {type = BT_UNKNOWN, kind = 4, derived = 0x0, cl = 0x0}) at /src/gcc/fortran/gcc/gcc/fortran/trans-expr.c:155
155       tmp = build3 (COND_EXPR, TREE_TYPE (se->expr), present, se->expr,
(gdb) l
150     {
151       tree present;
152       tree tmp;
153
154       present = gfc_conv_expr_present (arg->symtree->n.sym);
155       tmp = build3 (COND_EXPR, TREE_TYPE (se->expr), present, se->expr,
156                     build_int_cst (TREE_TYPE (se->expr), 0));


(gdb) p debug_generic_expr (se->expr)
*alpha_imD.988
$1 = void
(gdb) p debug_tree (se->expr)
 <indirect_ref 0xb7d48020
    type <real_type 0xb7cec958 real4 SF
        size <integer_cst 0xb7cdd3d8 constant invariant 32>
        unit size <integer_cst 0xb7cdd168 constant invariant 4>
        align 32 symtab 0 alias set -1 precision 32
        pointer_to_this <pointer_type 0xb7ceca6c>>

    arg 0 <parm_decl 0xb7d47050 alpha_im
        type <pointer_type 0xb7ceca6c type <real_type 0xb7cec958 real4>
            public unsigned SI size <integer_cst 0xb7cdd3d8 32> unit size <integer_cst 0xb7cdd168 4>
            align 32 symtab 0 alias set -1>
        readonly used unsigned SI file t.f90 line 1 size <integer_cst 0xb7cdd3d8 32> unit size <integer_cst 0xb7cdd168 4>
        align 32 context <function_decl 0xb7d453f0 pw_sumup> initial <pointer_type 0xb7ceca6c> arg-type <pointer_type 0xb7ceca6c>>>


We are calling build_int_cst on a "real" type.
Comment 2 Paul Thomas 2006-11-27 06:19:18 UTC
Subject: Re:  [4.2/4.3 regression] ICE on optional arg

Andrew,
>
> We are calling build_int_cst on a "real" type.
>   
Yes, I discovered the same on my flight back to France last night.  Will 
come up with a fix tonight.

Paul
Comment 3 Paul Thomas 2006-11-27 22:25:28 UTC
I will submit the patch as 'obvious' tomorrow morning - see:

http://gcc.gnu.org/ml/fortran/2006-11/msg00686.html

Paul

Comment 4 Jerry DeLisle 2006-11-28 01:18:44 UTC
I think wrong url in comment #3
Comment 5 Paul Thomas 2006-11-28 05:25:00 UTC
Subject: Re:  [4.2/4.3 regression] ICE on optional arg

jvdelisle at gcc dot gnu dot org wrote:
> ------- Comment #4 from jvdelisle at gcc dot gnu dot org  2006-11-28 01:18 -------
> I think wrong url in comment #3
>
>
>   
'tis not.... read (ii). :-)

Paul

Comment 6 Paul Thomas 2006-11-28 05:39:52 UTC
Subject: Bug 29976

Author: pault
Date: Tue Nov 28 05:39:42 2006
New Revision: 119273

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119273
Log:
2006-11-28  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29976
	* trans-expr.c (gfc_conv_missing_dummy): Remove build_int_const
	and replace with cast to type of se->expr of integer_zero_node.

2006-11-28  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29976
	* gfortran.dg/missing_optional_dummy_3.f90

Added:
    trunk/gcc/testsuite/gfortran.dg/missing_optional_dummy_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Paul Thomas 2006-11-28 05:52:13 UTC
Subject: Bug 29976

Author: pault
Date: Tue Nov 28 05:52:02 2006
New Revision: 119275

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119275
Log:
2006-11-28  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29976
	* trans-expr.c (gfc_conv_missing_dummy): Remove build_int_const
	and replace with cast to type of se->expr of integer_zero_node.

2006-11-28  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29976
	* gfortran.dg/missing_optional_dummy_3.f90

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/missing_optional_dummy_3.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 8 Paul Thomas 2006-11-28 08:14:49 UTC
Fixed

Paul