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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-08-13
                 CC|                            |msebor at gcc dot gnu.org
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
             Blocks|                            |83819

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Overlapping copies are undefined and GCC diagnoses those it detects with
-Wrestrict.  GCC also transforms some undefined statements (such as some
exactly overlapping copies) into their reasonable but benign equivalent but
it's neither done consistently, nor under the control of an option to give
users a way to opt out (or choose some other transformation such as replace the
undefined statement with a trap).  While such transformations aren't always
desirable, diagnosing the underlying bugs almost always is.  The long term goal
we converged on in Manchester in 2018 is to a) provide an option to control
such transformations, and b) issue a diagnostic when undefined behavior is
detected.

$ gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout pr96599.c
pr96599.c: In function ‘f’:
pr96599.c:5:10: warning: ‘stpcpy’ source argument is the same as destination
[-Wrestrict]
    5 |   return stpcpy (a, a);
      |          ^~~~~~~~~~~~~

;; Function f (f, funcdef_no=0, decl_uid=1933, cgraph_uid=1, symbol_order=0)

f (char * a)
{
  char * _4;

  <bb 2> [local count: 1073741824]:
  _4 = stpcpy (a_2(D), a_2(D)); [tail call]
  return _4;

}


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83819
[Bug 83819] [meta-bug] missing strlen optimizations

Reply via email to