This patch started out as some additional testcases for the SHAPE, UBOUND, and SIZE intrinsic extensions for assumed-rank arrays added by TS29113; I realized a while ago that I had not added test coverage for polymorphic arguments. My guess that this was a likely trouble spot was correct as the new test cases did not work. :-( The one that was most concerning was an ICE when calling the SHAPE intrinsic with an assumed-rank class type argument, as reported in PR94070. (I think this ICE is similar to the one reported in PR102641 that Tobias thinks is a problem with the scalarizer.) In this case, SHAPE was calling a library function and trying to copy the array contents to a temporary, which is really stupid because SHAPE only needs to look at the descriptor and not the array contents. I thought we could handle this inline the same as UBOUND and LBOUND, by extending gfc_trans_intrinsic_bound, and avoid the library function entirely. Then, I found some other existing problems in gfc_trans_intrinsic_bound; the conditional it was building to test for the extent-zero special cases for LBOUND and UBOUND was completely wrong, and the compile-time test for the assumed-rank/assumed-size case was wrong too. So I ended up rewriting large parts of that function. I also fixed a bug in the SIZE intrinsic where it was not taking the class types into account. (SIZE is already being handled inline in a separate place, otherwise I might've merged it into gfc_trans_intrinsic_bound as well.) While I was at it I also added 3 more testcases for these functions to test for correct behavior with bind(c). All 6 new tests PASS now, and there are no other regressions. OK to commit? -Sandra