From: Martin Sebor <msebor@gmail.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: [PATCH] handle MEM_REF with void* arguments (PR c++/95768)
Date: Mon, 22 Jun 2020 11:25:51 -0600 [thread overview]
Message-ID: <ff44a764-a42b-c78a-0b30-8aace0cb9939@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
The attached fix parallels the one for the equivalent C bug 95580
where the pretty printers don't correctly handle MEM_REF arguments
with type void* or other pointers to an incomplete type.
The incorrect handling was exposed by the recent change to
-Wuninitialized which includes such expressions in diagnostics.
Martin
[-- Attachment #2: gcc-95768.diff --]
[-- Type: text/x-patch, Size: 2863 bytes --]
PR c++/95768 - pretty-printer ICE on -Wuninitialized with allocated storage
gcc/cp/ChangeLog:
PR c++/95768
* error.c (dump_expr): Handle sizeless operand types such as void*.
gcc/testsuite/ChangeLog:
PR c++/95768
* g++.dg/pr95768.C: New test.
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 0d6375e5e14..3a7254fdce1 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2374,32 +2374,37 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
break;
case MEM_REF:
- if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
- && integer_zerop (TREE_OPERAND (t, 1)))
- dump_expr (pp, TREE_OPERAND (TREE_OPERAND (t, 0), 0), flags);
- else
- {
- pp_cxx_star (pp);
- if (!integer_zerop (TREE_OPERAND (t, 1)))
- {
- pp_cxx_left_paren (pp);
- if (!integer_onep (TYPE_SIZE_UNIT
- (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))))))
- {
- pp_cxx_left_paren (pp);
- dump_type (pp, ptr_type_node, flags);
- pp_cxx_right_paren (pp);
- }
- }
- dump_expr (pp, TREE_OPERAND (t, 0), flags);
- if (!integer_zerop (TREE_OPERAND (t, 1)))
- {
- pp_cxx_ws_string (pp, "+");
- dump_expr (pp, fold_convert (ssizetype, TREE_OPERAND (t, 1)),
- flags);
- pp_cxx_right_paren (pp);
- }
- }
+ {
+ tree arg = TREE_OPERAND (t, 0);
+ tree offset = TREE_OPERAND (t, 1);
+
+ if (TREE_CODE (arg) == ADDR_EXPR
+ && integer_zerop (offset))
+ dump_expr (pp, TREE_OPERAND (arg, 0), flags);
+ else
+ {
+ pp_cxx_star (pp);
+ if (!integer_zerop (offset))
+ {
+ pp_cxx_left_paren (pp);
+ tree argtype = TREE_TYPE (arg);
+ if (tree size = TYPE_SIZE_UNIT (TREE_TYPE (argtype)))
+ if (!integer_onep (size))
+ {
+ pp_cxx_left_paren (pp);
+ dump_type (pp, ptr_type_node, flags);
+ pp_cxx_right_paren (pp);
+ }
+ }
+ dump_expr (pp, arg, flags);
+ if (!integer_zerop (offset))
+ {
+ pp_cxx_ws_string (pp, "+");
+ dump_expr (pp, fold_convert (ssizetype, offset), flags);
+ pp_cxx_right_paren (pp);
+ }
+ }
+ }
break;
case NEGATE_EXPR:
diff --git a/gcc/testsuite/g++.dg/pr95768.C b/gcc/testsuite/g++.dg/pr95768.C
new file mode 100644
index 00000000000..babfcb49bf8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr95768.C
@@ -0,0 +1,32 @@
+/* PR c++/95768 - pretty-printer ICE on -Wuninitialized with allocated storage
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+extern "C" void *malloc (__SIZE_TYPE__);
+
+struct f
+{
+ int i;
+ static int e (int);
+ void operator= (int) { e (i); }
+};
+
+struct m {
+ int i;
+ f length;
+};
+
+struct n {
+ m *o() { return (m *)this; }
+};
+
+struct p {
+ n *header;
+ p () {
+ header = (n *)malloc (0);
+ m b = *header->o(); // { dg-warning "-Wuninitialized" }
+ b.length = 0;
+ }
+};
+
+void detach2() { p(); }
next reply other threads:[~2020-06-22 17:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-22 17:25 Martin Sebor [this message]
2020-06-22 18:55 ` Jason Merrill
2020-06-22 22:22 ` Martin Sebor
2020-06-23 7:12 ` Richard Biener
2020-06-28 23:07 ` Martin Sebor
2020-06-29 7:19 ` Richard Biener
2020-07-09 15:50 ` Martin Sebor
2021-01-02 22:22 ` [PATCH v3] " Martin Sebor
2021-01-05 23:17 ` Jeff Law
2021-01-07 8:26 ` Jakub Jelinek
2021-01-07 21:36 ` 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=ff44a764-a42b-c78a-0b30-8aace0cb9939@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/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).