]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/80097 (internal compiler error in c_fully_fold_internal with std...
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 08:16:31 +0000 (10:16 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 08:16:31 +0000 (10:16 +0200)
Backported from mainline
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.

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

From-SVN: r248661

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

index 55d8225bf03be4c5cc78cc4f77ea7ec1327687e7..510bb7fc500d997af4971cb61f8d31807e1b6b7b 100644 (file)
@@ -1,6 +1,12 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       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-02-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/79512
index 8f3086e38f9e4bd58b10ad62df583f7945e22719..ce20eead1393c79cefe0b3cae0f00f340eb514ed 100644 (file)
@@ -11338,14 +11338,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 39e8328464853e2913cfc22b23c7b5c6a1bce9b6..7f1612091ef3419ccc344bf38c53acafb72e6379 100644 (file)
@@ -1,6 +1,11 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2017-03-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/80097
+       * gcc.dg/ubsan/pr80097.c: New test.
+
        2017-03-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/79896
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;
+}