I was creating the const char type in a wrong way. I should've used build_qualified_type, otherwise we'd ICE in the C++ FE later on due to mismatched TYPE_CANONICALs...
Tested x86_64-pc-linux-gnu, applying to ubsan branch. 2013-08-05 Marek Polacek <pola...@redhat.com> * ubsan.c (ubsan_source_location_type): Properly create const char type using build_qualified_type. * c-c++-common/ubsan/const-char-1.c: New test. --- gcc/ubsan.c.mp 2013-08-05 16:15:03.769489097 +0200 +++ gcc/ubsan.c 2013-08-05 16:15:12.352528297 +0200 @@ -226,8 +226,8 @@ ubsan_source_location_type (void) static const char *field_names[3] = { "__filename", "__line", "__column" }; tree fields[3], ret; - tree const_char_type = char_type_node; - TYPE_READONLY (const_char_type) = 1; + tree const_char_type = build_qualified_type (char_type_node, + TYPE_QUAL_CONST); ret = make_node (RECORD_TYPE); for (int i = 0; i < 3; i++) --- gcc/testsuite/c-c++-common/ubsan/const-char-1.c.mp 2013-08-05 16:15:48.733686613 +0200 +++ gcc/testsuite/c-c++-common/ubsan/const-char-1.c 2013-08-05 16:18:06.384287418 +0200 @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=shift" } */ + +void +foo (void) +{ + int y = 1 << 2; + __builtin_printf ("%d\n", y); +} Marek