From 2aa8aa18a66f7677a7f7c7e987e2435750bdc982 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 28 Aug 2017 11:42:23 +0000 Subject: [PATCH] re PR tree-optimization/81977 (Issue with inline memcpy with optimizations enabled) 2017-08-28 Richard Biener PR tree-optimization/81977 * tree-ssa-sccvn.c (vn_reference_lookup_3): Fix look through memcpy. * g++.dg/torture/pr81977.C: New testcase. From-SVN: r251378 --- gcc/ChangeLog | 6 ++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/torture/pr81977.C | 55 ++++++++++++++++++++++++++++++++++ gcc/tree-ssa-sccvn.c | 2 +- 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr81977.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c79a0e8..90063a6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-08-28 Richard Biener + + PR tree-optimization/81977 + * tree-ssa-sccvn.c (vn_reference_lookup_3): Fix look through + memcpy. + 2017-08-28 Alexander Monakov PR target/80640 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a3687c4..2b5204e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-08-28 Richard Biener + + PR tree-optimization/81977 + * g++.dg/torture/pr81977.C: New testcase. + 2017-08-28 Alexander Monakov PR target/80640 diff --git a/gcc/testsuite/g++.dg/torture/pr81977.C b/gcc/testsuite/g++.dg/torture/pr81977.C new file mode 100644 index 0000000..a8c8ba0 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr81977.C @@ -0,0 +1,55 @@ +/* { dg-do run } */ +/* { dg-require-effective-target int32plus } */ + +#include + +typedef struct +{ + uint16_t x ; + uint16_t y ; + uint64_t z ; +} __attribute__((packed, aligned(1))) TestMsgType; + +struct Payload +{ + uint16_t header_info[2]; + TestMsgType _pref; + void Pack(uint8_t *buffer) + { + __builtin_memcpy(buffer, &_pref, sizeof(_pref)); + } + void UnPack(uint8_t *buffer) + { + __builtin_memcpy(&_pref, buffer, sizeof(_pref)); + } +}; + + +struct Msg +{ + Payload _payload; + void Pack(uint8_t *buffer) + { + _payload.Pack(buffer); + } + + void UnPack(uint8_t *buffer) + { + _payload.UnPack(buffer); + } +}; + +int main() +{ + uint8_t * buffer = new uint8_t [30]; + Msg msg; + Msg msg1; + msg._payload._pref.x = 0xabcd; + msg._payload._pref.y = 0xa; + msg._payload._pref.z = 0x0001020304051617; + msg.Pack(&buffer[0]); + msg1.UnPack(&buffer[0]); + if (msg1._payload._pref.x != 0xabcd) + __builtin_abort (); + delete [] buffer; +} diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 19db44a..472ab0b 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -2334,7 +2334,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_, memset (&op, 0, sizeof (op)); op.type = vr->type; op.opcode = MEM_REF; - op.op0 = build_int_cst (ptr_type_node, at - rhs_offset); + op.op0 = build_int_cst (ptr_type_node, at - lhs_offset + rhs_offset); op.off = at - lhs_offset + rhs_offset; vr->operands[0] = op; op.type = TREE_TYPE (rhs); -- 2.7.4