From: Martin Sebor <msebor@gmail.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [committed] fix another ICE in MEM_REF formatting (PR 98578)
Date: Thu, 7 Jan 2021 14:29:50 -0700 [thread overview]
Message-ID: <12069778-e6af-6fb9-13d4-a3c555c70a29@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 445 bytes --]
Fixing the ICE in MEM_REF formatting (or the enhancements that
came along with the fix) introduced another, ICE plus a plugin
test failure. I have committed the attached simple patch to
fix both.
Martin
PS There are outstanding bugs to fix/improvements to be made
to the MEM_REF formatting (though hopefully no more ICEs) that
I found while testing the attached fix. I xfailed the tests
and opened the referenced bugs to keep track of them.
[-- Attachment #2: gcc-98578.diff --]
[-- Type: text/x-patch, Size: 8731 bytes --]
commit 178f0afce3611282170de380fcea9db9d6e3ff0c
Author: Martin Sebor <msebor@redhat.com>
Date: Thu Jan 7 14:20:39 2021 -0700
PR middle-end/98578 - ICE warning on uninitialized VLA access
gcc/c-family/ChangeLog:
PR middle-end/98578
* c-pretty-print.c (print_mem_ref): Strip array from access type.
Avoid assuming acces type's size is constant. Correct condition
guarding the printing of a parenthesis.
gcc/testsuite/ChangeLog:
PR middle-end/98578
* gcc.dg/plugin/gil-1.c: Adjust expected output.
* gcc.dg/uninit-pr98578.c: New test.
diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index e963cf53091..87301a2091c 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/gcc/c-family/c-pretty-print.c
@@ -1844,22 +1844,25 @@ print_mem_ref (c_pretty_printer *pp, tree e)
}
}
- const tree access_type = TREE_TYPE (e);
+ tree access_type = TREE_TYPE (e);
+ if (TREE_CODE (access_type) == ARRAY_TYPE)
+ access_type = TREE_TYPE (access_type);
tree arg_type = TREE_TYPE (TREE_TYPE (arg));
if (TREE_CODE (arg_type) == ARRAY_TYPE)
arg_type = TREE_TYPE (arg_type);
if (tree access_size = TYPE_SIZE_UNIT (access_type))
- {
- /* For naturally aligned accesses print the nonzero offset
- in units of the accessed type, in the form of an index.
- For unaligned accesses also print the residual byte offset. */
- offset_int asize = wi::to_offset (access_size);
- offset_int szlg2 = wi::floor_log2 (asize);
-
- elt_idx = byte_off >> szlg2;
- byte_off = byte_off - (elt_idx << szlg2);
- }
+ if (TREE_CODE (access_size) == INTEGER_CST)
+ {
+ /* For naturally aligned accesses print the nonzero offset
+ in units of the accessed type, in the form of an index.
+ For unaligned accesses also print the residual byte offset. */
+ offset_int asize = wi::to_offset (access_size);
+ offset_int szlg2 = wi::floor_log2 (asize);
+
+ elt_idx = byte_off >> szlg2;
+ byte_off = byte_off - (elt_idx << szlg2);
+ }
/* True to include a cast to the accessed type. */
const bool access_cast = VOID_TYPE_P (arg_type)
@@ -1924,9 +1927,9 @@ print_mem_ref (c_pretty_printer *pp, tree e)
}
if (elt_idx != 0)
{
- if (byte_off == 0 && char_cast)
+ if (access_cast || char_cast)
pp_c_right_paren (pp);
- pp_c_right_paren (pp);
+
if (addr)
{
pp_space (pp);
diff --git a/gcc/testsuite/gcc.dg/plugin/gil-1.c b/gcc/testsuite/gcc.dg/plugin/gil-1.c
index 4e8f535ba85..66872f07466 100644
--- a/gcc/testsuite/gcc.dg/plugin/gil-1.c
+++ b/gcc/testsuite/gcc.dg/plugin/gil-1.c
@@ -13,7 +13,7 @@ void test_2 (PyObject *obj)
{
Py_BEGIN_ALLOW_THREADS /* { dg-message "releasing the GIL here" } */
- Py_INCREF (obj); /* { dg-warning "use of PyObject '\\*\\(obj\\)' without the GIL" } */
+ Py_INCREF (obj); /* { dg-warning "use of PyObject '\\*obj' without the GIL" } */
Py_DECREF (obj);
Py_END_ALLOW_THREADS
@@ -60,7 +60,7 @@ void test_5 (PyObject *obj)
static void __attribute__((noinline))
called_by_test_6 (PyObject *obj)
{
- Py_INCREF (obj); /* { dg-warning "use of PyObject '\\*\\(obj\\)' without the GIL" } */
+ Py_INCREF (obj); /* { dg-warning "use of PyObject '\\*obj' without the GIL" } */
Py_DECREF (obj);
}
diff --git a/gcc/testsuite/gcc.dg/uninit-pr98578.c b/gcc/testsuite/gcc.dg/uninit-pr98578.c
new file mode 100644
index 00000000000..98d611757ab
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-pr98578.c
@@ -0,0 +1,110 @@
+/* PR middle-end/98578 - ICE warning on uninitialized VLA access
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+void* malloc (__SIZE_TYPE__);
+
+void T (int, ...);
+
+void vla_n (int n, int i)
+{
+ int a1[n];
+
+ /* a1[I] should be formatted as as a1[I] (or, for I == 0, perhaps
+ as *a1), but definitely not as *a1[I]. This is a bug in VLA
+ formatting. */
+ T (a1[0]); // { dg-warning "'a1\\\[0]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "'\\*a1\\\[0]' is used uninitialized" "spurious star" { target *-*-* } .-1 }
+ T (a1[1]); // { dg-warning "a1\\\[1]' is used uninitialized" }
+ T (a1[i]); // { dg-warning "a1\\\[i]' is used uninitialized" }
+}
+
+void vla_n_2 (int n, int i)
+{
+ int a2[n][2];
+
+ T (a2[0][0]); // { dg-warning "a2\\\[0]\\\[0]' is used uninitialized" }
+ T (a2[2][1]); // { dg-warning "a2\\\[2]\\\[1]' is used uninitialized" }
+ T (a2[3][i]); // { dg-warning "a2\\\[3]\\\[i]' is used uninitialized" }
+ T (a2[i][0]); // { dg-warning "a2\\\[i]\\\[0]' is used uninitialized" }
+ T (a2[i][i]); // { dg-warning "a2\\\[i]\\\[i]' is used uninitialized" }
+}
+
+
+void vla_3_n (int n, int i)
+{
+ int a2[3][n];
+
+ T (a2[0][0]); // { dg-warning "a2\\\[0]\\\[0]' is used uninitialized" }
+ T (a2[1][2]); // { dg-warning "a2\\\[1]\\\[2]' is used uninitialized" }
+ T (a2[2][i]); // { dg-warning "a2\\\[2]\\\[i]' is used uninitialized" }
+ T (a2[i][3]); // { dg-warning "a2\\\[i]\\\[3]' is used uninitialized" }
+ T (a2[i][i]); // { dg-warning "a2\\\[i]\\\[i]' is used uninitialized" }
+}
+
+
+void vla_n_n (int n, int i)
+{
+ int a2[n][n];
+
+ T (a2[0][0]); // { dg-warning "a2\\\[0]\\\[0]' is used uninitialized" }
+ T (a2[4][5]); // { dg-warning "a2\\\[4]\\\[5]' is used uninitialized" }
+ T (a2[6][i]); // { dg-warning "a2\\\[6]\\\[i]' is used uninitialized" }
+ T (a2[i][7]); // { dg-warning "a2\\\[i]\\\[7]' is used uninitialized" }
+ T (a2[i][i]); // { dg-warning "a2\\\[i]\\\[i]' is used uninitialized" }
+}
+
+
+void char_ptr_n (int n, int i)
+{
+ char *p = malloc (n);
+
+ T (p[0]); // { dg-warning "'\\\*p' is used uninitialized" }
+ T (p[1]); // { dg-warning "'p\\\[1]' is used uninitialized" }
+ T (p[i]); // { dg-warning "'p\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "is used uninitialized" "POINTER_PLUS_EXPR" { target *-*-* } .-1 }
+}
+
+
+void int_ptr_n (int n, int i)
+{
+ int *p = malloc (n);
+
+ T (p[0]); // { dg-warning "'\\\*p' is used uninitialized" }
+ T (p[1]); // { dg-warning "'p\\\[1]' is used uninitialized" }
+ T (p[i]); // { dg-warning "'p\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "is used uninitialized" "POINTER_PLUS_EXPR" { target *-*-* } .-1 }
+}
+
+
+void int_arr_ptr_n (int n, int i)
+{
+ int (*p)[n] = malloc (n);
+
+ T ((*p)[0]); // { dg-warning "\\(\\*p\\)\\\[0]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[0]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[1]); // { dg-warning "\\(\\*p\\)\\\[1]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[1]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[i]); // { dg-warning "\\(\\*p\\)\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+}
+
+
+void int_arr_ptr_n_n (int n, int i)
+{
+ int (*p)[n][n] = malloc (n);
+
+ T ((*p)[0][0]); // { dg-warning "\\(\\*p\\)\\\[0]\\\[0]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[0]\\\[0]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[1][2]); // { dg-warning "\\(\\*p\\)\\\[1]\\\[2]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[1]\\\[2]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[0][i]); // { dg-warning "\\(\\*p\\)\\\[0]\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[0]\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[3][i]); // { dg-warning "\\(\\*p\\)\\\[3]\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[3]\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[i][i]); // { dg-warning "\\(\\*p\\)\\\[i]\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[i]\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+
+ T ((*p)[i][i + 1]); // { dg-warning "\\(\\*p\\)\\\[i]\\\[i \\+ 1]' is used uninitialized" "pr98588" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[i]\\\[<unknown>]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+}
next reply other threads:[~2021-01-07 21:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-07 21:29 Martin Sebor [this message]
2021-01-07 21:37 ` Jakub Jelinek
2021-01-07 23:24 ` Martin Sebor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=12069778-e6af-6fb9-13d4-a3c555c70a29@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).