Page 1 of 1

clang generating UD2?

Posted: Sun Feb 27, 2011 8:23 pm
by NickJohnson
I just finished writing a new piece of code, but it crashes only when I enable -O3 -fomit-frame-pointer (I'm using clang as a compiler for x86). I disassembled it to try and find the problem, and what I found was a UD2 instruction halfway through a function. Isn't UD2 only supposed to be used for debugging? Could this perhaps be a compiler bug, or is there some valid purpose for the compiler inserting this instruction in a normal C function? I couldn't figure out exactly where in the C function it was, because the assembly was heavily optimized and the C function contained a large switch statement.

Edit: the UD2 instruction was the faulting instruction, if that wasn't clear.

Re: clang generating UD2?

Posted: Mon Feb 28, 2011 12:49 am
by Fanael
There's an undefined behavior in your code, you may consider yourself lucky not to meet the nasal demons.