re PR c/67279 (-fsanitize=undefined spurious error: initializer element is not constant)
authorMarek Polacek <polacek@redhat.com>
Fri, 4 Sep 2015 12:37:39 +0000 (12:37 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 4 Sep 2015 12:37:39 +0000 (12:37 +0000)
PR sanitizer/67279
* c-typeck.c (build_binary_op): Don't instrument static initializers.

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

From-SVN: r227491

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

index ae1081b357db92cbc4f0177c152016798c5a9262..a61df71ae8e90c1bc78b67b5050419bbc29341ec 100644 (file)
@@ -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
index c622a9027e6f9bb0b38162f5aac0864cd5e459ff..dc223969b3ef31f8e00a1d42edf33c6643404e25 100644 (file)
@@ -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);
index 8b444ab39782a7656f09df4a718902c36b29be5c..9f692bdd58259210f6c6623ac42f291bbd646160 100644 (file)
@@ -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 (file)
index 0000000..5b5db42
--- /dev/null
@@ -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;
+}