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; \
+}))      
+#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.

Reply via email to