aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2013-09-18 13:31:34 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2013-09-18 13:31:34 +0000
commita24d975caa592f57e0966687ca0340714df9a6a0 (patch)
tree97eab07355cd3cdcb2aa83c4500a803b8b9678d4
parent0547c9b695fcbcd477f7e455c2bf376ce1ec23d1 (diff)
downloadgcc-a24d975caa592f57e0966687ca0340714df9a6a0.zip
gcc-a24d975caa592f57e0966687ca0340714df9a6a0.tar.gz
gcc-a24d975caa592f57e0966687ca0340714df9a6a0.tar.bz2
re PR sanitizer/58443 (ubsan doesn't properly honor fsanitize= flags)
2013-09-18 Marek Polacek <polacek@redhat.com> PR sanitize/58443 cp/ * typeck.c (cp_build_binary_op): Properly honor -fsanitize options. Remove unnecessary check. c/ * c-typeck.c (build_binary_op): Properly honor -fsanitize options. Remove unnecessary check. testsuite/ * g++.dg/ubsan/div-by-zero-1.C: Use the integer-divide-by-zero option instead of the shift option. * c-c++-common/ubsan/pr58443-1.c: New test. * c-c++-common/ubsan/pr58443-3.c: New test. * c-c++-common/ubsan/pr58443-2.c: New test. From-SVN: r202701
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-typeck.c8
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c8
-rw-r--r--gcc/testsuite/ChangeLog9
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/pr58443-1.c11
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/pr58443-2.c11
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/pr58443-3.c18
-rw-r--r--gcc/testsuite/g++.dg/ubsan/div-by-zero-1.C2
9 files changed, 70 insertions, 9 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 59b71aa..81b2018 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,5 +1,11 @@
2013-09-18 Marek Polacek <polacek@redhat.com>
+ PR sanitize/58443
+ * c-typeck.c (build_binary_op): Properly honor -fsanitize options.
+ Remove unnecessary check.
+
+2013-09-18 Marek Polacek <polacek@redhat.com>
+
PR sanitizer/58411
* c-typeck.c (build_binary_op): Don't sanitize function if it has the
no_sanitize_undefined attribute.
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 7dc5527..7ecafe4 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -10496,7 +10496,7 @@ build_binary_op (location_t location, enum tree_code code,
return error_mark_node;
}
- if (flag_sanitize & SANITIZE_UNDEFINED
+ if ((flag_sanitize & (SANITIZE_SHIFT | SANITIZE_DIVIDE))
&& current_function_decl != 0
&& !lookup_attribute ("no_sanitize_undefined",
DECL_ATTRIBUTES (current_function_decl))
@@ -10507,9 +10507,9 @@ build_binary_op (location_t location, enum tree_code code,
op1 = c_save_expr (op1);
op0 = c_fully_fold (op0, false, NULL);
op1 = c_fully_fold (op1, false, NULL);
- if (doing_div_or_mod)
+ if (doing_div_or_mod && (flag_sanitize & SANITIZE_DIVIDE))
instrument_expr = ubsan_instrument_division (location, op0, op1);
- else if (doing_shift)
+ else if (doing_shift && (flag_sanitize & SANITIZE_SHIFT))
instrument_expr = ubsan_instrument_shift (location, code, op0, op1);
}
@@ -10537,7 +10537,7 @@ build_binary_op (location_t location, enum tree_code code,
ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
protected_set_expr_location (ret, location);
- if ((flag_sanitize & SANITIZE_UNDEFINED) && instrument_expr != NULL)
+ if (instrument_expr != NULL)
ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret),
instrument_expr, ret);
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c16d682..d53fb51 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
2013-09-18 Marek Polacek <polacek@redhat.com>
+ PR sanitize/58443
+ * typeck.c (cp_build_binary_op): Properly honor -fsanitize options.
+ Remove unnecessary check.
+
+2013-09-18 Marek Polacek <polacek@redhat.com>
+
PR sanitizer/58411
* typeck.c (cp_build_binary_op): Don't sanitize function if it has the
no_sanitize_undefined attribute.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index f7d6208..bcb8782 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4884,7 +4884,7 @@ cp_build_binary_op (location_t location,
if (build_type == NULL_TREE)
build_type = result_type;
- if ((flag_sanitize & SANITIZE_UNDEFINED)
+ if ((flag_sanitize & (SANITIZE_SHIFT | SANITIZE_DIVIDE))
&& !processing_template_decl
&& current_function_decl != 0
&& !lookup_attribute ("no_sanitize_undefined",
@@ -4898,7 +4898,7 @@ cp_build_binary_op (location_t location,
tf_none));
op1 = maybe_constant_value (fold_non_dependent_expr_sfinae (op1,
tf_none));
- if (doing_div_or_mod)
+ if (doing_div_or_mod && (flag_sanitize & SANITIZE_DIVIDE))
{
/* For diagnostics we want to use the promoted types without
shorten_binary_op. So convert the arguments to the
@@ -4912,7 +4912,7 @@ cp_build_binary_op (location_t location,
}
instrument_expr = ubsan_instrument_division (location, cop0, cop1);
}
- else if (doing_shift)
+ else if (doing_shift && (flag_sanitize & SANITIZE_SHIFT))
instrument_expr = ubsan_instrument_shift (location, code, op0, op1);
}
@@ -4926,7 +4926,7 @@ cp_build_binary_op (location_t location,
&& !TREE_OVERFLOW_P (op1))
overflow_warning (location, result);
- if ((flag_sanitize & SANITIZE_UNDEFINED) && instrument_expr != NULL)
+ if (instrument_expr != NULL)
result = fold_build2 (COMPOUND_EXPR, TREE_TYPE (result),
instrument_expr, result);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7a243c3..8fc5174 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2013-09-18 Marek Polacek <polacek@redhat.com>
+
+ PR sanitize/58443
+ * g++.dg/ubsan/div-by-zero-1.C: Use the integer-divide-by-zero option
+ instead of the shift option.
+ * c-c++-common/ubsan/pr58443-1.c: New test.
+ * c-c++-common/ubsan/pr58443-3.c: New test.
+ * c-c++-common/ubsan/pr58443-2.c: New test.
+
2013-09-18 Richard Biener <rguenther@suse.de>
PR tree-optimization/58417
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr58443-1.c b/gcc/testsuite/c-c++-common/ubsan/pr58443-1.c
new file mode 100644
index 0000000..76f1dda
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/pr58443-1.c
@@ -0,0 +1,11 @@
+/* PR sanitizer/58443 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=shift,unreachable -w" } */
+
+int
+foo (int u, int o)
+{
+ return u / o;
+}
+
+/* { dg-final { scan-assembler-not "__ubsan_handle_divrem_overflow" } } */
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr58443-2.c b/gcc/testsuite/c-c++-common/ubsan/pr58443-2.c
new file mode 100644
index 0000000..a135758
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/pr58443-2.c
@@ -0,0 +1,11 @@
+/* PR sanitizer/58443 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=unreachable,integer-divide-by-zero -w" } */
+
+int
+foo (int u, int o)
+{
+ return u >> o;
+}
+
+/* { dg-final { scan-assembler-not "__ubsan_handle_shift_out_of_bounds" } } */
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr58443-3.c b/gcc/testsuite/c-c++-common/ubsan/pr58443-3.c
new file mode 100644
index 0000000..5696a62
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/pr58443-3.c
@@ -0,0 +1,18 @@
+/* PR sanitizer/58443 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined -w" } */
+
+int
+foo (int u, int o)
+{
+ return u >> o;
+}
+
+int
+bar (int u, int o)
+{
+ return u / o;
+}
+
+/* { dg-final { scan-assembler "__ubsan_handle_divrem_overflow" } } */
+/* { dg-final { scan-assembler "__ubsan_handle_shift_out_of_bounds" } } */
diff --git a/gcc/testsuite/g++.dg/ubsan/div-by-zero-1.C b/gcc/testsuite/g++.dg/ubsan/div-by-zero-1.C
index d7d2c8f1..88acfa1 100644
--- a/gcc/testsuite/g++.dg/ubsan/div-by-zero-1.C
+++ b/gcc/testsuite/g++.dg/ubsan/div-by-zero-1.C
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-fsanitize=shift -w" } */
+/* { dg-options "-fsanitize=integer-divide-by-zero -w" } */
void
foo (int i)