On Fri, 25 Aug 2023, Richard Biener via Gcc-patches wrote:
>
> The following adds the capability to have fold-const.cc matched
> patterns visible in -folding dumps. There's two choices,
> a portable one replacing return stmts like
>
> - return fold_build1 (tcode, ctype, fold_convert (ctype, t1));
> + DRET (fold_build1 (tcode, ctype, fold_convert (ctype, t1)));
>
> (carefully keeping total line length the same)
>
> Or less portably by wrapping the return value:
>
> - return fold_build1 (tcode, ctype, fold_convert (ctype, t1));
> + return DUMP_FOLD (fold_build1 (tcode, ctype, fold_convert (ctype,
> t1)));
>
> (requiring re-indenting)
>
> +/* Similar to match.pd dumping support notes as part of -folding dumping
> + by wrapping return values in DUMP_FOLD (...). */
> +#if __GNUC__
> +#define DUMP_FOLD(X) (__extension__ ({ \
> + auto x = (X); \
> + if (x && dump_file && (dump_flags & TDF_FOLDING)) \
> +fprintf (dump_file, "Applying fold-const.c:%d\n", __LINE__); \
> + x; \
> +}))
Would using an ordinary function here work?
static tree
dump_fold (tree x, int line)
{
if (...)
fprintf (dump_file, "Applying fold-const.c:%d\n", line);
return x;
}
#define DUMP_FOLD(X) dump_fold ((X), __LINE__)
> +#else
> +#define DUMP_FOLD(X) (X)
> +#endif
>
> vs.
>
> +/* Similar to match.pd dumping support notes as part of -folding dumping
> + by changing return statements to DRET (...). */
> +#define DRET(X) do { \
> + auto x = (X); \
> + if (x && dump_file && (dump_flags & TDF_FOLDING)) \
> +fprintf (dump_file, "Applying fold-const.c:%d\n", __LINE__); \
> + return x; \
> +} while (0)
>
> I personally prefer keeping 'return' visible and thus going the
> non-portable way. Any C++ folks know how to avoid re-evaluating
> X portably in expression context?
>
> Any other comments?
>
> Thanks,
> Richard.
>
>