Article

Why does the compiler sometimes use ud2 and sometimes int 3 for code that shouldn’t execute?

The Old New Thing ·The Old New Thing ·Published 2026-10-06 ·5 min read

This article explains the differences between the int 3 and ud2 opcodes used by x86 compilers to indicate unreachable code. It discusses their purposes and implications for debugging.

From the article

There are two common ways for x86 compilers to indicate that execution should not have reached a particular point: One is the single-byte int 3 breakpoint opcode. And the other is the two-byte ud2 invalid instruction opcode. How do they decide which one to use?

The two types of “bad instructions” are typically for different purposes.

The int 3 means “There is no code here. If you somehow got here, then somebody used an invalid function pointer.” It is used as padding, such as between functions. There is no way that code can reach the int 3 by normal execution. You must have generated an invalid address and called it.


Share this resource


Discovered 2026-10-07 Source The Old New Thing Archive 2026-10 →