[Bug middle-end/91146] -Werror=array-bounds if compile with -fsanitize=address

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jul 11 21:42:00 GMT 2019


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
I can reproduce the warning but I have a few comments:

1) A smaller test case would make the issue easier to debug.
2) The instrumentation inserted by the sanitizers is known to cause false
positive warnings.  This is unfortunate but until we come up with a solution we
advise to either avoid combining sanitizers and warnings or be prepared for
false positives.
3) The code in small_vector_impl::insert copied below doesn't look quite right
to me:

  iterator insert(iterator I, const T &Elt) {
    ...
    // If we just moved the element we're inserting, be sure to update
    // the reference.
    const T *EltPtr = &Elt;
    if (I <= EltPtr && EltPtr < this->EndX)
      ++EltPtr;
    *I = ::std::move(*EltPtr);

Calling it as is done in the test but on a non-empty vector:

  v.insert (v.begin (), 1);

sets EltPtr to point to the temporary 1 while I ans this->EndX point to an
object unrelated to the temporary.  The result of an inequality expression
between pointers to unrelated objects is unspecified in C++ and so the
increment could in theory be evaluated regardless of whether Elt is a reference
to an element of the vector or some other object (such as the temporary).

A false positive warning can likely be reproduced with a valid test case but I
don't think this one qualifies.


More information about the Gcc-bugs mailing list