Q:

Signed integers' undefined behavior and Apple Secure Coding Guide

Apple Secure Coding Guide says the following (page 27):

Also, any bits that overflow past the length of an integer variable (whether signed or unsigned) are dropped.

However, regards to signed integer overflow C standard (89) says:

An example of undefined behavior is the behavior on integer overflow.

and

If an exception occurs during the evaluation of an expression (that is, if the result is not mathematically defined or not representable), the behavior is undefined.

Is the Coding Guide wrong? Is there something here that I don't get? I am not convinced myself that Apple Secure Coding Guide could get this wrong.

A:

Here is a second opinion, from a static analyzer described as detecting undefined behavior:
int x;

int main(){
  x = 0x7fffffff + 1;
}

The analyzer is run so:
$ frama-c -val -machdep x86_32 t.c

And it produces:
[kernel] preprocessing with "gcc -C -E -I.  t.c"
[value] Analyzing a complete application starting at main
...
t.c:4:[kernel] warning: signed overflow. assert 0x7fffffff+1 ≤ 2147483647;
...
[value] Values at end of function main:
  NON TERMINATING FUNCTION

This means that the program t.c contains undefined behavior, and that no execution of it ever terminates without causing undefined behavior.

A:

Let's take this example:
1 << 32

If we assume 32-bit int, C clearly says it is undefined behavior. Period.
But any implementation can define this undefined behavior.
gcc for example says (while not very explicit in defining the behavior): 

GCC does not use the latitude given in C99 only to treat certain aspects of signed '<<' as undefined, but this is subject to change. 

http://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
I don't know for clang but I suspect that as for gcc, the evaluation of an expression like 1 << 32 would give no surprise (that is, evaluate to 0).
But even if it is defined on implementations running in Apple operating systems, a portable program should not make use of expressions that invoke undefined behavior in the C language.
EDIT: I thought the Apple sentence was dealing only with bitwise << operator. It looks like it's more general and in that case for C language, they are utterly wrong.

