001-rtl-optimization-109585-alias-analysis-typo.patch 1.8 KB

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