]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR sanitizer/80348 (UBSAN: compile time crash in ubsan_instrument_division)
authorMarek Polacek <polacek@redhat.com>
Sat, 24 Jun 2017 10:57:01 +0000 (10:57 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Sat, 24 Jun 2017 10:57:01 +0000 (10:57 +0000)
PR sanitizer/80348
* typeck.c (cp_build_binary_op): Convert COP[01] to ORIG_TYPE.

* g++.dg/ubsan/div-by-zero-2.C: New test.

From-SVN: r249623

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ubsan/div-by-zero-2.C [new file with mode: 0644]

index 17085d81ce18d930b8f093af1fd40458f62bc451..36d86098a347e9ff728ff60cedaac0fb12d26a12 100644 (file)
@@ -8,11 +8,14 @@
        * parser.c (cp_parser_std_attribute_list): Return error_mark if
        make_pack_expansion returns an error.
 
-       2017-04-18  Marek Polacek  <polacek@redhat.com>
-
        PR c++/80244 - ICE with attribute in template alias.
        * tree.c (strip_typedefs): Handle UNDERLYING_TYPE.
 
+       2017-04-07  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/80348
+       * typeck.c (cp_build_binary_op): Convert COP[01] to ORIG_TYPE.
+
 2017-06-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index 5b0e2733d1fdf2a773c62013d4c5bef2350ab789..ebde9a8dd06a3b37362894552c613899f4778c55 100644 (file)
@@ -5142,10 +5142,12 @@ cp_build_binary_op (location_t location,
             original result_type.  */
          tree cop0 = op0;
          tree cop1 = op1;
-         if (orig_type != NULL && result_type != orig_type)
+         if (orig_type != NULL_TREE)
            {
-             cop0 = cp_convert (orig_type, op0, complain);
-             cop1 = cp_convert (orig_type, op1, complain);
+             if (TREE_TYPE (cop0) != orig_type)
+               cop0 = cp_convert (orig_type, op0, complain);
+             if (TREE_TYPE (cop1) != orig_type)
+               cop1 = cp_convert (orig_type, op1, complain);
            }
          instrument_expr = ubsan_instrument_division (location, cop0, cop1);
        }
index bbb56ad894b8de4e6f2f3f74caa90a6c1696ffaf..368b097a398d577a584ec2c1aff9c1c95d236329 100644 (file)
@@ -9,6 +9,11 @@
        PR c++/80244 - ICE with attribute in template alias.
        * g++.dg/cpp0x/alias-decl-59.C: New test.
 
+       2017-04-07  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/80348
+       * g++.dg/ubsan/div-by-zero-2.C: New test.
+
 2017-06-23  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/g++.dg/ubsan/div-by-zero-2.C b/gcc/testsuite/g++.dg/ubsan/div-by-zero-2.C
new file mode 100644 (file)
index 0000000..d500ae6
--- /dev/null
@@ -0,0 +1,10 @@
+// PR sanitizer/80348
+// { dg-do compile }
+// { dg-options "-fsanitize=integer-divide-by-zero" }
+
+void
+foo ()
+{
+  if (0)
+    unsigned ((0 != 60806) > (0 != 0)) / 0; // { dg-warning "division by zero" }
+}