c++: Add unsequenced C++ testcase
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
Commit Message
Hi!
This is the testcase I wrote originally and which on top of the
https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659154.html
patch didn't behave the way I wanted (no warning and no optimizations of
[[unsequenced]] function templates which don't have pointer/reference
arguments.
Posting this separately, because it depends on the above mentioned
patch as well as the PR116175
https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659157.html
patch.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2024-08-01 Jakub Jelinek <jakub@redhat.com>
* g++.dg/ext/attr-unsequenced-1.C: New test.
Jakub
Comments
On 8/1/24 2:43 PM, Jakub Jelinek wrote:
> Hi!
>
> This is the testcase I wrote originally and which on top of the
> https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659154.html
> patch didn't behave the way I wanted (no warning and no optimizations of
> [[unsequenced]] function templates which don't have pointer/reference
> arguments.
> Posting this separately, because it depends on the above mentioned
> patch as well as the PR116175
> https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659157.html
> patch.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 2024-08-01 Jakub Jelinek <jakub@redhat.com>
>
> * g++.dg/ext/attr-unsequenced-1.C: New test.
>
> --- gcc/testsuite/g++.dg/ext/attr-unsequenced-1.C.jj 2024-08-01 16:57:52.309618653 +0200
> +++ gcc/testsuite/g++.dg/ext/attr-unsequenced-1.C 2024-08-01 16:53:36.711859089 +0200
> @@ -0,0 +1,53 @@
> +// { dg-do compile { target c++11 } }
> +// { dg-options "-O2 -fdump-tree-optimized" } */
> +// { dg-final { scan-tree-dump-times " bar<int> \\\(1, 2, 3\\\);" 1 "optimized" } }
> +// { dg-final { scan-tree-dump-times " bar<int> \\\(4, 5, 6\\\);" 1 "optimized" } }
> +
> +template <typename T, typename U>
> +[[gnu::noipa]] U
> +foo (T x, T y, T z) [[gnu::unsequenced]]
> +{
> + *x = 1;
> + *y = 2;
> + *z = 3;
> +}
> +
> +template <typename T>
> +[[gnu::noipa]] T
> +bar (T x, T y, T z) [[gnu::unsequenced]]
> +{
> + return x + y + z;
> +}
> +
> +int
> +baz () [[gnu::unsequenced]]
> +{
> + int x, y, z;
> + foo <int *, void> (&x, &y, &z);
> + return x;
> +}
> +
> +int
> +qux () [[gnu::unsequenced]]
> +{
> + int a = bar (1, 2, 3);
> + int b = bar (1, 2, 3);
> + int c = bar (1, 2, 3);
> + int d = bar (4, 5, 6);
> + int e = bar (4, 5, 6);
> + int f = bar (4, 5, 6);
> + return a + b + c + d + e + f;
> +}
> +
> +template <typename T, typename U>
> +[[gnu::noipa]] U
> +corge (T x, T y, T z) [[gnu::unsequenced]] // { dg-warning "'unsequenced' attribute on function type without pointer arguments returning 'void'" }
> +{
> + x += y + z;
> +}
> +
> +void
> +freddy ()
> +{
> + corge <int, void> (1, 2, 3);
> +}
>
> Jakub
>
@@ -0,0 +1,53 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2 -fdump-tree-optimized" } */
+// { dg-final { scan-tree-dump-times " bar<int> \\\(1, 2, 3\\\);" 1 "optimized" } }
+// { dg-final { scan-tree-dump-times " bar<int> \\\(4, 5, 6\\\);" 1 "optimized" } }
+
+template <typename T, typename U>
+[[gnu::noipa]] U
+foo (T x, T y, T z) [[gnu::unsequenced]]
+{
+ *x = 1;
+ *y = 2;
+ *z = 3;
+}
+
+template <typename T>
+[[gnu::noipa]] T
+bar (T x, T y, T z) [[gnu::unsequenced]]
+{
+ return x + y + z;
+}
+
+int
+baz () [[gnu::unsequenced]]
+{
+ int x, y, z;
+ foo <int *, void> (&x, &y, &z);
+ return x;
+}
+
+int
+qux () [[gnu::unsequenced]]
+{
+ int a = bar (1, 2, 3);
+ int b = bar (1, 2, 3);
+ int c = bar (1, 2, 3);
+ int d = bar (4, 5, 6);
+ int e = bar (4, 5, 6);
+ int f = bar (4, 5, 6);
+ return a + b + c + d + e + f;
+}
+
+template <typename T, typename U>
+[[gnu::noipa]] U
+corge (T x, T y, T z) [[gnu::unsequenced]] // { dg-warning "'unsequenced' attribute on function type without pointer arguments returning 'void'" }
+{
+ x += y + z;
+}
+
+void
+freddy ()
+{
+ corge <int, void> (1, 2, 3);
+}