[v4,4/5] Add tests for C/C++ musttail attributes
Checks
Commit Message
Mostly adopted from the existing C musttail plugin tests.
gcc/testsuite/ChangeLog:
* c-c++-common/musttail1.c: New test.
* c-c++-common/musttail2.c: New test.
* c-c++-common/musttail3.c: New test.
* c-c++-common/musttail4.c: New test.
* c-c++-common/musttail5.c: New test.
---
gcc/testsuite/c-c++-common/musttail1.c | 15 ++++++++++++
gcc/testsuite/c-c++-common/musttail2.c | 34 ++++++++++++++++++++++++++
gcc/testsuite/c-c++-common/musttail3.c | 29 ++++++++++++++++++++++
gcc/testsuite/c-c++-common/musttail4.c | 17 +++++++++++++
gcc/testsuite/c-c++-common/musttail5.c | 25 +++++++++++++++++++
5 files changed, 120 insertions(+)
create mode 100644 gcc/testsuite/c-c++-common/musttail1.c
create mode 100644 gcc/testsuite/c-c++-common/musttail2.c
create mode 100644 gcc/testsuite/c-c++-common/musttail3.c
create mode 100644 gcc/testsuite/c-c++-common/musttail4.c
create mode 100644 gcc/testsuite/c-c++-common/musttail5.c
Comments
On Fri, 2 Feb 2024 at 14:44, Andi Kleen <ak@linux.intel.com> wrote:
>
> Mostly adopted from the existing C musttail plugin tests.
>
> gcc/testsuite/ChangeLog:
>
> * c-c++-common/musttail1.c: New test.
> * c-c++-common/musttail2.c: New test.
> * c-c++-common/musttail3.c: New test.
> * c-c++-common/musttail4.c: New test.
> * c-c++-common/musttail5.c: New test.
> ---
> gcc/testsuite/c-c++-common/musttail1.c | 15 ++++++++++++
> gcc/testsuite/c-c++-common/musttail2.c | 34 ++++++++++++++++++++++++++
> gcc/testsuite/c-c++-common/musttail3.c | 29 ++++++++++++++++++++++
> gcc/testsuite/c-c++-common/musttail4.c | 17 +++++++++++++
> gcc/testsuite/c-c++-common/musttail5.c | 25 +++++++++++++++++++
> 5 files changed, 120 insertions(+)
> create mode 100644 gcc/testsuite/c-c++-common/musttail1.c
> create mode 100644 gcc/testsuite/c-c++-common/musttail2.c
> create mode 100644 gcc/testsuite/c-c++-common/musttail3.c
> create mode 100644 gcc/testsuite/c-c++-common/musttail4.c
> create mode 100644 gcc/testsuite/c-c++-common/musttail5.c
>
> diff --git a/gcc/testsuite/c-c++-common/musttail1.c b/gcc/testsuite/c-c++-common/musttail1.c
> new file mode 100644
> index 000000000000..ac92f9f74616
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/musttail1.c
> @@ -0,0 +1,15 @@
> +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
> +/* { dg-options "-O2" } */
> +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
> +
> +int __attribute__((noinline,noclone,noipa))
> +callee (int i)
Hi Andy,
Sorry, I wasn't clear about this in previous patch -- noipa will
subsume other ipa attributes,
so there's no need to have noinline, noclone along with noipa.
int __attribute__((noipa)) callee(int i) should be sufficient for
disabling IPA optimizations involving callee.
Thanks,
Prathamesh
> +{
> + return i * i;
> +}
> +
> +int __attribute__((noinline,noclone,noipa))
> +caller (int i)
> +{
> + [[gnu::musttail]] return callee (i + 1);
> +}
> diff --git a/gcc/testsuite/c-c++-common/musttail2.c b/gcc/testsuite/c-c++-common/musttail2.c
> new file mode 100644
> index 000000000000..058329b69cc2
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/musttail2.c
> @@ -0,0 +1,34 @@
> +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
> +
> +struct box { char field[256]; int i; };
> +
> +int __attribute__((noinline,noclone,noipa))
> +test_2_callee (int i, struct box b)
> +{
> + if (b.field[0])
> + return 5;
> + return i * i;
> +}
> +
> +int __attribute__((noinline,noclone,noipa))
> +test_2_caller (int i)
> +{
> + struct box b;
> + [[gnu::musttail]] return test_2_callee (i + 1, b); /* { dg-error "cannot tail-call: " } */
> +}
> +
> +extern void setjmp (void);
> +void
> +test_3 (void)
> +{
> + [[gnu::musttail]] return setjmp (); /* { dg-error "cannot tail-call: " } */
> +}
> +
> +typedef void (fn_ptr_t) (void);
> +volatile fn_ptr_t fn_ptr;
> +
> +void
> +test_5 (void)
> +{
> + [[gnu::musttail]] return fn_ptr (); /* { dg-error "cannot tail-call: " } */
> +}
> diff --git a/gcc/testsuite/c-c++-common/musttail3.c b/gcc/testsuite/c-c++-common/musttail3.c
> new file mode 100644
> index 000000000000..ea9589c59ef2
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/musttail3.c
> @@ -0,0 +1,29 @@
> +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
> +
> +extern int foo2 (int x, ...);
> +
> +struct str
> +{
> + int a, b;
> +};
> +
> +struct str
> +cstruct (int x)
> +{
> + if (x < 10)
> + [[clang::musttail]] return cstruct (x + 1);
> + return ((struct str){ x, 0 });
> +}
> +
> +int
> +foo (int x)
> +{
> + if (x < 10)
> + [[clang::musttail]] return foo2 (x, 29);
> + if (x < 100)
> + {
> + int k = foo (x + 1);
> + [[clang::musttail]] return k; /* { dg-error "cannot tail-call: " } */
> + }
> + return x;
> +}
> diff --git a/gcc/testsuite/c-c++-common/musttail4.c b/gcc/testsuite/c-c++-common/musttail4.c
> new file mode 100644
> index 000000000000..23f4b5e1cd68
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/musttail4.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
> +
> +struct box { char field[64]; int i; };
> +
> +struct box __attribute__((noinline,noclone,noipa))
> +returns_struct (int i)
> +{
> + struct box b;
> + b.i = i * i;
> + return b;
> +}
> +
> +int __attribute__((noinline,noclone))
> +test_1 (int i)
> +{
> + [[gnu::musttail]] return returns_struct (i * 5).i; /* { dg-error "cannot tail-call: " } */
> +}
> diff --git a/gcc/testsuite/c-c++-common/musttail5.c b/gcc/testsuite/c-c++-common/musttail5.c
> new file mode 100644
> index 000000000000..71f4de40fc6d
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/musttail5.c
> @@ -0,0 +1,25 @@
> +/* { dg-do compile } */
> +/* { dg-options "-std=c23" { target c } } */
> +/* { dg-options "-std=gnu++11" { target c++ } } */
> +
> +[[musttail]] int j; /* { dg-warning "attribute" } */
> +__attribute__((musttail)) int k; /* { dg-warning "attribute" } */
> +
> +void foo(void)
> +{
> + [[gnu::musttail]] j++; /* { dg-warning "attribute" } */
> + [[gnu::musttail]] if (k > 0) /* { dg-warning "attribute" } */
> + [[gnu::musttail]] k++; /* { dg-warning "attribute" } */
> +}
> +
> +int foo2(int p)
> +{
> + [[gnu::musttail(1)]] return foo2(p + 1); /* { dg-error "attribute" } */
> +}
> +
> +int i;
> +
> +void foo3(void)
> +{
> + [[musttail]] i++; /* { dg-warning "attribute" } */
> +}
> --
> 2.43.0
>
> Sorry, I wasn't clear about this in previous patch -- noipa will
> subsume other ipa attributes,
> so there's no need to have noinline, noclone along with noipa.
> int __attribute__((noipa)) callee(int i) should be sufficient for
> disabling IPA optimizations involving callee.
I thought you were worried about extra IPA optimizations. I prefer to
clearly say what I mean (besides it was just copied from existing
tests), so the verbose form is better. So if e.g. gcc ever re-adds the old
RTL inliner it wouldn't break.
-Andi
new file mode 100644
@@ -0,0 +1,15 @@
+/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
+
+int __attribute__((noinline,noclone,noipa))
+callee (int i)
+{
+ return i * i;
+}
+
+int __attribute__((noinline,noclone,noipa))
+caller (int i)
+{
+ [[gnu::musttail]] return callee (i + 1);
+}
new file mode 100644
@@ -0,0 +1,34 @@
+/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
+
+struct box { char field[256]; int i; };
+
+int __attribute__((noinline,noclone,noipa))
+test_2_callee (int i, struct box b)
+{
+ if (b.field[0])
+ return 5;
+ return i * i;
+}
+
+int __attribute__((noinline,noclone,noipa))
+test_2_caller (int i)
+{
+ struct box b;
+ [[gnu::musttail]] return test_2_callee (i + 1, b); /* { dg-error "cannot tail-call: " } */
+}
+
+extern void setjmp (void);
+void
+test_3 (void)
+{
+ [[gnu::musttail]] return setjmp (); /* { dg-error "cannot tail-call: " } */
+}
+
+typedef void (fn_ptr_t) (void);
+volatile fn_ptr_t fn_ptr;
+
+void
+test_5 (void)
+{
+ [[gnu::musttail]] return fn_ptr (); /* { dg-error "cannot tail-call: " } */
+}
new file mode 100644
@@ -0,0 +1,29 @@
+/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
+
+extern int foo2 (int x, ...);
+
+struct str
+{
+ int a, b;
+};
+
+struct str
+cstruct (int x)
+{
+ if (x < 10)
+ [[clang::musttail]] return cstruct (x + 1);
+ return ((struct str){ x, 0 });
+}
+
+int
+foo (int x)
+{
+ if (x < 10)
+ [[clang::musttail]] return foo2 (x, 29);
+ if (x < 100)
+ {
+ int k = foo (x + 1);
+ [[clang::musttail]] return k; /* { dg-error "cannot tail-call: " } */
+ }
+ return x;
+}
new file mode 100644
@@ -0,0 +1,17 @@
+/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
+
+struct box { char field[64]; int i; };
+
+struct box __attribute__((noinline,noclone,noipa))
+returns_struct (int i)
+{
+ struct box b;
+ b.i = i * i;
+ return b;
+}
+
+int __attribute__((noinline,noclone))
+test_1 (int i)
+{
+ [[gnu::musttail]] return returns_struct (i * 5).i; /* { dg-error "cannot tail-call: " } */
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c23" { target c } } */
+/* { dg-options "-std=gnu++11" { target c++ } } */
+
+[[musttail]] int j; /* { dg-warning "attribute" } */
+__attribute__((musttail)) int k; /* { dg-warning "attribute" } */
+
+void foo(void)
+{
+ [[gnu::musttail]] j++; /* { dg-warning "attribute" } */
+ [[gnu::musttail]] if (k > 0) /* { dg-warning "attribute" } */
+ [[gnu::musttail]] k++; /* { dg-warning "attribute" } */
+}
+
+int foo2(int p)
+{
+ [[gnu::musttail(1)]] return foo2(p + 1); /* { dg-error "attribute" } */
+}
+
+int i;
+
+void foo3(void)
+{
+ [[musttail]] i++; /* { dg-warning "attribute" } */
+}