From: Sam James Date: Mon, 21 Oct 2024 11:11:42 +0000 (+0100) Subject: testsuite: add testcase for fixed PR107467 X-Git-Tag: basepoints/gcc-16~4830 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e09ae37dbe0a10f48490214f50ff733cc92280a;p=thirdparty%2Fgcc.git testsuite: add testcase for fixed PR107467 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. --- 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..a871aca82459 --- /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 +struct pair +{ + int first; + T second; +}; + +template +[[gnu::optimize("strict-aliasing")]] +bool __attribute__((noinline)) +compare_pairs(const pair &lhs, const pair &rhs) { + return lhs.first == rhs.first && lhs.second == rhs.second; +} + +template struct Combined { + pair +__attribute__((noinline)) get_const() { + return pair{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 myvar; + __builtin_printf("%i\n", myvar.clashy()); +} + +[[gnu::optimize("strict-aliasing")]] +void other_func() { + Combined myvar; + int t = myvar.clashy(); + if (!t) + __builtin_abort(); +} + +[[gnu::optimize("O0")]] +int main() +{ + other_func(); +}