Crash your favorite compiler Write a perfectly legal code in a decent language of your choice whose compiling will either crash the compiler or send it into an infinite loop (infinite compile time).

Restrictions:


Use a standard language that is used in real world.
Use a standard, well-developed compiler (no answers like "I wrote my C compiler that crashes on everything").
The code must be legal in the language (so most likely you'll have to exploit a compiler or a language bug).
Give your compiler version and options used so that others can replicate it.
Explain why the compiler crashed, if possible.


Have fun :)
My favorite solution for GHC:


data Bad a = C (Bad a -&gt; a)

xx :: Bad a -&gt; a
xx (x@(C x')) = x' x

omega :: a
omega = xx (C xx)

main = omega


For GHC 6.12.1 both ghci Bad.hs and ghc Bad.hs loop infinitely.
GHC 7.4.1 loops infinitely when ghc -O2 Bad.hs is executed.

Explanation: omega is defined using an infinite recursion (the only way it can inhabit any type). Compiler's inliner sees xx as a simple, non-recursive function, so it tries to inline it in the definition of omega. It results in (\x@(C x') -&gt; x' x) (C xx). Seeing a pattern match on a constructor the compiler tries to reduce it, getting xx (C xx) again and loops. The trick is that xx is actually recursive, but the recursion is hidden within the data type.

Note: While writing the puzzle, I forgot I left GHC running in the infinite loop. It took all my memory, crashed Firefox and I barely managed to kill it without hard reset.