As has been discussed in many forums, target, intent(in) is not a reliable library solution, particularly due to automatic targeting semantics in the standard.
Fortranners may consider pointer, intent(in) instead with such use cases. The actual objects (e.g., a, b in the OP’s latest example) can thus be ALLOCATABLE (or nonallocatable) but with the TARGET attribute and that is a safer approach.