PR sanitizer/64906
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 25 Sep 2015 09:50:29 +0000 (09:50 +0000)
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 25 Sep 2015 09:50:29 +0000 (09:50 +0000)
* c-ubsan.c (ubsan_instrument_division): Also pre-evaluate OP1.

* c-c++-common/ubsan/pr64906.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@228112 138bc75d-0d04-0410-961f-82ee72b054a4

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

index e409150..b9feff6 100644 (file)
@@ -1,3 +1,8 @@
+2015-09-25  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/64906
+       * c-ubsan.c (ubsan_instrument_division): Also pre-evaluate OP1.
+
 2015-09-24  Patrick Palka  <ppalka@gcc.gnu.org>
 
        * c-indentation.c (should_warn_for_misleading_indentation):
index e0cce84..d2bc264 100644 (file)
@@ -104,6 +104,7 @@ ubsan_instrument_division (location_t loc, tree op0, tree op1)
        }
     }
   t = fold_build2 (COMPOUND_EXPR, TREE_TYPE (t), unshare_expr (op0), t);
+  t = fold_build2 (COMPOUND_EXPR, TREE_TYPE (t), unshare_expr (op1), t);
   if (flag_sanitize_undefined_trap_on_error)
     tt = build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0);
   else
index 193eb8e..cfa23c6 100644 (file)
@@ -1,3 +1,8 @@
+2015-09-25  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/64906
+       * c-c++-common/ubsan/pr64906.c: New test.
+
 2015-09-24  H.J. Lu  <hongjiu.lu@intel.com>
 
        * gcc.target/i386/pr66749.c (dg-options): Replace -mtune=iamcu
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr64906.c b/gcc/testsuite/c-c++-common/ubsan/pr64906.c
new file mode 100644 (file)
index 0000000..e0ac0ee
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR sanitizer/64906 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=integer-divide-by-zero -O -Werror=maybe-uninitialized" } */
+
+int
+fn1 (int f, int s)
+{
+  int ret = 0;
+  if (f)
+    ret = s / (f ? (unsigned long) 8 : 0);
+  return ret;
+}