> The compiler is supposed to compile programs that comply with the spec
Yes.
> and not compile programs that don't.
No, there is no limitation on what a compiler does in this case.
> The concept of "compiling a program that doesn't comply with the spec" doesn't even exist!
It does, it is called "undefined behaviour".
> A text file that doesn't comply with the C spec isn't a C program.
That's the point. A program that contains UB is not a valid C program. That's what UB means.