[LLVMdev] [cfe-dev] LLVM frontend supporting arbitrary bit-width integral datatypes

Duncan Sands baldrick at free.fr
Thu Jun 25 07:16:07 PDT 2009


Hi Sebastian,

> You're producing a signed overflow, which is simply undefined behavior.
> Unsigned overflow is well-defined, even for bitfields, but signed is not.

that's true, here's an unsigned version (outputs 5 + 5 = 2):

#include <stdio.h>

struct i3 { unsigned i:3; };

int main(void) {
   struct i3 A, B, C;

   A.i = 5;
   B.i = 5;
   C.i = A.i + B.i;
   printf("%d + %d = %d\n", A.i, B.i, C.i);
   return 0;
}
Ciao,

Duncan.



More information about the llvm-dev mailing list