Sema: Factor out argument range checks for builtin functions

No behavioural change intended.