toolchain: gcc: backport patch for gcc 13 fixing access path analysis
[openwrt/staging/dangole.git] / toolchain / gcc / patches-13.x / 001-rtl-optimization-109585-alias-analysis-typo.patch
1 From bb406a6aea336966681927a27f54ee89c4fd4ea1 Mon Sep 17 00:00:00 2001
2 From: Richard Biener <rguenther@suse.de>
3 Date: Mon, 24 Apr 2023 13:31:07 +0200
4 Subject: [PATCH] rtl-optimization/109585 - alias analysis typo
5
6 When r10-514-gc6b84edb6110dd2b4fb improved access path analysis
7 it introduced a typo that triggers when there's an access to a
8 trailing array in the first access path leading to false
9 disambiguation.
10
11 PR rtl-optimization/109585
12 * tree-ssa-alias.cc (aliasing_component_refs_p): Fix typo.
13
14 * gcc.dg/torture/pr109585.c: New testcase.
15
16 (cherry picked from commit 6d4bd27a60447c7505cb4783e675e98a191a8904)
17 ---
18 gcc/testsuite/gcc.dg/torture/pr109585.c | 33 +++++++++++++++++++++++++
19 gcc/tree-ssa-alias.cc | 2 +-
20 2 files changed, 34 insertions(+), 1 deletion(-)
21 create mode 100644 gcc/testsuite/gcc.dg/torture/pr109585.c
22
23 --- /dev/null
24 +++ b/gcc/testsuite/gcc.dg/torture/pr109585.c
25 @@ -0,0 +1,33 @@
26 +/* { dg-do run } */
27 +
28 +#include <stdlib.h>
29 +
30 +struct P {
31 + long v;
32 + struct P *n;
33 +};
34 +
35 +struct F {
36 + long x;
37 + struct P fam[];
38 +};
39 +
40 +int __attribute__((noipa))
41 +f(struct F *f, int i)
42 +{
43 + struct P *p = f->fam;
44 + asm("" : "+r"(f): "r"(p));
45 + p->v = 0;
46 + p->n = 0;
47 + return f->fam->n != 0;
48 +}
49 +
50 +int
51 +main()
52 +{
53 + struct F *m = malloc (sizeof (long) + 2 * sizeof (struct P));
54 + m->fam[0].n = &m->fam[1];
55 + if (f (m, 0))
56 + abort ();
57 + return 0;
58 +}
59 --- a/gcc/tree-ssa-alias.cc
60 +++ b/gcc/tree-ssa-alias.cc
61 @@ -1330,7 +1330,7 @@ aliasing_component_refs_p (tree ref1,
62 /* If we didn't find a common base, try the other way around. */
63 if (cmp_outer <= 0
64 || (end_struct_ref1
65 - && compare_type_sizes (TREE_TYPE (end_struct_ref1), type1) <= 0))
66 + && compare_type_sizes (TREE_TYPE (end_struct_ref1), type2) <= 0))
67 {
68 int res = aliasing_component_refs_walk (ref2, type2, base2,
69 offset2, max_size2,