Safer implementation of proposed fix.

Don't dyn_cast<ArrayType> unless we know it is an array type.