On Fri, Feb 5, 2016 at 9:34 PM, Jason Merrill <ja...@redhat.com> wrote: > The problem here was that the call to convert_to_integer_nofold was still > pushing the conversion down into the multiply expression, and when we do the > multiplication in unsigned short it overflows. This patch fixes > convert_to_integer_1 to not do any truncation distribution when !dofold. > But that broke several testcases, because fold() doesn't ever try to do that > distribution, and so was missing some optimizations revealed by the > distribution. So this patch changes cp_fold to redo the conversion with > dofold enabled. I also change the C++ convert() entry point to do folding > conversion again, since a few places in convert_to_integer_1, and probably > elsewhere in the back end, expect that. > > For this email I didn't re-indent the truncation distribution code in > convert_to_integer_1 to make it easier to read; for what I check in should I > leave it like this, re-indent it, or do something else like a goto to avoid > the need for re-indentation?
re-indent is fine but you could also simply tail-duplicate (optimized) /* When parsing long initializers, we might end up with a lot of casts. Shortcut this. */ if (TREE_CODE (expr) == INTEGER_CST) return fold_convert (type, expr); return build1 (CONVERT_EXPR, type, expr); and thus do if (!dofold) return ...; > Tested x86_64-pc-linux-gnu, OK for trunk? Ok. Note that I think we should move all the truncation distribution code elsewhere (match.pd). But that's probably for GCC 7. Richard.