diff mbox series

[v7,6/9] Add tests for C/C++ musttail attributes

Message ID 20240602172205.2151579-7-ak@linux.intel.com
State New
Headers show
Series [v7,1/9] Improve must tail in RTL backend | expand

Commit Message

Andi Kleen June 2, 2024, 5:16 p.m. UTC
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/musttail7.c: New test.
	* c-c++-common/musttail8.c: New test.
	* g++.dg/musttail6.C: New test.
	* g++.dg/musttail9.C: New test.
	* g++.dg/musttail10.C: New test.
---
 gcc/testsuite/c-c++-common/musttail1.c | 14 +++++++
 gcc/testsuite/c-c++-common/musttail2.c | 33 +++++++++++++++
 gcc/testsuite/c-c++-common/musttail3.c | 29 +++++++++++++
 gcc/testsuite/c-c++-common/musttail4.c | 17 ++++++++
 gcc/testsuite/c-c++-common/musttail5.c | 28 +++++++++++++
 gcc/testsuite/c-c++-common/musttail7.c | 14 +++++++
 gcc/testsuite/c-c++-common/musttail8.c | 17 ++++++++
 gcc/testsuite/g++.dg/musttail10.C      | 20 +++++++++
 gcc/testsuite/g++.dg/musttail6.C       | 58 ++++++++++++++++++++++++++
 gcc/testsuite/g++.dg/musttail9.C       | 10 +++++
 10 files changed, 240 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
 create mode 100644 gcc/testsuite/c-c++-common/musttail7.c
 create mode 100644 gcc/testsuite/c-c++-common/musttail8.c
 create mode 100644 gcc/testsuite/g++.dg/musttail10.C
 create mode 100644 gcc/testsuite/g++.dg/musttail6.C
 create mode 100644 gcc/testsuite/g++.dg/musttail9.C

Comments

Jason Merrill June 3, 2024, 2:46 p.m. UTC | #1
On 6/2/24 13:16, Andi Kleen 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/musttail7.c: New test.
> 	* c-c++-common/musttail8.c: New test.
> 	* g++.dg/musttail6.C: New test.
> 	* g++.dg/musttail9.C: New test.
> 	* g++.dg/musttail10.C: New test.
> ---
>   gcc/testsuite/c-c++-common/musttail1.c | 14 +++++++
>   gcc/testsuite/c-c++-common/musttail2.c | 33 +++++++++++++++
>   gcc/testsuite/c-c++-common/musttail3.c | 29 +++++++++++++
>   gcc/testsuite/c-c++-common/musttail4.c | 17 ++++++++
>   gcc/testsuite/c-c++-common/musttail5.c | 28 +++++++++++++
>   gcc/testsuite/c-c++-common/musttail7.c | 14 +++++++
>   gcc/testsuite/c-c++-common/musttail8.c | 17 ++++++++
>   gcc/testsuite/g++.dg/musttail10.C      | 20 +++++++++
>   gcc/testsuite/g++.dg/musttail6.C       | 58 ++++++++++++++++++++++++++
>   gcc/testsuite/g++.dg/musttail9.C       | 10 +++++
>   10 files changed, 240 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
>   create mode 100644 gcc/testsuite/c-c++-common/musttail7.c
>   create mode 100644 gcc/testsuite/c-c++-common/musttail8.c
>   create mode 100644 gcc/testsuite/g++.dg/musttail10.C
>   create mode 100644 gcc/testsuite/g++.dg/musttail6.C
>   create mode 100644 gcc/testsuite/g++.dg/musttail9.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..74efcc2a0bc6
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/musttail1.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
> +/* { 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);
> +}
> diff --git a/gcc/testsuite/c-c++-common/musttail2.c b/gcc/testsuite/c-c++-common/musttail2.c
> new file mode 100644
> index 000000000000..86f2c3d77404
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/musttail2.c
> @@ -0,0 +1,33 @@
> +/* { 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: " } */
> +}
> +
> +extern float f7(void);
> +
> +int
> +test_6 (void)
> +{
> +  [[gnu::musttail]] return f7(); /* { 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..234da0d3f2a9
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/musttail5.c
> @@ -0,0 +1,28 @@
> +/* { 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 "\(before numeric constant|attribute\)" } */
> +}
> +
> +int i;
> +
> +int foo3(void)
> +{
> +  [[musttail]] i++; /* { dg-warning "attribute" } */
> +  [[musttail]] if (i > 10) /* { dg-warning "attribute" } */
> +    [[musttail]] return foo2(i); /* { dg-warning "attribute" } */
> +  return 0;
> +}
> diff --git a/gcc/testsuite/c-c++-common/musttail7.c b/gcc/testsuite/c-c++-common/musttail7.c
> new file mode 100644
> index 000000000000..5e4eb1bfbacc
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/musttail7.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
> +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
> +
> +extern void f();
> +
> +void f2()
> +{
> +  [[gnu::musttail]] return f2();
> +}
> +
> +void f3()
> +{
> +  [[gnu::musttail]] return f();
> +}
> diff --git a/gcc/testsuite/c-c++-common/musttail8.c b/gcc/testsuite/c-c++-common/musttail8.c
> new file mode 100644
> index 000000000000..9fa10e0b54c4
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/musttail8.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
> +
> +float f1(void);
> +
> +int f2(void)
> +{
> +  [[gnu::musttail]] return f1 (); /* { dg-error "changed after call" } */
> +}
> +
> +
> +int f3(int *);
> +
> +int f4(void)
> +{
> +  int x;
> +  [[gnu::musttail]] return f3(&x); /* { dg-error "\(refers to locals|other reasons\)" } */
> +}
> diff --git a/gcc/testsuite/g++.dg/musttail10.C b/gcc/testsuite/g++.dg/musttail10.C
> new file mode 100644
> index 000000000000..6da7e021f826
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/musttail10.C
> @@ -0,0 +1,20 @@
> +/* { dg-do compile { target { tail_call } } } */
> +/* { dg-options "-std=gnu++11" } */
> +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
> +
> +int f();
> +
> +double h() { [[gnu::musttail]] return f(); } /* { dg-error "cannot tail-call" } */
> +
> +/* The error check cannot distinguish between the (valid) int and the invalid
> +   double conversion case because the template context is lost when tree-tailcall
> +   finally runs.  */

