]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
lto: Handle RAW_DATA_CST in compare_tree_sccs_1 [PR117201]
authorJakub Jelinek <jakub@redhat.com>
Fri, 25 Oct 2024 12:05:37 +0000 (14:05 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 25 Oct 2024 12:05:37 +0000 (14:05 +0200)
I've missed I need to add RAW_DATA_CST support in compare_tree_sccs_1,
because without that it considers all RAW_DATA_CSTs to be equivalent,
regardless of their length or content.

2024-10-24  Jakub Jelinek  <jakub@redhat.com>

PR lto/117201
PR lto/117288
* lto-common.cc (compare_tree_sccs_1): Handle RAW_DATA_CST.

* gcc.dg/lto/pr117201_0.c: New test.
* gcc.dg/lto/pr117288_0.c: New test.

gcc/lto/lto-common.cc
gcc/testsuite/gcc.dg/lto/pr117201_0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/lto/pr117288_0.c [new file with mode: 0644]

index 77607751db520892f5b3d4f62b6a32a21d97ac5d..cc14cd7100f1a425ebb609ba606046969dd38ca9 100644 (file)
@@ -1336,6 +1336,12 @@ compare_tree_sccs_1 (tree t1, tree t2, tree **map)
                   TREE_STRING_LENGTH (t1)) != 0)
       return false;
 
+  if (code == RAW_DATA_CST)
+    if (RAW_DATA_LENGTH (t1) != RAW_DATA_LENGTH (t2)
+       || memcmp (RAW_DATA_POINTER (t1), RAW_DATA_POINTER (t2),
+                  RAW_DATA_LENGTH (t1)) != 0)
+      return false;
+
   if (code == OMP_CLAUSE)
     {
       compare_values (OMP_CLAUSE_CODE);
diff --git a/gcc/testsuite/gcc.dg/lto/pr117201_0.c b/gcc/testsuite/gcc.dg/lto/pr117201_0.c
new file mode 100644 (file)
index 0000000..e4bfce6
--- /dev/null
@@ -0,0 +1,26 @@
+/* PR lto/117201 */
+/* { dg-lto-do run } */
+/* { dg-lto-options { "-O0 -flto" } } */
+
+unsigned char a = 193;
+unsigned char *b = &a;
+
+void
+foo (void)
+{
+  unsigned char c[] = { 0, 2, 1, 1, 2, 1, 2, 2, 6, 2, 1, 1, 1, 1, 2, 2, 0,
+                       2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2,
+                       1, 1, 2, 1, 2, 2, 1, 1, 2, 4, 8, 8, 3, 3, 1, 1, 5,
+                       4, 1, 1, 1, 0, 5, 5, 9, 4, 8, 8, 7, 0, 1, 1 };
+}
+
+int
+main ()
+{
+  unsigned char c[] = { 193, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 5, 2, 3, 1, 0,
+                       1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 4,
+                       2, 2, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
+                       1, 1, 0, 5, 3, 3, 1, 0, 1, 0, 0, 1, 0, 1, 0 };
+  if (b[0] != c[0])
+    __builtin_abort ();
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr117288_0.c b/gcc/testsuite/gcc.dg/lto/pr117288_0.c
new file mode 100644 (file)
index 0000000..05179aa
--- /dev/null
@@ -0,0 +1,76 @@
+/* PR lto/117288 */
+/* { dg-lto-do link } */
+/* { dg-lto-options { "-O0 -flto" } } */
+
+__attribute__((noipa)) static void
+foo (const void *x)
+{
+  (void) x;
+}
+
+static void
+bar (void)
+{
+  unsigned char a[81] = {
+    0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x01, 0xfa, 0x01, 0x00, 0x01,
+    0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+    0xee, 0xfe, 0xfd, 0xc0, 0xca, 0xb5, 0x6f, 0x3d,
+    0x23, 0xcc, 0x53, 0x9a, 0x67, 0x17, 0x70, 0xd3,
+    0xfb, 0x23, 0x16, 0x9e, 0x4e, 0xd6, 0x7e, 0x29,
+    0xab, 0xfa, 0x4c, 0xa5, 0x84, 0x95, 0xc3, 0xdb,
+    0x21, 0x9a, 0x52, 0x00, 0x00, 0x00, 0x36, 0x13,
+    0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
+    0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00,
+    0x9e,
+  };
+  foo (&a);
+}
+
+static void
+baz (void)
+{
+  const struct S
+  {
+    unsigned char a[32];
+    int b;
+    unsigned char c[32];
+    int d;
+    unsigned char e[32];
+    int f;
+    unsigned char g[80];
+    int h;
+    unsigned char i[80];
+    int j;
+  } s = {
+    { 0x00, }, 16,
+    { 0x4f, }, 16,
+    { 0x00 }, 0,
+    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
+      0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
+      0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+      0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
+      0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
+      0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
+      0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
+      0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }, 80,
+    { 0xe9, }, 80,
+  };
+
+  foo (s.g);
+}
+
+__attribute__((noipa)) static void
+qux (const void (*x) (void))
+{
+  (void) x;
+}
+
+int
+main ()
+{
+  qux (&baz);
+  qux (&bar);
+}