Bug 26440 - ICE in expand_copysign, at optabs.c:2930 with using -ff2c
Summary: ICE in expand_copysign, at optabs.c:2930 with using -ff2c
Status: RESOLVED DUPLICATE of bug 25392
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, monitored
Depends on: 25392
Blocks:
  Show dependency treegraph
 
Reported: 2006-02-23 12:40 UTC by Richard Biener
Modified: 2006-02-24 17:40 UTC (History)
3 users (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-02-23 15:33:56


Attachments
testcase (443 bytes, text/plain)
2006-02-23 12:40 UTC, Richard Biener
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2006-02-23 12:40:28 UTC
The attached testcase ICEs with

./f951 t.f -ffixed-form -quiet -dumpbase t.f -mtune=pentiumpro -auxbase t -O0 -pedantic -W -Waliasing -std=legacy -version -fno-automatic -frepack-arrays -ff2c -o /dev/null 
GNU F95 version 4.1.0 20060222 (prerelease) (i686-pc-linux-gnu)
        compiled by GNU C version 4.0.2 20050901 (prerelease) (SUSE Linux).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
t.f: In function ‘gvftor’:
t.f:37: internal compiler error: in expand_copysign, at optabs.c:2930
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

(ICEs also with mainline)
Comment 1 Richard Biener 2006-02-23 12:40:51 UTC
Created attachment 10900 [details]
testcase
Comment 2 Richard Biener 2006-02-23 12:48:40 UTC
We are trying to expand

#3  0x0816828b in expand_builtin (exp=0x401f8258, target=0x401f3e30, subtarget=0x401f3e30, mode=SFmode, ignore=0)
    at /space/rguenther/src/svn/gcc-4_1-branch/gcc/builtins.c:5651
5651          target = expand_builtin_copysign (arglist, target, subtarget);
(gdb) call debug_tree(exp)
 <call_expr 0x401f8258
    type <real_type 0x401cd958 real4 SF
        size <integer_cst 0x401bf3f0 constant invariant 32>
        unit size <integer_cst 0x401bf180 constant invariant 4>
        align 32 symtab 0 alias set -1 precision 32
        pointer_to_this <pointer_type 0x401cda6c>>
   
    arg 0 <addr_expr 0x40209e60
        type <pointer_type 0x4020e33c type <function_type 0x401f66d4>
            unsigned SI size <integer_cst 0x401bf3f0 32> unit size <integer_cst 0x401bf180 4>
            align 32 symtab 0 alias set -1>
        readonly constant invariant
        arg 0 <function_decl 0x401fe780 __builtin_copysignf type <function_type 0x401f66d4>
            readonly addressable public external built-in QI file t.f line 0
            built-in BUILT_IN_NORMAL:BUILT_IN_COPYSIGNF
            (mem:QI (symbol_ref:SI ("copysignf") [flags 0x41] <function_decl 0x401fe780 __builtin_copysignf>) [0 S1 A8]) chain <function_decl 0x401fe700 __builtin_copysign>>>
    arg 1 <tree_list 0x4020c360
        value <var_decl 0x401ca370 __result_gvftor type <real_type 0x401cd9b4 real8>
            used DF file t.f line 31
            size <integer_cst 0x401bf528 constant invariant 64>
            unit size <integer_cst 0x401bf540 constant invariant 8>
            align 32 context <function_decl 0x40206e80 gvftor>
            (mem/c/i:DF (plus:SI (reg/f:SI 54 virtual-stack-vars)
        (const_int -8 [0xfffffff8])) [0 __result_gvftor+0 S8 A32])>
        chain <tree_list 0x4020c3a8 value <var_decl 0x401ca580 D.609>>>
    t.f:37>

where we later call 

#2  0x08166042 in expand_builtin_copysign (arglist=0x4020c360, target=0x401f3e30, subtarget=0x401f3e30)
    at /space/rguenther/src/svn/gcc-4_1-branch/gcc/builtins.c:4818
4818      return expand_copysign (op0, op1, target);

with

(gdb) call debug_rtx(op0)
(mem/c/i:DF (plus:SI (reg/f:SI 54 virtual-stack-vars)
        (const_int -8 [0xfffffff8])) [0 __result_gvftor+0 S8 A32])
(gdb) call debug_rtx(op1)
(reg:SF 60 [ D.609 ])

(note the wrong mode, which comes from a real*4 arg)
Comment 3 Volker Reichelt 2006-02-23 15:33:56 UTC
Confirmed. Reduced testcase:

===========================
      real function FOO()
          real X
          FOO=SIGN(FOO,X)
      end
===========================
Comment 4 Richard Biener 2006-02-24 11:28:12 UTC
gfc_sym_type()

  if (gfc_option.flag_f2c
      && sym->attr.function 
      && sym->ts.type == BT_REAL
      && sym->ts.kind == gfc_default_real_kind
      && !sym->attr.always_explicit)
    {
      /* Special case: f2c calling conventions require that (scalar)
         default REAL functions return the C type double instead.  */
      sym->ts.kind = gfc_default_double_kind;
      type = gfc_typenode_for_spec (&sym->ts);
      sym->ts.kind = gfc_default_real_kind;
    }

is asking for trouble.  This kind of hack has to be repeated elsewhere, so
we do not miss the type-mismatch between FOO and X.

But the real solution looks like creating the correct kind for the return
type in the first place like if it was written as REAL*8.
Comment 5 Andrew Pinski 2006-02-24 17:25:54 UTC
I want to say this is exactly the same issue as PR 25392, looking at the fact it is the return value which is causing the issue.
Comment 6 Andrew Pinski 2006-02-24 17:40:05 UTC
Actually looking at the simplified testcase this is a dup of bug 25392.

*** This bug has been marked as a duplicate of 25392 ***