diff options
Diffstat (limited to 'gcc/ubsan.c')
-rw-r--r-- | gcc/ubsan.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/gcc/ubsan.c b/gcc/ubsan.c index b8d40d52128..9dc19c9d29a 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -233,10 +233,9 @@ ubsan_source_location (location_t loc) static unsigned short get_ubsan_type_info_for_type (tree type) { - int prec = exact_log2 (TYPE_PRECISION (type)); - if (prec == -1) - error ("unexpected size of type %qT", type); - + gcc_assert (TYPE_SIZE (type) && host_integerp (TYPE_SIZE (type), 1)); + int prec = exact_log2 (tree_low_cst (TYPE_SIZE (type), 1)); + gcc_assert (prec != -1); return (prec << 1) | !TYPE_UNSIGNED (type); } @@ -260,11 +259,18 @@ ubsan_type_descriptor (tree type) unsigned short tkind, tinfo; /* At least for INTEGER_TYPE/REAL_TYPE/COMPLEX_TYPE, this should work. - ??? For e.g. type_unsigned_for (type), the TYPE_NAME would be NULL. */ + For e.g. type_unsigned_for (type) or bit-fields, the TYPE_NAME + would be NULL. */ if (TYPE_NAME (type) != NULL) - tname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); + { + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) + tname = IDENTIFIER_POINTER (TYPE_NAME (type)); + else + tname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); + } else tname = "<unknown>"; + if (TREE_CODE (type) == INTEGER_TYPE) { /* For INTEGER_TYPE, this is 0x0000. */ |