Maybe use identical g1 and g2 to distinguish?

> +
> +template <class T>
> +T g() { [[gnu::musttail]] return f(); } /* { dg-error "cannot tail-call" } */
> +
> +int main()
> +{
> +  g<int>();
> +  g<double>();
> +}
> diff --git a/gcc/testsuite/g++.dg/musttail6.C b/gcc/testsuite/g++.dg/musttail6.C
> new file mode 100644
> index 000000000000..e0e478e08d58
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/musttail6.C
> @@ -0,0 +1,58 @@
> +/* { dg-do compile { target { tail_call } } } */
> +/* { dg-options "-std=gnu++11" } */
> +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
> +
> +class Foo {
> +public:
> +  int a, b;
> +  Foo(int a, int b) : a(a), b(b) {}
> +};
> +
> +Foo __attribute__((noinline,noclone,noipa))
> +callee (int i)
> +{
> +  return Foo(i, i+1);
> +}
> +
> +Foo __attribute__((noinline,noclone,noipa))
> +caller (int i)
> +{
> +  [[gnu::musttail]] return callee (i + 1);
> +}
> +
> +template<typename T>
> +T __attribute__((noinline,noclone,noipa)) foo (T i)
> +{
> +  return i + 1;
> +}
> +
> +int
> +caller2 (int k)
> +{
> +  [[gnu::musttail]] return foo<int>(1);
> +}
> +
> +template<typename T>
> +T caller3 (T v)
> +{
> +  [[gnu::musttail]] return foo<T>(v);
> +}
> +
> +int call3(int i)
> +{
> +  [[gnu::musttail]] return caller3<int>(i + 1);
> +}
> +
> +struct Bar {
> +  int a;
> +  Bar(int a) : a(a) {}
> +  Bar operator+(Bar o) { return Bar(a + o.a); }
> +};
> +
> +#if __OPTIMIZE__ >= 1
> +Bar
> +caller4 (Bar k)
> +{
> +  [[gnu::musttail]] return caller3<Bar>(Bar(99));
> +}
> +#endif
> diff --git a/gcc/testsuite/g++.dg/musttail9.C b/gcc/testsuite/g++.dg/musttail9.C
> new file mode 100644
> index 000000000000..8095bdf6fe62
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/musttail9.C
> @@ -0,0 +1,10 @@
> +/* { dg-do compile { target { tail_call } } } */
> +/* { dg-options "-std=gnu++11 -Wno-deprecated" } */
> +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
> +
> +extern void foo() throw(const char *);
> +
> +void f() throw()
> +{
> +  [[gnu::musttail]] return foo(); /* { dg-error "call may throw exception that does not propagate" } */
> +}

Instead of -Wno-deprecated let's use C++11 exception-specifications; you 
can leave out the exception specification on foo and change f's to 
"noexcept".

Jason
diff mbox series

Patch

