re PR sanitizer/79757 (ICE in declare_vars, at gimplify.c:634)
authorMarek Polacek <polacek@redhat.com>
Thu, 9 Mar 2017 16:58:17 +0000 (16:58 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 9 Mar 2017 16:58:17 +0000 (16:58 +0000)
PR sanitizer/79757
* c-parser.c (c_parser_declaration_or_fndef): Don't sanitize old-style
parameter declarations with initializers.

* gcc.dg/ubsan/pr79757-1.c: New test.
* gcc.dg/ubsan/pr79757-2.c: New test.
* gcc.dg/ubsan/pr79757-3.c: New test.
* gcc.dg/ubsan/pr79757-4.c: New test.
* gcc.dg/ubsan/pr79757-5.c: New test.

From-SVN: r246010

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ubsan/pr79757-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ubsan/pr79757-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ubsan/pr79757-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ubsan/pr79757-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ubsan/pr79757-5.c [new file with mode: 0644]

index e6da629882f1f796d2b35a79d2f098bda6069184..c461c6dbb62a8f1cd224321c61dd597a924deeea 100644 (file)
@@ -1,3 +1,9 @@
+2017-03-09  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/79757
+       * c-parser.c (c_parser_declaration_or_fndef): Don't sanitize old-style
+       parameter declarations with initializers.
+
 2017-03-09  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/79969
index 8330e65fc94bcf43864ad4548f90e40e2393efad..1394f18b844f3a4083d2d9c00e6f07a23490ddf4 100644 (file)
@@ -1859,7 +1859,13 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
                  init_loc = c_parser_peek_token (parser)->location;
                  rich_location richloc (line_table, init_loc);
                  start_init (NULL_TREE, asm_name, global_bindings_p (), &richloc);
+                 /* A parameter is initialized, which is invalid.  Don't
+                    attempt to instrument the initializer.  */
+                 int flag_sanitize_save = flag_sanitize;
+                 if (nested && !empty_ok)
+                   flag_sanitize = 0;
                  init = c_parser_expr_no_commas (parser, NULL);
+                 flag_sanitize = flag_sanitize_save;
                  if (TREE_CODE (init.value) == COMPONENT_REF
                      && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1)))
                    error_at (here,
@@ -1917,7 +1923,13 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
                  init_loc = c_parser_peek_token (parser)->location;
                  rich_location richloc (line_table, init_loc);
                  start_init (d, asm_name, global_bindings_p (), &richloc);
+                 /* A parameter is initialized, which is invalid.  Don't
+                    attempt to instrument the initializer.  */
+                 int flag_sanitize_save = flag_sanitize;
+                 if (TREE_CODE (d) == PARM_DECL)
+                   flag_sanitize = 0;
                  init = c_parser_initializer (parser);
+                 flag_sanitize = flag_sanitize_save;
                  finish_init ();
                }
              if (oacc_routine_data)
index 48fba4842f6b4326be1e6f4746676e2fa0cd75fb..3da89cd3c6bb61275f0ada8a17c2bf4b12347e5f 100644 (file)
@@ -1,3 +1,12 @@
+2017-03-09  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/79757
+       * gcc.dg/ubsan/pr79757-1.c: New test.
+       * gcc.dg/ubsan/pr79757-2.c: New test.
+       * gcc.dg/ubsan/pr79757-3.c: New test.
+       * gcc.dg/ubsan/pr79757-4.c: New test.
+       * gcc.dg/ubsan/pr79757-5.c: New test.
+
 2017-03-09  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/79969
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr79757-1.c b/gcc/testsuite/gcc.dg/ubsan/pr79757-1.c
new file mode 100644 (file)
index 0000000..ca074bc
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR sanitizer/79757 */
+/* { dg-do compile } */
+/* { dg-require-effective-target int128 } */
+/* { dg-options "-fsanitize=undefined" } */
+
+unsigned __int128 x, y;
+
+void
+fn1 (void)
+{
+  int a (z)
+    unsigned long long z = x / y; /* { dg-error "parameter 'z' is initialized" } */
+  {
+  }
+}
+
+void
+fn2 (void)
+{
+  int a (z)
+    unsigned long long z = x >> y; /* { dg-error "parameter 'z' is initialized" } */
+  {
+  }
+}
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr79757-2.c b/gcc/testsuite/gcc.dg/ubsan/pr79757-2.c
new file mode 100644 (file)
index 0000000..b3e1939
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR sanitizer/79757 */
+/* { dg-do compile } */
+/* { dg-require-effective-target int128 } */
+/* { dg-options "-fsanitize=undefined" } */
+
+unsigned __int128 x, y;
+
+void
+fn1 (z)
+  unsigned long long z = x / y; /* { dg-error "parameter 'z' is initialized" } */
+{
+}
+
+void
+fn2 (z)
+  unsigned long long z = x >> y; /* { dg-error "parameter 'z' is initialized" } */
+{
+}
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr79757-3.c b/gcc/testsuite/gcc.dg/ubsan/pr79757-3.c
new file mode 100644 (file)
index 0000000..22fe3de
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR sanitizer/79757 */
+/* { dg-do compile } */
+/* { dg-require-effective-target int128 } */
+/* { dg-options "-fsanitize=undefined" } */
+
+unsigned __int128 x, y;
+
+void
+fn1 (z)
+  __auto_type z = x / y; /* { dg-error "parameter 'z' is initialized" } */
+{
+}
+
+void
+fn2 (z)
+  __auto_type z = x >> y; /* { dg-error "parameter 'z' is initialized" } */
+{
+}
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr79757-4.c b/gcc/testsuite/gcc.dg/ubsan/pr79757-4.c
new file mode 100644 (file)
index 0000000..33b348f
--- /dev/null
@@ -0,0 +1,29 @@
+/* PR sanitizer/79757 */
+/* { dg-do run } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
+/* { dg-options "-fsanitize=undefined" } */
+
+int
+main (void)
+{
+  int
+  div (int n)
+  {
+    int i = 5 / n;
+    return i;
+  }
+
+  int
+  shift (int n)
+  {
+    int i = 5 << n;
+    return i;
+  }
+
+  int j = shift (100);
+  int i = div (0);
+  return 0;
+}
+
+/* { dg-output "shift exponent 100 is too large for \[^\n\r]*-bit type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division by zero" } */
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr79757-5.c b/gcc/testsuite/gcc.dg/ubsan/pr79757-5.c
new file mode 100644 (file)
index 0000000..786d817
--- /dev/null
@@ -0,0 +1,29 @@
+/* PR sanitizer/79757 */
+/* { dg-do run } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
+/* { dg-options "-fsanitize=undefined" } */
+
+int
+main (void)
+{
+  int
+  div (int n)
+  {
+    __auto_type i = 5 / n;
+    return i;
+  }
+
+  int
+  shift (int n)
+  {
+    __auto_type i = 5 << n;
+    return i;
+  }
+
+  int j = shift (100);
+  int i = div (0);
+  return 0;
+}
+
+/* { dg-output "shift exponent 100 is too large for \[^\n\r]*-bit type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*division by zero" } */