[cfe-dev] Some questions about the undefined behavior checking in clang
peng li
peterlee at cs.utah.edu
Sat May 1 20:16:21 PDT 2010
Hi There
I am a new comer for clang, and am getting a question about the
undefined-behavior checking in clang compiler
*-fcatch-undefined-behavior*: Turn on runtime code generation to check
for undefined behavior.
This option, which defaults to off, controls whether or not Clang
adds runtime checks for undefined runtime behavior. If the check
fails, __builtin_trap() is used to indicate failure. The checks are:
# Subscripting where the static type of one operand is variable which
is decayed from an array type and the other operand is greater than
the size of the array or less than zero.
# Shift operators where the amount shifted is greater or equal to the
promoted bit-width of the left-hand-side or less than zero.
# If control flow reaches __builtin_unreachable.
# When llvm implements more __builtin_object_size support, reads and
writes for objects that __builtin_object_size indicates we aren't
accessing valid memory. Bit-fields and vectors are not yet checked.
The information listed above is the verbose explanation about undefined
behavior checking flag, seems that the undefined behavior checking is
realized via the dynamic checkers instrumented into the C source code,
what I am wondering is whether those checkers should be added
automatically by clang or added by users manually.
Moreover, what is the status of the integrations of undefined behavior
checking into clang?
Thanks a lot for your replies.
Peng
More information about the cfe-dev
mailing list