On Fri, 4 Aug 2023 at 23:28, Bradley Lucier via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > The patch at the end adds a warning when a tail/sibling call cannot be > optimized for various reasons. > > I built and tested GCC with and without the patch with configuration > > Configured with: ../../gcc-mainline/configure --enable-languages=c > --disable-multilib --prefix=/pkgs/gcc-mainline --disable-werror > > There were some changes in the test results, but I can't say that they > look substantive: > > diff -C 2 summary.log ../gcc-mainline > *** summary.log Thu Aug 3 22:56:13 2023 > --- ../gcc-mainline/summary.log Thu Aug 3 19:42:33 2023 > *************** > *** 14,22 **** > === g++ Summary === > > ! # of expected passes 239234 > # of unexpected failures 5 > # of expected failures 2087 > ! # of unsupported tests 10566 > ! /home/lucier/programs/gcc/objdirs/gcc-mainline-new/gcc/xg++ version > 14.0.0 20230802 (experimental) (GCC) > > === gcc tests === > --- 14,22 ---- > === g++ Summary === > > ! # of expected passes 239262 > # of unexpected failures 5 > # of expected failures 2087 > ! # of unsupported tests 10562 > ! /home/lucier/programs/gcc/objdirs/gcc-mainline/gcc/xg++ version > 14.0.0 20230802 (experimental) (GCC) > > === gcc tests === > *************** > *** 155,164 **** > === gcc Summary === > > ! # of expected passes 192553 > # of unexpected failures 109 > # of unexpected successes 19 > # of expected failures 1506 > ! # of unsupported tests 2623 > ! /home/lucier/programs/gcc/objdirs/gcc-mainline-new/gcc/xgcc version > 14.0.0 20230802 (experimental) (GCC) > > === libatomic tests === > --- 155,164 ---- > === gcc Summary === > > ! # of expected passes 192563 > # of unexpected failures 109 > # of unexpected successes 19 > # of expected failures 1506 > ! # of unsupported tests 2619 > ! /home/lucier/programs/gcc/objdirs/gcc-mainline/gcc/xgcc version > 14.0.0 20230802 (experimental) (GCC) > > === libatomic tests === > > I then configured and built GCC with > > ../../gcc-mainline/configure CXX="/pkgs/gcc-mainline-new/bin/g++ > -Wdisabled-optimization" --enable-languages=c --disable-multilib > --prefix=/pkgs/gcc-mainline-test --disable-werror --disable-bootstrap > > to test the new warning. The warnings are of the form, e.g., > > ../../../gcc-mainline/gcc/tree-vect-stmts.cc:11990:44: warning: cannot > apply sibling-call optimization: callee required more stack slots than > the caller [-Wdisabled-optimization] > > These are the number of times this warning was triggered building stage1: > > grep warning: build.log | grep sibling | sed 's/^.*://' | sort | uniq -c > 259 callee required more stack slots than the caller > [-Wdisabled-optimization] > 43 callee returns a structure [-Wdisabled-optimization] > > If this patch is OK, someone else will need to commit it for me. > > Brad > > gcc/Changelog > > * calls.cc (maybe_complain_about_tail_call) Add warning when > tail or sibling call cannot be optimized. Hi Bradley, I don't have comments on the patch, but a new warning will also require a corresponding entry in doc/invoke.texi.
Thanks, Prathamesh > > diff --git a/gcc/calls.cc b/gcc/calls.cc > index 1f3a6d5c450..b95c876fda8 100644 > --- a/gcc/calls.cc > +++ b/gcc/calls.cc > @@ -1242,10 +1242,12 @@ void > maybe_complain_about_tail_call (tree call_expr, const char *reason) > { > gcc_assert (TREE_CODE (call_expr) == CALL_EXPR); > - if (!CALL_EXPR_MUST_TAIL_CALL (call_expr)) > - return; > - > - error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason); > + if (CALL_EXPR_MUST_TAIL_CALL (call_expr)) > + error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason); > + else if (flag_optimize_sibling_calls) > + warning (OPT_Wdisabled_optimization, > + "cannot apply sibling-call optimization: %s", reason); > + return; > } > > /* Fill in ARGS_SIZE and ARGS array based on the parameters found in > >