Mostly adopted from the existing C musttail plugin tests. --- gcc/testsuite/g++.dg/musttail1.C | 15 ++++++++++++ gcc/testsuite/g++.dg/musttail2.C | 35 ++++++++++++++++++++++++++ gcc/testsuite/g++.dg/musttail3.C | 42 ++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/musttail4.C | 19 +++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 gcc/testsuite/g++.dg/musttail1.C create mode 100644 gcc/testsuite/g++.dg/musttail2.C create mode 100644 gcc/testsuite/g++.dg/musttail3.C create mode 100644 gcc/testsuite/g++.dg/musttail4.C
diff --git a/gcc/testsuite/g++.dg/musttail1.C b/gcc/testsuite/g++.dg/musttail1.C new file mode 100644 index 000000000000..c9276e0ae86a --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail1.C @@ -0,0 +1,15 @@ +/* { dg-do compile { target tail_call } } */ +/* { dg-options "-std=c++11 -O2" } */ +/* { dg-options "-fdelayed-branch" { target sparc*-*-* } } */ + +int __attribute__((noinline,noclone)) +callee (int i) +{ + return i * i; +} + +int __attribute__((noinline,noclone)) +caller (int i) +{ + [[gnu::musttail]] return callee (i + 1); +} diff --git a/gcc/testsuite/g++.dg/musttail2.C b/gcc/testsuite/g++.dg/musttail2.C new file mode 100644 index 000000000000..d9151d25f517 --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail2.C @@ -0,0 +1,35 @@ +/* { dg-do compile { target tail_call } } */ +/* { dg-options "-std=c++11" } */ + +struct box { char field[256]; int i; }; + +int __attribute__((noinline,noclone)) +test_2_callee (int i, struct box b) +{ + if (b.field[0]) + return 5; + return i * i; +} + +int __attribute__((noinline,noclone)) +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/g++.dg/musttail3.C b/gcc/testsuite/g++.dg/musttail3.C new file mode 100644 index 000000000000..7d55f44124ee --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail3.C @@ -0,0 +1,42 @@ +/* { dg-do compile { target tail_call } } */ +/* { dg-options "-std=c++11" } */ + +extern int foo2 (int x, ...); + +struct str +{ + int a, b; +}; + +str +cstruct (int x) +{ + if (x < 10) + [[clang::musttail]] return cstruct (x + 1); + return { x, 0 }; +} + +int +cstruct2 (int x, str & ref) +{ + if (x < 10) + { + str r = { }; + [[clang::musttail]] return cstruct2 (x + 1, r); + } + return x + 1; +} + + +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/g++.dg/musttail4.C b/gcc/testsuite/g++.dg/musttail4.C new file mode 100644 index 000000000000..3122acfb1719 --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail4.C @@ -0,0 +1,19 @@ +/* { dg-do compile { target tail_call } } */ +/* Allow nested functions. */ +/* { dg-options "-Wno-pedantic -std=c++11" } */ + +struct box { char field[64]; int i; }; + +struct box __attribute__((noinline,noclone)) +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 "return value must be a call" } */ +} -- 2.43.0