2013-09-20 Marek Polacek <polacek@redhat.com>
PR sanitizer/58413
* ubsan.c (get_ubsan_type_info_for_type): Use TYPE_SIZE instead of
TYPE_PRECISION. Add asserts.
testsuite/
* c-c++-common/ubsan/shift-4.c: New test.
From-SVN: r202776
+2013-09-20 Marek Polacek <polacek@redhat.com>
+
+ PR sanitizer/58413
+ * ubsan.c (get_ubsan_type_info_for_type): Use TYPE_SIZE instead of
+ TYPE_PRECISION. Add asserts.
+
2013-09-20 Richard Biener <rguenther@suse.de>
PR tree-optimization/58453
+2013-09-20 Marek Polacek <polacek@redhat.com>
+
+ PR sanitizer/58413
+ * c-c++-common/ubsan/shift-4.c: New test.
+
2013-09-20 Richard Biener <rguenther@suse.de>
PR tree-optimization/58453
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-fsanitize=shift -w" } */
+
+struct S { unsigned long long int b:40; } s;
+
+int
+main ()
+{
+ s.b = 2;
+ s.b <<= 120;
+ return 0;
+}
+
+/* { dg-output "shift exponent 120 is too large\[^\n\r]*(\n|\r\n|\r)" } */
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);
}