re PR c/80097 (internal compiler error in c_fully_fold_internal with std=c89 and...
authorJakub Jelinek <jakub@redhat.com>
Tue, 21 Mar 2017 07:01:05 +0000 (08:01 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 21 Mar 2017 07:01:05 +0000 (08:01 +0100)
PR c/80097
* c-typeck.c (build_binary_op): Add EXCESS_PRECISION_EXPR only around
optional COMPOUND_EXPR with ubsan instrumentation.

* gcc.dg/ubsan/pr80097.c: New test.

From-SVN: r246302

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ubsan/pr80097.c [new file with mode: 0644]

index ac8db9b88138240d5818354625f43d345e3e0689..218b804cfa3bc8b1ec4d89788d1dfcb8d8bf3cb4 100644 (file)
@@ -1,3 +1,9 @@
+2017-03-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/80097
+       * c-typeck.c (build_binary_op): Add EXCESS_PRECISION_EXPR only around
+       optional COMPOUND_EXPR with ubsan instrumentation.
+
 2017-03-17  Marek Polacek  <polacek@redhat.com>
 
        * c-parser.c: Add C11 references.
index b4f61b0a674e8f6f98abe96ec91c8aec3c752d46..b283a211a0365152c79ca76d66a2307ab36ec61c 100644 (file)
@@ -11856,14 +11856,16 @@ build_binary_op (location_t location, enum tree_code code,
   else if (TREE_CODE (ret) != INTEGER_CST && int_operands
           && !in_late_binary_op)
     ret = note_integer_operands (ret);
-  if (semantic_result_type)
-    ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
   protected_set_expr_location (ret, location);
 
   if (instrument_expr != NULL)
     ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret),
                       instrument_expr, ret);
 
+  if (semantic_result_type)
+    ret = build1_loc (location, EXCESS_PRECISION_EXPR,
+                     semantic_result_type, ret);
+
   return ret;
 }
 
index 121c3dc7c316ba73f0c459856d8d636394fb5d40..79672408fe2b08bff212aa4108582968af5c68a7 100644 (file)
@@ -1,3 +1,8 @@
+2017-03-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/80097
+       * gcc.dg/ubsan/pr80097.c: New test.
+
 2017-03-20  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        PR tree-optimization/80054
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr80097.c b/gcc/testsuite/gcc.dg/ubsan/pr80097.c
new file mode 100644 (file)
index 0000000..4d48eea
--- /dev/null
@@ -0,0 +1,10 @@
+/* PR c/80097 */
+/* { dg-do compile } */
+/* { dg-options "-std=c89 -fsanitize=float-divide-by-zero" } */
+
+int
+foo (double a)
+{
+  int b = (1 / a >= 1);
+  return b;
+}