https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78901
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 40404 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40404&action=edit gcc7-pr78901.patch There are multiple issues, this patch hopefully fixes just one of them - the case when the call might throw and is replaced by a constant that can't throw. The other problems are: if the call is not the NULL buffer, 0 size case, where the call is kept, just lhs removed and lhs = cst; added after the call, then if the call might throw (thus has to be last in the bb), inserting a stmt after it is invalid - if (stmt_ends_bb_p (info.callstmt), then the stmt needs to be added to the beginning of the fallthru basic block. And another problem is that while you nicely remove lhs = snprintf (0, 0, ""); call and just set lhs = 0;, if the user just writes useless snprintf (0, 0, ""); without lhs, then nothing removes it at all. If the call has no lhs and is info.nowrite, then I think we can just remove it (the case replacing it with constant will work for that too).