public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix PR67271
Date: Wed, 16 Sep 2015 14:24:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.11.1509161623130.24931@zhemvz.fhfr.qr> (raw)


Bootstrapped / tested on x86_64-unknown-linux-gnu, applied.

Richard.

2015-09-16  Richard Biener  <rguenther@suse.de>

	PR middle-end/67271
	* fold-const.c (native_encode_expr): Bail out on bogus offsets.

	* gcc.dg/pr67271.c: New testcase.

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	(revision 227779)
+++ gcc/fold-const.c	(working copy)
@@ -7106,6 +7127,10 @@ native_encode_string (const_tree expr, u
 int
 native_encode_expr (const_tree expr, unsigned char *ptr, int len, int off)
 {
+  /* We don't support starting at negative offset and -1 is special.  */
+  if (off < -1)
+    return 0;
+
   switch (TREE_CODE (expr))
     {
     case INTEGER_CST:
Index: gcc/testsuite/gcc.dg/pr67271.c
===================================================================
--- gcc/testsuite/gcc.dg/pr67271.c	(revision 0)
+++ gcc/testsuite/gcc.dg/pr67271.c	(working copy)
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+extern long int labs (long int j);
+int
+main ()
+{
+  long *a = (long *)"empty";
+  int i = 1441516387;
+  a[i] = labs (a[i]);
+  return 0;
+}

                 reply	other threads:[~2015-09-16 14:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=alpine.LSU.2.11.1509161623130.24931@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --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).