From: Martin Sebor <msebor@gmail.com>
To: Gcc Patch List <gcc-patches@gcc.gnu.org>,
Jason Merrill <jason@redhat.com>
Subject: [PATCH] have chkp skip flexible member arrays (PR #79986)
Date: Mon, 20 Mar 2017 23:04:00 -0000 [thread overview]
Message-ID: <4c6d8cdd-46f8-216d-56cb-07a74284f69a@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 715 bytes --]
Attached is a minimal patch to avoid an ICE in CHKP upon
encountering one form of an initializer for a flexible array
member, specifically the empty string:
int f ()
{
struct B { int n; char a[]; };
return ((struct B){ 1, "" }).a[0];
}
Although GCC accepts (and doesn't ICE on) non-empty initializers
for flexible array members, such as
(struct B){ 1, "123" }
it generates wrong code for them. This could either be fixed by
emitting correct code, or it could be handled by rejecting all
initializers for non-static objects with such members. Both
approaches seem risky to me at this stage and so I think it's
safest to hold off on implementing either until after the release.
Martin
[-- Attachment #2: gcc-79986.diff --]
[-- Type: text/x-patch, Size: 1272 bytes --]
PR c++/79986 - [CHKP] ICE in fold_convert_loc with a flexible array
gcc/ChangeLog:
PR c++/79986
* tree-chkp.c (chkp_process_stmt): Avoid assuming size is non-null.
gcc/testsuite/ChangeLog:
PR c++/79986
* g++.dg/pr79986.C: New test.
diff --git a/gcc/testsuite/g++.dg/pr79986.C b/gcc/testsuite/g++.dg/pr79986.C
new file mode 100644
index 0000000..d179cf6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr79986.C
@@ -0,0 +1,10 @@
+/* PR c++/79986 - [CHKP] ICE in fold_convert_loc with a flexible array
+ { dg-do compile { target { { i?86-*-* x86_64-*-* } && { ! x32 } } } }
+ { dg-options "-fcheck-pointer-bounds -mmpx" } */
+
+int f (int i)
+{
+ struct A { int n; char a[]; };
+
+ return ((struct A){ 1, "" }).a[i]; // { dg-error "invalid use of array" }
+}
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index b1ff218..780d18f 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -4092,6 +4092,10 @@ chkp_process_stmt (gimple_stmt_iterator *iter, tree node,
expression to compute it. */
if (!addr_last)
{
+ /* C++ flexible array members have a null size. */
+ if (!size)
+ return;
+
addr_last = fold_build_pointer_plus_loc (loc, addr_first, size);
addr_last = fold_build_pointer_plus_hwi_loc (loc, addr_last, -1);
}
next reply other threads:[~2017-03-20 23:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-20 23:04 Martin Sebor [this message]
2017-03-20 23:51 ` Jason Merrill
2017-03-20 23:58 ` Martin Sebor
2017-03-21 4:27 ` Jason Merrill
2017-03-21 15:08 ` Martin Sebor
2017-03-21 15:15 ` Jakub Jelinek
2017-03-21 15:17 ` Jeff Law
2017-03-21 15:46 ` Marek Polacek
2017-03-21 23:56 ` Martin Sebor
2017-03-21 19:33 ` Jason Merrill
2017-03-29 23:29 ` Martin Sebor
2017-04-07 16:50 ` Jason Merrill
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=4c6d8cdd-46f8-216d-56cb-07a74284f69a@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).