From 7b909872f15f48482a23e41fe8093cb1f4425c74 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 16 Feb 2015 18:15:19 +0000 Subject: [PATCH] re PR tree-optimization/65077 (memcpy generates incorrect code with floating point numbers and -O1) 2015-02-16 Richard Biener PR tree-optimization/65077 * tree-ssa-structalias.c (get_constraint_for_1): Handle IMAGPART_EXPR, REALPART_EXPR and BIT_FIELD_REF. (find_func_aliases): Allow float values to carry pointers again. * gcc.dg/torture/pr65077.c: New testcase. From-SVN: r220741 --- gcc/ChangeLog | 7 +++ gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/gcc.dg/torture/pr65077.c | 70 ++++++++++++++++++++++++++ gcc/tree-ssa-structalias.c | 9 ++-- 4 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr65077.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a4994293eb2..061e0341c50 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2015-02-16 Richard Biener + + PR tree-optimization/65077 + * tree-ssa-structalias.c (get_constraint_for_1): Handle + IMAGPART_EXPR, REALPART_EXPR and BIT_FIELD_REF. + (find_func_aliases): Allow float values to carry pointers again. + 2015-02-16 James Greenhalgh * doc/install.texi (Specific): Reorder targets list to put diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index abc735816a2..8af42fa4458 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-02-16 Richard Biener + + PR tree-optimization/65077 + * gcc.dg/torture/pr65077.c: New testcase. + 2015-02-16 Alex Velenko * gcc.target/aarch64/atomic-op-consume.c (scan-assember-times): diff --git a/gcc/testsuite/gcc.dg/torture/pr65077.c b/gcc/testsuite/gcc.dg/torture/pr65077.c new file mode 100644 index 00000000000..f57356c60bb --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr65077.c @@ -0,0 +1,70 @@ +/* { dg-do run } */ + +extern void abort (void); +extern void *memcpy(void *, const void *, __SIZE_TYPE__); + +typedef struct { + void *v1; + void *v2; + void *v3; + union { + void *f1; + void *f2; + } u; +} S; + + +S *getS(); +void verify_p(void *p); +double *getP(void *p); + +void memcpy_bug() +{ + S *s; + double *p = getP(0); + + if (p) { + int intSptr[sizeof(S*)/sizeof(int)]; + unsigned i = 0; + for (i = 0; i < sizeof(intSptr)/sizeof(*intSptr); ++i) { + intSptr[i] = (int) p[i]; + } + memcpy(&s, intSptr, sizeof(intSptr)); + (s)->u.f1 = p; + verify_p((s)->u.f1); + } else { + s = getS(); + } + verify_p(s->u.f1); +} + +double P[4]; + +double *getP(void *p) { + union u { + void *p; + int i[2]; + } u; + u.p = P; + P[0] = u.i[0]; + P[1] = u.i[1]; + return P; +} + +S *getS() +{ + return 0; +} + +void verify_p(void *p) +{ + if (p != P) + abort (); +} + +int main(int argc, char *argv[]) +{ + memcpy_bug(); + return 0; +} + diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index 4c43b75730d..fd0f5359dd7 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -3492,6 +3492,9 @@ get_constraint_for_1 (tree t, vec *results, bool address_p, case ARRAY_REF: case ARRAY_RANGE_REF: case COMPONENT_REF: + case IMAGPART_EXPR: + case REALPART_EXPR: + case BIT_FIELD_REF: get_constraint_for_component_ref (t, results, address_p, lhs_p); return; case VIEW_CONVERT_EXPR: @@ -4712,11 +4715,7 @@ find_func_aliases (struct function *fn, gimple origt) get_constraint_for (lhsop, &lhsc); - if (FLOAT_TYPE_P (TREE_TYPE (lhsop))) - /* If the operation produces a floating point result then - assume the value is not produced to transfer a pointer. */ - ; - else if (code == POINTER_PLUS_EXPR) + if (code == POINTER_PLUS_EXPR) get_constraint_for_ptr_offset (gimple_assign_rhs1 (t), gimple_assign_rhs2 (t), &rhsc); else if (code == BIT_AND_EXPR -- 2.30.2