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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot 
gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The test case actually exposes two bugs: besides the ICE, the more interesting
problem is the false positive.  The warning considers pointers with positive
offsets invalid arguments to all deallocation functions.  That's fair for
arguments to pairs of calls to allocation and deallocation functions but not
necessarily when just the deallocator is known and not also the allocator the
pointer was obtained from.  A simple test case for that, reduced from the two
translation units in comment #0, is below:

$ cat t.C && gcc -O2 -S -Wall t.C
struct MemoryManager { void* allocate (); };

struct XMemory
{
  void* operator new (__SIZE_TYPE__, MemoryManager *mgr)
  {
    void *p = mgr->allocate ();
    return (char*)p + sizeof(MemoryManager);
  }

  void operator delete (void*, MemoryManager*);
};

struct XMLMutex: XMemory {
  XMLMutex();
};

void gValidatorMutex (MemoryManager *mgr) { new (mgr) XMLMutex; }
t.C: In function ‘void gValidatorMutex(MemoryManager*)’:
t.C:18:55: warning: ‘static void XMemory::operator delete(void*,
MemoryManager*)’ called on pointer ‘<unknown>’ with nonzero offset 1
[-Wfree-nonheap-object]
   18 | void gValidatorMutex (MemoryManager *mgr) { new (mgr) XMLMutex; }
      |                                                       ^~~~~~~~
t.C:7:29: note: returned from a call to ‘void* MemoryManager::allocate()’
    7 |     void *p = mgr->allocate ();
      |               ~~~~~~~~~~~~~~^~

Reply via email to