]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR sanitizer/58413 (ubsan constant folding)
authorMarek Polacek <polacek@redhat.com>
Fri, 20 Sep 2013 13:26:07 +0000 (13:26 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 20 Sep 2013 13:26:07 +0000 (13:26 +0000)
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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/shift-4.c [new file with mode: 0644]
gcc/ubsan.c

index e4e4a69a87121bb368743e76da95fafa4d9b70d2..2e50e731b62d5bdb191a9dceeb5286467ae315d5 100644 (file)
@@ -1,3 +1,9 @@
+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
index 8d287f1665c781bfeff017441d275a0489f53b41..f34163210b55a8ce2c732f5a2415188e1e652e4c 100644 (file)
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/testsuite/c-c++-common/ubsan/shift-4.c b/gcc/testsuite/c-c++-common/ubsan/shift-4.c
new file mode 100644 (file)
index 0000000..239c013
--- /dev/null
@@ -0,0 +1,14 @@
+/* { 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)" } */
index b8d40d521289c26a508878cf2196e630664e3471..6c6fea80afd3e0fb7f036a7b12e467c337acea45 100644 (file)
@@ -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);
 }