]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/111807 - ICE in verify_sra_access_forest
authorRichard Biener <rguenther@suse.de>
Mon, 16 Oct 2023 10:54:28 +0000 (12:54 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 17 Oct 2023 06:23:33 +0000 (08:23 +0200)
The following addresses build_reconstructed_reference failing to
build references with a different offset than the models and thus
the caller conditional being off.  This manifests when attempting
to build a ref with offset 160 from the model BIT_FIELD_REF <l_4827[9], 8, 0>
onto the same base l_4827 but the models offset being 288.  This
cannot work for any kind of ref I can think of, not just with
BIT_FIELD_REFs.

PR tree-optimization/111807
* tree-sra.cc (build_ref_for_model): Only call
build_reconstructed_reference when the offsets are the same.

* gcc.dg/torture/pr111807.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr111807.c [new file with mode: 0644]
gcc/tree-sra.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr111807.c b/gcc/testsuite/gcc.dg/torture/pr111807.c
new file mode 100644 (file)
index 0000000..09fbdcf
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+static struct A {
+  int x : 4;
+} a;
+static int b;
+int main()
+{
+  struct A t[2];
+  t[0] = b ? t[1] : a;
+  return (b ? t[1].x : 0) && 1;
+}
index 24d0c20da6ae03a84b6340acd966f7d0a83e23e1..f8dff8b27d76737a65fffc86b284bff131da6563 100644 (file)
@@ -1751,7 +1751,7 @@ build_ref_for_model (location_t loc, tree base, HOST_WIDE_INT offset,
          && !TREE_THIS_VOLATILE (base)
          && (TYPE_ADDR_SPACE (TREE_TYPE (base))
              == TYPE_ADDR_SPACE (TREE_TYPE (model->expr)))
-         && offset <= model->offset
+         && offset == model->offset
          /* build_reconstructed_reference can still fail if we have already
             massaged BASE because of another type incompatibility.  */
          && (res = build_reconstructed_reference (loc, base, model)))