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)
Created attachment 10900 [details] testcase
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)
Confirmed. Reduced testcase: =========================== real function FOO() real X FOO=SIGN(FOO,X) end ===========================
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.
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.
Actually looking at the simplified testcase this is a dup of bug 25392. *** This bug has been marked as a duplicate of 25392 ***