From: Richard Biener Date: Thu, 6 Apr 2017 13:56:35 +0000 (+0000) Subject: re PR tree-optimization/80334 (Segfault when taking address of copy of unaligned... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=09b63f67a11096fb9aa163f9936909bded2e690b;p=gcc.git re PR tree-optimization/80334 (Segfault when taking address of copy of unaligned struct) 2017-04-06 Richard Biener PR tree-optimization/80334 * tree-ssa-loop-ivopts.c (rewrite_use_address): Properly preserve alignment of accesses. * g++.dg/torture/pr80334.C: New testcase. From-SVN: r246731 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 020d9f8707d..d4f0c937d44 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-04-06 Richard Biener + + PR tree-optimization/80334 + * tree-ssa-loop-ivopts.c (rewrite_use_address): Properly + preserve alignment of accesses. + 2017-04-06 Richard Biener PR tree-optimization/80262 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 32f5507a332..e5b327469e8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-06 Richard Biener + + PR tree-optimization/80334 + * g++.dg/torture/pr80334.C: New testcase. + 2017-04-06 Martin Liska PR sanitizer/80166 diff --git a/gcc/testsuite/g++.dg/torture/pr80334.C b/gcc/testsuite/g++.dg/torture/pr80334.C new file mode 100644 index 00000000000..de50c463535 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr80334.C @@ -0,0 +1,18 @@ +// { dg-do run } + +struct A { alignas(16) char c; }; +struct B { A unpacked; char d; } __attribute__((packed)); + +char x; + +int +main() +{ + alignas(16) B b[3]; + for (int i = 0; i < 3; i++) b[i].unpacked.c = 'a' + i; + for (int i = 0; i < 3; i++) + { + auto a = new A(b[i].unpacked); + x = a->c; + } +} diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 72e3ff98a3e..d5bd0362f25 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -7396,7 +7396,11 @@ rewrite_use_address (struct ivopts_data *data, base_hint = var_at_stmt (data->current_loop, cand, use->stmt); iv = var_at_stmt (data->current_loop, cand, use->stmt); - ref = create_mem_ref (&bsi, TREE_TYPE (*use->op_p), &aff, + tree type = TREE_TYPE (*use->op_p); + unsigned int align = get_object_alignment (*use->op_p); + if (align != TYPE_ALIGN (type)) + type = build_aligned_type (type, align); + ref = create_mem_ref (&bsi, type, &aff, reference_alias_ptr_type (*use->op_p), iv, base_hint, data->speed); copy_ref_info (ref, *use->op_p);