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

Teresa Johnson <tejohnson at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tejohnson at google dot com

--- Comment #2 from Teresa Johnson <tejohnson at google dot com> ---
I have another small test case that manifests as a seg fault at runtime, but I
believe it is likely the same issue.

test.cc:

class MyClass {
 public:
  virtual void Method1() const {}

  virtual void Method2() const {}

  virtual ~MyClass() {}
};

int main(void) {
  MyClass *d = new MyClass;
  struct MethodStruct {
    void (MyClass::*method)() const;
  };

  const MethodStruct kTest[] = {
    {&MyClass::Method1},
    {&MyClass::Method2},
  };

  for (int i = 0; i < 2; ++i) {
    (d->*kTest[i].method)();
  }
  delete d;
}


Compiled with "g++ -O2 test.cc -std=gnu++11" it seg faults when trying to
invoke method in the for loop. If I make this change:

22c22,23
<     (d->*kTest[i].method)();
---
>     const auto ptmf = kTest[i].method;
>     (d->*ptmf)();

the test case passes.

I found that the following initializations of the function pointers in kTest
are being eliminated by cddce1, and if that is disabled, then they are
eliminated by dce1:

  [test.cc : 19:3] # .MEM_12 = VDEF <.MEM_10>
  kTestD.2288[0].methodD.2287.__pfnD.2284 = 1B;
  [test.cc : 19:3] # .MEM_13 = VDEF <.MEM_12>
  kTestD.2288[0].methodD.2287.__deltaD.2285 = 0;
  [test.cc : 19:3] # .MEM_14 = VDEF <.MEM_13>
  kTestD.2288[1].methodD.2287.__pfnD.2284 = 9B;
  [test.cc : 19:3] # .MEM_15 = VDEF <.MEM_14>
  kTestD.2288[1].methodD.2287.__deltaD.2285 = 0;

Reply via email to