testsuite: add testcase for fixed PR107467

Message ID 2a3d484399534a1449ac3a29d6089ed62b839a5a.1729885673.git.sam@gentoo.org
State New
Headers
Series testsuite: add testcase for fixed PR107467 |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed

Commit Message

Sam James Oct. 25, 2024, 7:47 p.m. UTC
  PR107467 ended up being fixed by the fix for PR115110, but let's
add the testcase on top.

gcc/testsuite/ChangeLog:
	PR tree-optimization/107467
	PR middle-end/115110

	* g++.dg/lto/pr107467_0.C: New test.
---
OK?

 gcc/testsuite/g++.dg/lto/pr107467_0.C | 52 +++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/lto/pr107467_0.C
  

Comments

Sam James Oct. 25, 2024, 8:31 p.m. UTC | #1
Sam James <sam@gentoo.org> writes:

> PR107467 ended up being fixed by the fix for PR115110, but let's
> add the testcase on top.
>
> gcc/testsuite/ChangeLog:
> 	PR tree-optimization/107467
> 	PR middle-end/115110
>
> 	* g++.dg/lto/pr107467_0.C: New test.
> ---
> OK?
>
>  gcc/testsuite/g++.dg/lto/pr107467_0.C | 52 +++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/lto/pr107467_0.C
>
> diff --git a/gcc/testsuite/g++.dg/lto/pr107467_0.C b/gcc/testsuite/g++.dg/lto/pr107467_0.C
> new file mode 100644
> index 000000000000..3a2c1c2d7ae1
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/lto/pr107467_0.C
> @@ -0,0 +1,52 @@
> +/* { dg-lto-do run } */
> +/* { dg-lto-options { -O2 -fno-strict-aliasing -flto } } */

This should be {{ }} around the options themselves, fixed locally.

> +
> +template <class T>
> +struct pair
> +{
> +    int first;
> +    T second;
> +};
> +
> +template <typename C>
> +[[gnu::optimize("strict-aliasing")]]
> +bool __attribute__((noinline))
> +compare_pairs(const pair<C> &lhs, const pair<C> &rhs) {
> +  return lhs.first == rhs.first && lhs.second == rhs.second;
> +}
> +
> +template <typename B> struct Combined {
> +  pair<B *> 
> +__attribute__((noinline)) get_const() {
> +    return pair<B *>{123, nullptr};
> +  }
> +[[gnu::optimize("strict-aliasing")]]
> +  bool 
> +__attribute__((noinline)) clashy() {
> +    return compare_pairs(get_const(), get_const());
> +  }
> +};
> +
> +class SomeClass {};
> +class OtherClass {};
> +
> +[[gnu::optimize("strict-aliasing")]]
> +[[gnu::used]]
> +void some_func() {
> +  Combined<SomeClass> myvar;
> +  __builtin_printf("%i\n", myvar.clashy());
> +}
> +
> +[[gnu::optimize("strict-aliasing")]]
> +void other_func() {
> +  Combined<OtherClass> myvar;
> +  int t = myvar.clashy();
> +  if (!t)
> +  __builtin_abort();
> +}
> +
> +[[gnu::optimize("O0")]]
> +int main()
> +{
> +  other_func();
> +}
  
Mike Stump Oct. 28, 2024, 4:05 p.m. UTC | #2
On Oct 25, 2024, at 12:47 PM, Sam James <sam@gentoo.org> wrote:
> 
> PR107467 ended up being fixed by the fix for PR115110, but let's
> add the testcase on top.
> 
> gcc/testsuite/ChangeLog:
> 	PR tree-optimization/107467
> 	PR middle-end/115110
> 
> 	* g++.dg/lto/pr107467_0.C: New test.
> ---
> OK?

Ok.
  
Sam James Oct. 28, 2024, 5:09 p.m. UTC | #3
Mike Stump <mikestump@comcast.net> writes:

> On Oct 25, 2024, at 12:47 PM, Sam James <sam@gentoo.org> wrote:
>> 
>> PR107467 ended up being fixed by the fix for PR115110, but let's
>> add the testcase on top.
>> 
>> gcc/testsuite/ChangeLog:
>> 	PR tree-optimization/107467
>> 	PR middle-end/115110
>> 
>> 	* g++.dg/lto/pr107467_0.C: New test.
>> ---
>> OK?
>
> Ok.

Thanks, pushed.
  

Patch

diff --git a/gcc/testsuite/g++.dg/lto/pr107467_0.C b/gcc/testsuite/g++.dg/lto/pr107467_0.C
new file mode 100644
index 000000000000..3a2c1c2d7ae1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr107467_0.C
@@ -0,0 +1,52 @@ 
+/* { dg-lto-do run } */
+/* { dg-lto-options { -O2 -fno-strict-aliasing -flto } } */
+
+template <class T>
+struct pair
+{
+    int first;
+    T second;
+};
+
+template <typename C>
+[[gnu::optimize("strict-aliasing")]]
+bool __attribute__((noinline))
+compare_pairs(const pair<C> &lhs, const pair<C> &rhs) {
+  return lhs.first == rhs.first && lhs.second == rhs.second;
+}
+
+template <typename B> struct Combined {
+  pair<B *> 
+__attribute__((noinline)) get_const() {
+    return pair<B *>{123, nullptr};
+  }
+[[gnu::optimize("strict-aliasing")]]
+  bool 
+__attribute__((noinline)) clashy() {
+    return compare_pairs(get_const(), get_const());
+  }
+};
+
+class SomeClass {};
+class OtherClass {};
+
+[[gnu::optimize("strict-aliasing")]]
+[[gnu::used]]
+void some_func() {
+  Combined<SomeClass> myvar;
+  __builtin_printf("%i\n", myvar.clashy());
+}
+
+[[gnu::optimize("strict-aliasing")]]
+void other_func() {
+  Combined<OtherClass> myvar;
+  int t = myvar.clashy();
+  if (!t)
+  __builtin_abort();
+}
+
+[[gnu::optimize("O0")]]
+int main()
+{
+  other_func();
+}