Bug 78965 - [7 Regression] Invalid -fprintf-return-value optimization
Summary: [7 Regression] Invalid -fprintf-return-value optimization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 7.0
: P1 normal
Target Milestone: 7.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-02 11:03 UTC by Jakub Jelinek
Modified: 2017-01-03 07:29 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-01-02 00:00:00


Attachments
gcc7-pr78965.patch (774 bytes, patch)
2017-01-02 11:17 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2017-01-02 11:03:17 UTC
int
main ()
{
  int a = 5, b = 6;
  int c = __builtin_snprintf (0, 0, "a%nb%nc", &a, &b);
  if (a + b + c != 6)
    __builtin_abort ();
  return 0;
}

is miscompiled since r242674 at -O2.
Comment 1 Jakub Jelinek 2017-01-02 11:17:03 UTC
Created attachment 40436 [details]
gcc7-pr78965.patch

Untested fix.
Comment 2 Jakub Jelinek 2017-01-03 07:23:43 UTC
Author: jakub
Date: Tue Jan  3 07:23:11 2017
New Revision: 244014

URL: https://gcc.gnu.org/viewcvs?rev=244014&root=gcc&view=rev
Log:
	PR tree-optimization/78965
	* gimple-ssa-sprintf.c (pass_sprintf_length::compute_format_length):
	Change first argument from const call_info & to call_info &.  For %n
	set info.nowrite to false.

	* gcc.dg/pr78965.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr78965.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-ssa-sprintf.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Jakub Jelinek 2017-01-03 07:29:22 UTC
Fixed.