aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDaniel Berlin <dberlin@dberlin.org>2005-10-06 19:38:00 +0000
committerDaniel Berlin <dberlin@gcc.gnu.org>2005-10-06 19:38:00 +0000
commit6c11790df95634c3911e7990770c6dac72eb8961 (patch)
tree35204d303db0ac31ddd4180b2a397aabddc209d8 /gcc
parent5597a350f4143b458bbc4c9a558d5bac43c141c5 (diff)
downloadgcc-6c11790df95634c3911e7990770c6dac72eb8961.zip
gcc-6c11790df95634c3911e7990770c6dac72eb8961.tar.gz
gcc-6c11790df95634c3911e7990770c6dac72eb8961.tar.bz2
re PR c++/22488 (C++ frontend generates RECORD_TYPEs with overlapping FIELD_DECLs)
2005-10-06 Daniel Berlin <dberlin@dberlin.org> Fix PR tree-optimization/22488 * tree-ssa-structalias.c (check_for_overlaps): New function. (create_variable_info_for): Use it. From-SVN: r105052
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/tree-ssa/pr22488.C33
-rw-r--r--gcc/tree-ssa-structalias.c32
3 files changed, 69 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7f7da32..16aeadb 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2005-10-06 Daniel Berlin <dberlin@dberlin.org>
+
+ Fix PR tree-optimization/22488
+ * tree-ssa-structalias.c (check_for_overlaps): New function.
+ (create_variable_info_for): Use it.
+
2005-10-06 Richard Henderson <rth@redhat.com>
PR debug/24070
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr22488.C b/gcc/testsuite/g++.dg/tree-ssa/pr22488.C
new file mode 100644
index 0000000..9063b06
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr22488.C
@@ -0,0 +1,33 @@
+// PR tree-optimization/22488
+// This testcase is really a C++ FE bug in represnting virtual inheritance
+// It gives the appearance to the middle end that the fields exist twice
+// which resulted in a very confused structure analyzer
+// { dg-do compile }
+// { dg-options "-O" }
+struct X
+{
+ int i0, i1;
+ char c;
+};
+
+struct A
+{
+ int i;
+ char c0, c1;
+
+ virtual ~A();
+};
+
+struct B : virtual A {};
+
+struct C : B
+{
+ X x;
+
+ void bar(X y) { x = y; }
+};
+
+void foo()
+{
+ C().bar(X());
+}
diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 890006a..f6ac3ca 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -3020,6 +3020,26 @@ make_constraint_to_anything (varinfo_t vi)
process_constraint (new_constraint (lhs, rhs));
}
+
+/* Return true if FIELDSTACK contains fields that overlap.
+ FIELDSTACK is assumed to be sorted by offset. */
+
+static bool
+check_for_overlaps (VEC (fieldoff_s,heap) *fieldstack)
+{
+ fieldoff_s *fo = NULL;
+ unsigned int i;
+ unsigned int lastoffset = ~0;
+
+ for (i = 0; VEC_iterate (fieldoff_s, fieldstack, i, fo); i++)
+ {
+ if (fo->offset == lastoffset)
+ return true;
+ lastoffset = fo->offset;
+ }
+ return false;
+}
+
/* Create a varinfo structure for NAME and DECL, and add it to VARMAP.
This will also create any varinfo structures necessary for fields
of DECL. */
@@ -3104,8 +3124,16 @@ create_variable_info_for (tree decl, const char *name)
which will make notokay = true. In that case, we are going to return
without creating varinfos for the fields anyway, so sorting them is a
waste to boot. */
- if (!notokay)
- sort_fieldstack (fieldstack);
+ if (!notokay)
+ {
+ sort_fieldstack (fieldstack);
+ /* Due to some C++ FE issues, like PR 22488, we might end up
+ what appear to be overlapping fields even though they,
+ in reality, do not overlap. Until the C++ FE is fixed,
+ we will simply disable field-sensitivity for these cases. */
+ notokay = check_for_overlaps (fieldstack);
+ }
+
if (VEC_length (fieldoff_s, fieldstack) != 0)
fo = VEC_index (fieldoff_s, fieldstack, 0);