summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0288-2011-05-20-Richard-Guenther-rguenther-suse.de.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0288-2011-05-20-Richard-Guenther-rguenther-suse.de.patch')
-rw-r--r--meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0288-2011-05-20-Richard-Guenther-rguenther-suse.de.patch117
1 files changed, 117 insertions, 0 deletions
diff --git a/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0288-2011-05-20-Richard-Guenther-rguenther-suse.de.patch b/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0288-2011-05-20-Richard-Guenther-rguenther-suse.de.patch
new file mode 100644
index 0000000000..ff2cb06641
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0288-2011-05-20-Richard-Guenther-rguenther-suse.de.patch
@@ -0,0 +1,117 @@
1From 24f5b59f5c9418d39087b36dd0d275f71ac4dca5 Mon Sep 17 00:00:00 2001
2From: rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
3Date: Fri, 20 May 2011 15:08:56 +0000
4Subject: [PATCH] 2011-05-20 Richard Guenther <rguenther@suse.de>
5
6 PR tree-optimization/49079
7 * tree-dfa.c (get_ref_base_and_extent): Handle view-converting
8 MEM_REFs correctly for the trailing array access detection.
9 Special case constants the same way as decls for overall size
10 constraining.
11
12 * gcc.dg/torture/pr49079.c: New testcase.
13
14
15git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@173955 138bc75d-0d04-0410-961f-82ee72b054a4
16
17index 0efa0eb..dcb39c1 100644
18new file mode 100644
19index 0000000..1b53d3c
20--- /dev/null
21+++ b/gcc/testsuite/gcc.dg/torture/pr49079.c
22@@ -0,0 +1,31 @@
23+/* { dg-do run } */
24+
25+extern void abort (void);
26+
27+struct Ustr
28+{
29+ unsigned char data[1];
30+};
31+
32+static unsigned int
33+ustr_xi__embed_val_get(const unsigned char *data)
34+{
35+ return (unsigned int)data[0];
36+}
37+
38+int __attribute__((noinline)) zero(void) { return 0; }
39+
40+static unsigned int
41+ustr_len(const struct Ustr *s1)
42+{
43+ return ustr_xi__embed_val_get(s1->data + 1 + zero());
44+}
45+
46+int
47+main()
48+{
49+ if (ustr_len (((struct Ustr *) "\x01" "\x0002" "s2")) != 2)
50+ abort ();
51+
52+ return 0;
53+}
54diff --git a/gcc/tree-dfa.c b/gcc/tree-dfa.c
55index 6490c5e..2dacd44 100644
56--- a/gcc/tree-dfa.c
57+++ b/gcc/tree-dfa.c
58@@ -709,6 +709,7 @@ get_ref_base_and_extent (tree exp, HOST_WIDE_INT *poffset,
59 tree size_tree = NULL_TREE;
60 HOST_WIDE_INT bit_offset = 0;
61 bool seen_variable_array_ref = false;
62+ tree base_type;
63
64 /* First get the final access size from just the outermost expression. */
65 if (TREE_CODE (exp) == COMPONENT_REF)
66@@ -739,6 +740,8 @@ get_ref_base_and_extent (tree exp, HOST_WIDE_INT *poffset,
67 and find the ultimate containing object. */
68 while (1)
69 {
70+ base_type = TREE_TYPE (exp);
71+
72 switch (TREE_CODE (exp))
73 {
74 case BIT_FIELD_REF:
75@@ -926,9 +929,16 @@ get_ref_base_and_extent (tree exp, HOST_WIDE_INT *poffset,
76 the array. The simplest way to conservatively deal with this
77 is to punt in the case that offset + maxsize reaches the
78 base type boundary. This needs to include possible trailing padding
79- that is there for alignment purposes.
80+ that is there for alignment purposes. */
81+
82+ if (seen_variable_array_ref
83+ && maxsize != -1
84+ && (!host_integerp (TYPE_SIZE (base_type), 1)
85+ || (bit_offset + maxsize
86+ == (signed) TREE_INT_CST_LOW (TYPE_SIZE (base_type)))))
87+ maxsize = -1;
88
89- That is of course only true if the base object is not a decl. */
90+ /* In case of a decl or constant base object we can do better. */
91
92 if (DECL_P (exp))
93 {
94@@ -938,12 +948,14 @@ get_ref_base_and_extent (tree exp, HOST_WIDE_INT *poffset,
95 && host_integerp (DECL_SIZE (exp), 1))
96 maxsize = TREE_INT_CST_LOW (DECL_SIZE (exp)) - bit_offset;
97 }
98- else if (seen_variable_array_ref
99- && maxsize != -1
100- && (!host_integerp (TYPE_SIZE (TREE_TYPE (exp)), 1)
101- || (bit_offset + maxsize
102- == (signed) TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp))))))
103- maxsize = -1;
104+ else if (CONSTANT_CLASS_P (exp))
105+ {
106+ /* If maxsize is unknown adjust it according to the size of the
107+ base type constant. */
108+ if (maxsize == -1
109+ && host_integerp (TYPE_SIZE (TREE_TYPE (exp)), 1))
110+ maxsize = TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp))) - bit_offset;
111+ }
112
113 /* ??? Due to negative offsets in ARRAY_REF we can end up with
114 negative bit_offset here. We might want to store a zero offset
115--
1161.7.0.4
117