diff --git a/gcc/testsuite/c-c++-common/musttail1.c b/gcc/testsuite/c-c++-common/musttail1.c
new file mode 100644
index 000000000000..74efcc2a0bc6
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/musttail1.c
@@ -0,0 +1,14 @@ 
+/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
+/* { 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);
+}
diff --git a/gcc/testsuite/c-c++-common/musttail2.c b/gcc/testsuite/c-c++-common/musttail2.c
new file mode 100644
index 000000000000..86f2c3d77404
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/musttail2.c
@@ -0,0 +1,33 @@ 
+/* { 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: " } */
+}
+
+extern float f7(void);
+
+int
+test_6 (void)
+{
+  [[gnu::musttail]] return f7(); /* { 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..234da0d3f2a9
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/musttail5.c
@@ -0,0 +1,28 @@ 
+/* { 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 "\(before numeric constant|attribute\)" } */
+}
+
+int i;
+
+int foo3(void)
+{
+  [[musttail]] i++; /* { dg-warning "attribute" } */
+  [[musttail]] if (i > 10) /* { dg-warning "attribute" } */
+    [[musttail]] return foo2(i); /* { dg-warning "attribute" } */
+  return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/musttail7.c b/gcc/testsuite/c-c++-common/musttail7.c
new file mode 100644
index 000000000000..5e4eb1bfbacc
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/musttail7.c
@@ -0,0 +1,14 @@ 
+/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
+/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
+
+extern void f();
+
+void f2()
+{
+  [[gnu::musttail]] return f2();
+}
+
+void f3()
+{
+  [[gnu::musttail]] return f();
+}
diff --git a/gcc/testsuite/c-c++-common/musttail8.c b/gcc/testsuite/c-c++-common/musttail8.c
new file mode 100644
index 000000000000..9fa10e0b54c4
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/musttail8.c
@@ -0,0 +1,17 @@ 
+/* { dg-do compile { target { tail_call && { c || c++11 } } } } */
+
+float f1(void);
+
+int f2(void)
+{
+  [[gnu::musttail]] return f1 (); /* { dg-error "changed after call" } */
+}
+
+
+int f3(int *);
+
+int f4(void)
+{
+  int x;
+  [[gnu::musttail]] return f3(&x); /* { dg-error "\(refers to locals|other reasons\)" } */
+}
diff --git a/gcc/testsuite/g++.dg/musttail10.C b/gcc/testsuite/g++.dg/musttail10.C
new file mode 100644
index 000000000000..6da7e021f826
--- /dev/null
+++ b/gcc/testsuite/g++.dg/musttail10.C
@@ -0,0 +1,20 @@ 
+/* { dg-do compile { target { tail_call } } } */
+/* { dg-options "-std=gnu++11" } */
+/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
+
+int f();
+
+double h() { [[gnu::musttail]] return f(); } /* { dg-error "cannot tail-call" } */
+
+/* The error check cannot distinguish between the (valid) int and the invalid
+   double conversion case because the template context is lost when tree-tailcall
+   finally runs.  */
+
+template <class T>
+T g() { [[gnu::musttail]] return f(); } /* { dg-error "cannot tail-call" } */
+
+int main()
+{
+  g<int>();
+  g<double>();
+}
diff --git a/gcc/testsuite/g++.dg/musttail6.C b/gcc/testsuite/g++.dg/musttail6.C
new file mode 100644
index 000000000000..e0e478e08d58
--- /dev/null
+++ b/gcc/testsuite/g++.dg/musttail6.C
@@ -0,0 +1,58 @@ 
+/* { dg-do compile { target { tail_call } } } */
+/* { dg-options "-std=gnu++11" } */
+/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
+
+class Foo {
+public:
+  int a, b;
+  Foo(int a, int b) : a(a), b(b) {}
+};
+
+Foo __attribute__((noinline,noclone,noipa))
+callee (int i)
+{
+  return Foo(i, i+1);
+}
+
+Foo __attribute__((noinline,noclone,noipa))
+caller (int i)
+{
+  [[gnu::musttail]] return callee (i + 1);
+}
+
+template<typename T>
+T __attribute__((noinline,noclone,noipa)) foo (T i)
+{
+  return i + 1;
+}
+
+int
+caller2 (int k)
+{
+  [[gnu::musttail]] return foo<int>(1);
+}
+
+template<typename T>
+T caller3 (T v)
+{
+  [[gnu::musttail]] return foo<T>(v);
+}
+
+int call3(int i)
+{
+  [[gnu::musttail]] return caller3<int>(i + 1);
+}
+
+struct Bar {
+  int a;
+  Bar(int a) : a(a) {}
+  Bar operator+(Bar o) { return Bar(a + o.a); } 
+};
+
+#if __OPTIMIZE__ >= 1
+Bar
+caller4 (Bar k)
+{
+  [[gnu::musttail]] return caller3<Bar>(Bar(99));
+}
+#endif
diff --git a/gcc/testsuite/g++.dg/musttail9.C b/gcc/testsuite/g++.dg/musttail9.C
new file mode 100644
index 000000000000..8095bdf6fe62
--- /dev/null
+++ b/gcc/testsuite/g++.dg/musttail9.C
@@ -0,0 +1,10 @@ 
+/* { dg-do compile { target { tail_call } } } */
+/* { dg-options "-std=gnu++11 -Wno-deprecated" } */
+/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
+
+extern void foo() throw(const char *);
+
+void f() throw()
+{
+  [[gnu::musttail]] return foo(); /* { dg-error "call may throw exception that does not propagate" } */
+}