[Bug tree-optimization/80655] -Werror=format-truncation inconsistency between x86_32 and x86_64

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon May 8 02:07:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80655

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|2017-05-06 00:00:00         |2017-05-07
                 CC|                            |msebor at gcc dot gnu.org
          Component|c++                         |tree-optimization
     Ever confirmed|0                           |1

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed.  The warning can be suppressed by changing the invocation of the
vector ctor to be passed an unsigned type, e.g., like so:

    std::vector<char> longer_message(size + 1U);

The gimple-ssa-sprintf pass sees this.  It's almost as though size_14 was being
considered to be unsigned.

  <bb 2> [100.00%]:
  ...
  size_14 = snprintf (&message, 256, format_12(D), _2);
  ...
  <bb 5> [50.00%]:
  if (size_14 >= 0)                  <<< given size_14 is int,
    goto <bb 6>; [46.68%]
  else
    goto <bb 13>; [53.32%]
  <bb 6> [23.34%]:
  _4 = size_14 + 1;                  <<< and given this,
  ...
  if (_4 != 0)                       <<< how could this not hold...
    goto <bb 7>; [33.00%]
  else
    goto <bb 19>; [67.00%]           <<< ...and this branch be taken?
  ...
  <bb 7> [7.70%]:
  _61 = operator new (_5);
  __builtin_memset (_61, 0, _5);
  ...
  snprintf (_61, _5, format_12(D), _7);
  ...
  <bb 19> [15.64%]:
  __builtin_memset (0B, 0, _5);
  ...
  snprintf (0B, _5, format_12(D), _85);


More information about the Gcc-bugs mailing list