We were missing a check that the TYPE_MAX_VALUE is not NULL. If it is, we ICE later when gimplifying the UBSAN_BOUNDS call arguments.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2014-07-15 Marek Polacek <pola...@redhat.com> * c-ubsan.c (ubsan_instrument_bounds): Don't instrument if TYPE_MAX_VALUE is NULL. * gcc.dg/ubsan/bounds-1.c: New test. diff --git gcc/c-family/c-ubsan.c gcc/c-family/c-ubsan.c index 3698580..ad5dd0b 100644 --- gcc/c-family/c-ubsan.c +++ gcc/c-family/c-ubsan.c @@ -265,7 +265,7 @@ ubsan_instrument_bounds (location_t loc, tree array, tree *index, tree type = TREE_TYPE (array); tree domain = TYPE_DOMAIN (type); - if (domain == NULL_TREE) + if (domain == NULL_TREE || TYPE_MAX_VALUE (domain) == NULL_TREE) return NULL_TREE; tree bound = TYPE_MAX_VALUE (domain); diff --git gcc/testsuite/gcc.dg/ubsan/bounds-1.c gcc/testsuite/gcc.dg/ubsan/bounds-1.c index e69de29..6f3cd2d 100644 --- gcc/testsuite/gcc.dg/ubsan/bounds-1.c +++ gcc/testsuite/gcc.dg/ubsan/bounds-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=bounds" } */ + +struct T { int c; char d[]; } t = { 1, "abcdefg" }; + +int +baz (int i) +{ + return t.d[i]; +} Marek