On 12/23/20 10:07 AM, Martin Liška wrote:
Hello.

I'm not fully familiar with code in warn_dealloc_offset, but I guess
the following can work.

Martin, what do you think?

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?

Thanks for looking into it!  I'm actually just testing the very same
fix.  It's taken me a while to come up with a non-LTO test case but
below is what I've got.

If you want to commit your fix go ahead, I'll just add the test case.
(FWIW, if you see OBJ_TYPE_REF there with LTO it's one possible trigger.
The test case below has a null pointer.)

Martin

typedef __SIZE_TYPE__ size_t;

void* (*pf) (size_t);

struct A;
struct B
{
  B ();

  void* operator new (size_t, A*);
  void operator delete (void*, A*);
};

void operator delete (void *, A*);

void B::operator delete (void*, A *p)
{
  void *q = pf (1);
  ::operator delete ((char*)q + 1, p);
}

void* f (A *p)
{
  return new (p) B;
}

Thanks,
Martin

gcc/ChangeLog:

     PR tree-optimization/98160
     * builtins.c (warn_dealloc_offset): Handle OBJ_TYPE_REF as
     def_stmt.
---
  gcc/builtins.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 28e44445ab2..057a5b1a973 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -13410,7 +13410,7 @@ warn_dealloc_offset (location_t loc, tree exp, const access_ref &aref)
        if (is_gimple_call (def_stmt))
          {
            tree alloc_decl = gimple_call_fndecl (def_stmt);
-          if (!DECL_IS_OPERATOR_NEW_P (alloc_decl))
+          if (alloc_decl == NULL_TREE || !DECL_IS_OPERATOR_NEW_P (alloc_decl))
          return false;
          }
      }

Reply via email to