]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: add testcase for fixed PR107467
authorSam James <sam@gentoo.org>
Mon, 21 Oct 2024 11:11:42 +0000 (12:11 +0100)
committerSam James <sam@gentoo.org>
Mon, 28 Oct 2024 17:05:24 +0000 (17:05 +0000)
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.

gcc/testsuite/g++.dg/lto/pr107467_0.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/lto/pr107467_0.C b/gcc/testsuite/g++.dg/lto/pr107467_0.C
new file mode 100644 (file)
index 0000000..a871aca
--- /dev/null
@@ -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();
+}