The generalized Morse–Sard theorem