aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-03-09 16:58:17 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-03-09 16:58:17 +0000
commit3661842863344b18d736c0f9fd02983ebceaed52 (patch)
tree3e36b6d392adffb0a06df6a6ae4f007457281828 /gcc
parent01e5af5a2f5fa4813e359bc03d42e98d091c7a2d (diff)
downloadgcc-3661842863344b18d736c0f9fd02983ebceaed52.zip
gcc-3661842863344b18d736c0f9fd02983ebceaed52.tar.gz
gcc-3661842863344b18d736c0f9fd02983ebceaed52.tar.bz2
re PR sanitizer/79757 (ICE in declare_vars, at gimplify.c:634)
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-parser.c12
-rw-r--r--gcc/testsuite/ChangeLog9
-rw-r--r--gcc/testsuite/gcc.dg/ubsan/pr79757-1.c24
-rw-r--r--gcc/testsuite/gcc.dg/ubsan/pr79757-2.c18
-rw-r--r--gcc/testsuite/gcc.dg/ubsan/pr79757-3.c18
-rw-r--r--gcc/testsuite/gcc.dg/ubsan/pr79757-4.c29
-rw-r--r--gcc/testsuite/gcc.dg/ubsan/pr79757-5.c29
8 files changed, 145 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index e6da629..c461c6d 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -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
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 8330e65..1394f18 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -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)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 48fba48..3da89cd 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..ca074bc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ubsan/pr79757-1.c
@@ -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
index 0000000..b3e1939
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ubsan/pr79757-2.c
@@ -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
index 0000000..22fe3de
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ubsan/pr79757-3.c
@@ -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
index 0000000..33b348f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ubsan/pr79757-4.c
@@ -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
index 0000000..786d817
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ubsan/pr79757-5.c
@@ -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" } */