clang generating UD2?

Programming, for all ages and all languages.
Post Reply
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

clang generating UD2?

Post 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.
Fanael
Member
Member
Posts: 38
Joined: Fri Oct 16, 2009 9:20 am

Re: clang generating UD2?

Post by Fanael »

There's an undefined behavior in your code, you may consider yourself lucky not to meet the nasal demons.
Post Reply