We ICEd on the following testcase because even though the underlying types were the same, theirs TREE_TYPEs were not. We can use TYPE_MAIN_VARIANT to see through the typedefs which confused us.
Tested x86_64-pc-linux-gnu, applying to the ubsan branch. 2013-08-14 Marek Polacek <pola...@redhat.com> * c-ubsan.c (ubsan_instrument_division): Use TYPE_MAIN_VARIANT in the assert. * c-c++-common/ubsan/typedef-1.c: New test. --- gcc/c-family/c-ubsan.c.mp 2013-08-14 16:55:56.322784886 +0200 +++ gcc/c-family/c-ubsan.c 2013-08-14 16:56:03.716812775 +0200 @@ -42,8 +42,10 @@ ubsan_instrument_division (location_t lo tree type = TREE_TYPE (op0); /* At this point both operands should have the same type, - because they are already converted to RESULT_TYPE. */ - gcc_assert (type == TREE_TYPE (op1)); + because they are already converted to RESULT_TYPE. + Use TYPE_MAIN_VARIANT since typedefs can confuse us. */ + gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (op0)) + == TYPE_MAIN_VARIANT (TREE_TYPE (op1))); /* TODO: REAL_TYPE is not supported yet. */ if (TREE_CODE (type) != INTEGER_TYPE) --- gcc/testsuite/c-c++-common/ubsan/typedef-1.c.mp 2013-08-14 16:58:05.767181047 +0200 +++ gcc/testsuite/c-c++-common/ubsan/typedef-1.c 2013-08-14 16:57:21.086022479 +0200 @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined" } */ + +typedef int V; +int +foo (void) +{ + V v = 9; + int a = 3; + v += v % a; + return v / 3; +} Marek