GCC Bugzilla – Bug 34500
Bind(C): Character returning function with ENTRY gives ICE
Last modified: 2010-12-13 21:06:53 UTC
function test() bind(C)
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 (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:
master.0.test2 (0, &tmp, len);
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).
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.)