public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, PR 57748] Check for out of bounds access
@ 2013-09-06  7:03 Bernd Edlinger
  2013-09-06  7:31 ` Richard Biener
  2013-09-06  9:29 ` [PATCH, PR 57748] Check for out of bounds access Eric Botcazou
  0 siblings, 2 replies; 105+ messages in thread
From: Bernd Edlinger @ 2013-09-06  7:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Biener

[-- Attachment #1: Type: text/plain, Size: 361 bytes --]

Hi,

this patch fixes the ICE and wrong code issues from PR57748. It contains two test cases.
One for the ICE and one for the wrong code. Both test cases fail for all gcc versions,
and are fixed with this patch.

Bootstrapped and tested on x86_64-linux without any problems.

OK for trunk and the 4.8 / 4.7 branch?

Regards
Bernd Edlinger 		 	   		  

[-- Attachment #2: changelog-pr57748.txt --]
[-- Type: text/plain, Size: 252 bytes --]

2013-09-06  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR middle-end/57748
	* expr.c (expand_assignment): Check for out of bounds
	access to structures.

testsuite:

	* gcc.dg/torture/pr57748-1.c: New test.
	* gcc.dg/torture/pr57748-2.c: New test.


[-- Attachment #3: patch-pr57748.diff --]
[-- Type: application/octet-stream, Size: 2938 bytes --]

--- gcc/expr.c	2013-08-06 00:09:45.000000000 +0200
+++ gcc/expr.c	2013-09-03 00:46:28.000000000 +0200
@@ -4707,6 +4707,9 @@ expand_assignment (tree to, tree from, b
       mode = TYPE_MODE (TREE_TYPE (tem));
       if (TREE_CODE (tem) == MEM_REF
 	  && mode != BLKmode
+	  && offset == 0
+	  && bitpos + bitsize <= GET_MODE_BITSIZE (mode)
+	  && !volatilep
 	  && ((align = get_object_alignment (tem))
 	      < GET_MODE_ALIGNMENT (mode))
 	  && ((icode = optab_handler (movmisalign_optab, mode))
@@ -4773,6 +4776,8 @@ expand_assignment (tree to, tree from, b
 	  if (MEM_P (to_rtx)
 	      && GET_MODE (to_rtx) == BLKmode
 	      && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
+	      && bitregion_start == 0
+	      && bitregion_end == 0
 	      && bitsize > 0
 	      && (bitpos % bitsize) == 0
 	      && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
--- gcc/testsuite/gcc.dg/torture/pr57748-1.c	1970-01-01 01:00:00.000000000 +0100
+++ gcc/testsuite/gcc.dg/torture/pr57748-1.c	2013-09-06 08:38:03.718686940 +0200
@@ -0,0 +1,49 @@
+/* PR middle-end/57748 */
+/* { dg-do run } */
+/* ICE in expand_assignment:
+   misalignp == true, !MEM_P (to_rtx), offset != 0, 
+   => gcc_assert (TREE_CODE (offset) == INTEGER_CST) */
+
+#include <stdlib.h>
+
+extern void abort (void);
+
+typedef long long V
+  __attribute__ ((vector_size (2 * sizeof (long long)), may_alias));
+
+typedef struct S { V a; V b[0]; } P __attribute__((aligned (1)));
+
+struct __attribute__((packed)) T { char c; P s; };
+
+void __attribute__((noinline, noclone))
+check (struct T *t)
+{
+  if (t->s.b[0][0] != 3 || t->s.b[0][1] != 4)
+    abort ();
+}
+
+int __attribute__((noinline, noclone))
+get_i (void)
+{
+  return 0;
+}
+
+void __attribute__((noinline, noclone))
+foo (P *p)
+{
+  V a = { 3, 4 };
+  int i = get_i ();
+  p->b[i] = a;
+}
+
+int
+main ()
+{
+  struct T *t = (struct T *) calloc (128, 1);
+
+  foo (&t->s);
+  check (t);
+
+  free (t);
+  return 0;
+}
--- gcc/testsuite/gcc.dg/torture/pr57748-2.c	1970-01-01 01:00:00.000000000 +0100
+++ gcc/testsuite/gcc.dg/torture/pr57748-2.c	2013-09-06 08:38:03.718686940 +0200
@@ -0,0 +1,43 @@
+/* PR middle-end/57748 */
+/* { dg-do run } */
+/* wrong code in expand_assignment:
+   misalignp == true, !MEM_P (to_rtx),
+   offset == 0, bitpos >= GET_MODE_PRECISION,
+   => result = NULL */
+
+#include <stdlib.h>
+
+extern void abort (void);
+
+typedef long long V
+  __attribute__ ((vector_size (2 * sizeof (long long)), may_alias));
+
+typedef struct S { V a; V b[0]; } P __attribute__((aligned (1)));
+
+struct __attribute__((packed)) T { char c; P s; };
+
+void __attribute__((noinline, noclone))
+check (struct T *t)
+{
+  if (t->s.b[0][0] != 3 || t->s.b[0][1] != 4)
+    abort ();
+}
+
+void __attribute__((noinline, noclone))
+foo (P *p)
+{
+  V a = { 3, 4 };
+  p->b[0] = a;
+}
+
+int
+main ()
+{
+  struct T *t = (struct T *) calloc (128, 1);
+
+  foo (&t->s);
+  check (t);
+
+  free (t);
+  return 0;
+}

^ permalink raw reply	[flat|nested] 105+ messages in thread

end of thread, other threads:[~2014-05-14  9:06 UTC | newest]

Thread overview: 105+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-06  7:03 [PATCH, PR 57748] Check for out of bounds access Bernd Edlinger
2013-09-06  7:31 ` Richard Biener
     [not found]   ` <DUB122-W323D4AAAEA1AFA890BF243E43C0@phx.gbl>
     [not found]     ` <CAFiYyc13wC0jmZ4xELAiL5L5Sbh0yauZWViP2hTdR+H4s0iPSw@mail.gmail.com>
     [not found]       ` <DUB122-W4D571A91831593BA22438E43C0@phx.gbl>
2013-09-06  9:19         ` Richard Biener
2013-09-06  9:30           ` Bernd Edlinger
2013-09-10 21:33           ` Martin Jambor
2013-09-11 14:42             ` Bernd Edlinger
2013-09-11 14:47               ` Richard Biener
2013-09-12 21:07                 ` Bernd Edlinger
2013-09-13  9:37                   ` Eric Botcazou
2013-09-13  9:48                     ` Bernd Edlinger
2013-09-15 19:08                 ` Bernd Edlinger
2013-09-17  0:05                   ` Martin Jambor
2013-09-17 10:32                     ` Bernd Edlinger
2013-10-22 14:08                     ` Bernd Edlinger
2013-10-23 16:02                       ` Richard Biener
2013-10-24  0:09                         ` Bernd Edlinger
2013-10-24  8:44                         ` Eric Botcazou
2013-10-24 10:06                           ` Richard Biener
2013-10-24 10:22                             ` Bernd Edlinger
2013-10-25 10:40                             ` Eric Botcazou
2013-11-06 15:08                       ` [PATCH, PR 57748] Check for out of bounds access, Part 3 Bernd Edlinger
2013-12-03 13:27                         ` [PE-POST] Adjust Bit-region in expand_assignment Bernd Edlinger
2013-12-04  5:55                           ` Jeff Law
2013-12-04  7:50                             ` Bernd Edlinger
2013-12-06  4:13                               ` Jeff Law
2013-12-06  8:03                                 ` Bernd Edlinger
2013-12-06  9:49                                   ` Richard Biener
2013-09-17 11:07                   ` [PATCH, PR 57748] Check for out of bounds access Richard Biener
2013-09-17 11:41                     ` Richard Biener
2013-09-17 12:48                       ` Bernd Edlinger
2013-09-24 11:40                         ` Richard Biener
2013-09-24 11:56                           ` Bernd Edlinger
2013-09-24  6:34                       ` [PATCH, PR 57748] Check for out of bounds access, Part 2 Bernd Edlinger
2013-09-24 10:31                         ` Richard Biener
2013-09-24 14:46                           ` Eric Botcazou
2013-09-24 18:51                           ` Martin Jambor
2013-09-25  9:51                             ` Richard Biener
2013-09-25 14:56                               ` Martin Jambor
2013-09-26  9:34                                 ` Bernd Edlinger
2013-09-26 11:18                                   ` Eric Botcazou
2013-09-26 12:42                                     ` Bernd Edlinger
2013-09-27  8:45                                       ` Eric Botcazou
2013-10-03  0:37                                         ` Bernd Edlinger
2013-10-08  8:02                                           ` Eric Botcazou
2013-10-08  9:22                                             ` Bernd Edlinger
2013-10-08 21:04                                               ` Eric Botcazou
2013-10-08 23:03                                                 ` Bernd Edlinger
2013-10-11 17:27                                                   ` Eric Botcazou
2013-10-13  8:22                                                     ` Bernd Edlinger
2013-10-13 12:29                                                       ` Eric Botcazou
2013-10-13 12:30                                                         ` Bernd Edlinger
2013-10-13 14:06                                                           ` Eric Botcazou
2013-10-22 11:02                                                   ` Bernd Edlinger
2013-10-23 16:14                                                     ` Richard Biener
2013-10-23 17:25                                                       ` Martin Jambor
2013-10-23 18:05                                                         ` Eric Botcazou
2013-10-24  8:20                                                         ` Bernd Edlinger
2013-10-24  9:16                                                           ` Eric Botcazou
2013-10-24 10:00                                                             ` Bernd Edlinger
2013-10-24 10:16                                                               ` Eric Botcazou
2013-10-24 10:50                                                             ` Richard Biener
2013-10-24 13:09                                                               ` Bernd Edlinger
2013-10-24 13:16                                                                 ` Richard Biener
2013-10-24 13:38                                                                   ` Bernd Edlinger
2013-10-25  7:05                                                                   ` Bernd Edlinger
2013-10-25  9:29                                                                     ` Richard Biener
2013-10-25 10:40                                                                       ` Bernd Edlinger
2013-10-25 11:10                                                                         ` Richard Biener
2013-10-25 14:01                                                                           ` Martin Jambor
2013-10-27 20:21                                                                           ` [PATCH] Remove "keep_aligning" from get_inner_reference Bernd Edlinger
2013-11-26 12:37                                                                             ` Richard Biener
2013-11-27 11:28                                                                             ` Eric Botcazou
2013-11-27 12:24                                                                               ` Bernd Edlinger
2013-11-27 12:33                                                                                 ` Eric Botcazou
2013-11-27 13:30                                                                               ` Richard Biener
2013-11-27 15:10                                                                                 ` Bernd Edlinger
2013-11-27 16:25                                                                                 ` Eric Botcazou
2013-11-27 16:33                                                                                   ` Richard Biener
2013-11-27 16:43                                                                                     ` Eric Botcazou
2014-04-22  7:55                                                                                 ` Bernd Edlinger
2014-04-22  8:11                                                                                   ` Eric Botcazou
2014-04-22  8:33                                                                                     ` Bernd Edlinger
2014-04-22  9:36                                                                                       ` Eric Botcazou
2014-05-02  6:18                                                                                         ` Jeff Law
2014-05-05  8:00                                                                                           ` Richard Biener
2014-05-05 20:25                                                                                             ` Mike Stump
2014-05-14  7:30                                                                                             ` Eric Botcazou
2014-05-14  9:06                                                                                               ` Bernd Edlinger
2013-11-07 13:23                                                                           ` [PATCH, PR 57748] Check for out of bounds access, Part 2 Bernd Edlinger
2013-11-07 13:23                                                                             ` Bernd Edlinger
2013-11-19 15:05                                                                               ` Bernd Edlinger
2013-11-27 16:22                                                                                 ` [PING] " Bernd Edlinger
2013-11-27 17:09                                                                                   ` Richard Biener
2013-11-27 22:30                                                                                   ` Jeff Law
2013-11-28 12:36                                                                                     ` Bernd Edlinger
2013-12-03  6:00                                                                                       ` Jeff Law
2013-10-24 13:20                                                                 ` Jakub Jelinek
2013-10-24 13:42                                                                   ` Richard Biener
2013-10-24 11:14                                                           ` Richard Biener
2013-10-24 13:13                                                             ` Richard Biener
2013-10-23 17:45                                                       ` Eric Botcazou
2013-09-25 13:22                             ` Bernd Edlinger
2013-09-06  9:29 ` [PATCH, PR 57748] Check for out of bounds access Eric Botcazou
2013-09-06  9:30   ` Jakub Jelinek
2013-09-06 10:30     ` Bernd Edlinger

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).