[Bug c++/70620] possible wrong code at -Os on x86_64-linux-gnu for C++ code with multiple inheritance and casting

2016-04-11 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70620

--- Comment #4 from Jakub Jelinek  ---
FYI, the change in behavior is that ipa-devirt or what changes the destructor
call into __builtin_unreachable () and anything can happen then.

[Bug c++/70620] possible wrong code at -Os on x86_64-linux-gnu for C++ code with multiple inheritance and casting

2016-04-11 Thread su at cs dot ucdavis.edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70620

--- Comment #3 from Zhendong Su  ---
(In reply to Jonathan Wakely from comment #2)
> Your code is equivalent to:
> 
>   delete reinterpret_cast(static_cast(new E));
> 
> which means the conversion is not done safely, and you get a D* that doesn't
> point to the D subobject.
> 
> Compare:
> 
>   E* e = new E;
>   std::cout << (D*)e << '\n' << (B1*)e << '\n' << (D*)(B1*)e << '\n';
> 
> The expression (D*)(B1*)e is not the same as (D*)e, i.e. it does not produce
> the address of the D subobject.

Thanks Jonathan. That's what I had thought, but the change in behavior caused
me to wonder.

[Bug c++/70620] possible wrong code at -Os on x86_64-linux-gnu for C++ code with multiple inheritance and casting

2016-04-11 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70620

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #2 from Jonathan Wakely  ---
Your code is equivalent to:

  delete reinterpret_cast(static_cast(new E));

which means the conversion is not done safely, and you get a D* that doesn't
point to the D subobject.

Compare:

  E* e = new E;
  std::cout << (D*)e << '\n' << (B1*)e << '\n' << (D*)(B1*)e << '\n';

The expression (D*)(B1*)e is not the same as (D*)e, i.e. it does not produce
the address of the D subobject.

[Bug c++/70620] possible wrong code at -Os on x86_64-linux-gnu for C++ code with multiple inheritance and casting

2016-04-11 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70620

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek  ---
This changed behavior with r215569.  I'd be really surprised if this is not UB,
but in C++ nothing can really surprise me.