aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2015-09-04 12:37:39 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2015-09-04 12:37:39 +0000
commitb2aaf235774b638c79fbde5ba18bd3495b7230f8 (patch)
tree3156c4838771e5bc99a49e5de85bcec907dec839 /gcc
parentf16081c2c6fb60a69195c3810fd88ed263757d21 (diff)
downloadgcc-b2aaf235774b638c79fbde5ba18bd3495b7230f8.zip
gcc-b2aaf235774b638c79fbde5ba18bd3495b7230f8.tar.gz
gcc-b2aaf235774b638c79fbde5ba18bd3495b7230f8.tar.bz2
re PR c/67279 (-fsanitize=undefined spurious error: initializer element is not constant)
PR sanitizer/67279 * c-typeck.c (build_binary_op): Don't instrument static initializers. * gcc.dg/ubsan/pr67279.c: New test. From-SVN: r227491
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/ChangeLog5
-rw-r--r--gcc/c/c-typeck.c3
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/ubsan/pr67279.c14
4 files changed, 26 insertions, 1 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index ae1081b..a61df71 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-04 Marek Polacek <polacek@redhat.com>
+
+ PR sanitizer/67279
+ * c-typeck.c (build_binary_op): Don't instrument static initializers.
+
2015-09-03 Martin Sebor <msebor@redhat.com>
PR c/66516
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index c622a90..dc22396 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -11292,7 +11292,8 @@ build_binary_op (location_t location, enum tree_code code,
if ((flag_sanitize & (SANITIZE_SHIFT | SANITIZE_DIVIDE
| SANITIZE_FLOAT_DIVIDE))
&& do_ubsan_in_current_function ()
- && (doing_div_or_mod || doing_shift))
+ && (doing_div_or_mod || doing_shift)
+ && !require_constant_value)
{
/* OP0 and/or OP1 might have side-effects. */
op0 = c_save_expr (op0);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8b444ab..9f692bd 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-04 Marek Polacek <polacek@redhat.com>
+
+ PR sanitizer/67279
+ * gcc.dg/ubsan/pr67279.c: New test.
+
2015-09-04 Andrey Turetskiy <andrey.turetskiy@intel.com>
Petr Murzin <petr.murzin@intel.com>
Kirill Yukhin <kirill.yukhin@intel.com>
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr67279.c b/gcc/testsuite/gcc.dg/ubsan/pr67279.c
new file mode 100644
index 0000000..5b5db42
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ubsan/pr67279.c
@@ -0,0 +1,14 @@
+/* PR sanitizer/67279 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined -w" } */
+
+#define INT_MIN (-__INT_MAX__ - 1)
+
+void
+foo (void)
+{
+ static int a1 = 1 << 31;
+ static int a2 = 10 << 30;
+ static int a3 = 100 << 28;
+ static int a4 = INT_MIN / -1;
+}