* [PATCH] Fix PR81977
@ 2017-08-28 12:11 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2017-08-28 12:11 UTC (permalink / raw)
To: gcc-patches
The following fixes a failure to account for lhs_offset (or rather
to consistently use the same offset in op0 and off).
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
Richard.
2017-08-28 Richard Biener <rguenther@suse.de>
PR tree-optimization/81977
* tree-ssa-sccvn.c (vn_reference_lookup_3): Fix look through
memcpy.
* g++.dg/torture/pr81977.C: New testcase.
Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c (revision 251377)
+++ gcc/tree-ssa-sccvn.c (working copy)
@@ -2334,7 +2334,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree
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);
Index: gcc/testsuite/g++.dg/torture/pr81977.C
===================================================================
--- gcc/testsuite/g++.dg/torture/pr81977.C (nonexistent)
+++ gcc/testsuite/g++.dg/torture/pr81977.C (working copy)
@@ -0,0 +1,55 @@
+/* { dg-do run } */
+/* { dg-require-effective-target int32plus } */
+
+#include <cstdint>
+
+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;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-08-28 11:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-28 12:11 [PATCH] Fix PR81977 Richard Biener
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).