User account creation filtered due to spam.

Bug 34500 - Bind(C): Character returning function with ENTRY gives ICE
Summary: Bind(C): Character returning function with ENTRY gives ICE
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: ice-on-valid-code, rejects-valid
Depends on:
Blocks: 19276 32630
  Show dependency treegraph
Reported: 2007-12-16 20:37 UTC by Tobias Burnus
Modified: 2014-06-16 10:52 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2009-12-13 16:23:55


Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-12-16 20:37:00 UTC
Test case:

function test() bind(C)
  use iso_c_binding
  implicit none
  character(len=1,kind=c_char) :: test, bar
entry bar() bind(C)
end function test

ICE occurs if either test() or bar() or both are bind(c).

The ENTRY fix needs to go into build_entry_thunks:
      if (thunk_sym->attr.function)
          if (gfc_return_by_reference (ns->proc_name))
This branch is entered as the master function,  proc_name, is is_bind_c ==
false, but it fails currently if (thunk_sym->attr.is_bind_c &&
thunk_sym->ts.type == BT_CHARACTER).

The proper tree should looks more or less as follows:

test2 ()
  character(kind=1) tmp[1:1];
  integer(kind=4) len;
  master.0.test2 (0, &tmp, len);
  return tmp[1];

That is test() itself returns a scalar character, but master.0.test2 takes the
string as argument, which allows to combine bind(C) with non-bind(C) functions
and allows for different string lengths of ENTRY and function (cf. PR 34421).
Comment 1 Andrew Pinski 2007-12-23 19:09:07 UTC
Comment 2 Tobias Burnus 2008-08-24 10:02:20 UTC
As PR 37201 shows, testing "result = funct()" is not enough, one should also test "otherfunc(func())" and "print *, func()". (Though the problems will probably be solved by the fix for PR 37201.)
Comment 3 Francois-Xavier Coudert 2014-06-16 10:11:41 UTC
Since 4.9, the code is now rejected (though it's valid):

$ gfortran a.f90    

  character(len=1,kind=c_char) :: test, bar

entry bar() bind(C)
Error: Procedure bar with binding label bar at (1) uses the same global identifier as entity at (2)
Comment 4 Dominique d'Humieres 2014-06-16 10:52:05 UTC
> Since 4.9, the code is now rejected (though it's valid): ...

The change occurred between r199034 (ICE, 2013-05-17) and r199221 (error, 2013-05-22).
I suspect r199120 (pr48858 and pr55465), although r199118 and r199119 are also candidates.