lto: Handle RAW_DATA_CST in compare_tree_sccs_1 [PR117201]

Message ID ZxtaY1h78E0uBJha@tucnak
State New
Headers
Series lto: Handle RAW_DATA_CST in compare_tree_sccs_1 [PR117201] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_check--master-arm fail Patch failed to apply

Commit Message

Jakub Jelinek Oct. 25, 2024, 8:44 a.m. UTC
  Hi!

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.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk?

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.


	Jakub
  

Comments

Richard Biener Oct. 25, 2024, 9:56 a.m. UTC | #1
On Fri, 25 Oct 2024, Jakub Jelinek wrote:

> Hi!
> 
> 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.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
> ok for trunk?

OK.

Thanks,
Richard.

> 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.jj	2024-06-07 12:17:09.000000000 +0200
> +++ gcc/lto/lto-common.cc	2024-10-24 15:55:13.713178421 +0200
> @@ -1335,6 +1335,12 @@ compare_tree_sccs_1 (tree t1, tree t2, t
>  		   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);
> --- gcc/testsuite/gcc.dg/lto/pr117201_0.c.jj	2024-10-24 15:56:04.769462522 +0200
> +++ gcc/testsuite/gcc.dg/lto/pr117201_0.c	2024-10-24 15:57:12.579511715 +0200
> @@ -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 ();
> +}
> --- gcc/testsuite/gcc.dg/lto/pr117288_0.c.jj	2024-10-25 10:37:37.693612115 +0200
> +++ gcc/testsuite/gcc.dg/lto/pr117288_0.c	2024-10-25 10:32:29.530992602 +0200
> @@ -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);
> +}
> 
> 	Jakub
> 
>
  

Patch

--- gcc/lto/lto-common.cc.jj	2024-06-07 12:17:09.000000000 +0200
+++ gcc/lto/lto-common.cc	2024-10-24 15:55:13.713178421 +0200
@@ -1335,6 +1335,12 @@  compare_tree_sccs_1 (tree t1, tree t2, t
 		   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);
--- gcc/testsuite/gcc.dg/lto/pr117201_0.c.jj	2024-10-24 15:56:04.769462522 +0200
+++ gcc/testsuite/gcc.dg/lto/pr117201_0.c	2024-10-24 15:57:12.579511715 +0200
@@ -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 ();
+}
--- gcc/testsuite/gcc.dg/lto/pr117288_0.c.jj	2024-10-25 10:37:37.693612115 +0200
+++ gcc/testsuite/gcc.dg/lto/pr117288_0.c	2024-10-25 10:32:29.530992602 +0200
@@ -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);
+}