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

--- Comment #14 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
OK, the unreachable is introduced here:
 - Creating a specialized node of bool staticBoolFunc(CompositeClass*)/414 for
all known contexts.
     the new node is <built-in>/977.                                            
     known ctx 0 is     Outer type (dynamic):struct EmptyClass offset -64       
No devirtualization target in <built-in>/977                                    
ipa-prop: Discovered a virtual call to a known target (<built-in>/977 -> void
__builtin_unreachable()/976), for stmt OBJ_TYPE_REF(_15;ptr_2(D)->1)
(ptr_2(D));
/aux/hubicka/trunk-install/include/c++/6.0.0/bits/unique_ptr.h:76:2: note:
converting indirect call in <built-in> to direct call to void
__builtin_unreachable()
No devirtualization target in <built-in>/977                                    
ipa-prop: Discovered a virtual call to a known target (<built-in>/977 -> void
__builtin_unreachable()/976), for stmt OBJ_TYPE_REF(_27;ptr_2(D)->1)
(ptr_2(D));
/aux/hubicka/trunk-install/include/c++/6.0.0/bits/unique_ptr.h:76:2: note:
converting indirect call in <built-in> to direct call to void
__builtin_unreachable()

So ipa-CP thinks that staticBoolFunc is called on EmptyClass instead of
CompositeClass:

Jump functions:                                                                 
  Jump functions of caller  long unsigned int __builtin_object_size(const
void*, int)/967:
  Jump functions of caller  void operator delete(void*, long unsigned int)/964: 
  Jump functions of caller  void* operator new(std::size_t)/963:                
  Jump functions of caller  int main(int, char**)/415:                          
    callsite  int main(int, char**)/415 -> void operator delete(void*, long
unsigned int)/964 :
    callsite  int main(int, char**)/415 -> bool
staticBoolFunc(CompositeClass*)/414 :
       param 0: UNKNOWN                                                         
         Context:     Outer type (dynamic):struct EmptyClass offset -64         
         Unknown alignment                                                      
    callsite  int main(int, char**)/415 -> EmptyClass::EmptyClass()/404 :       
       param 0: UNKNOWN                                                         
         Context:     Outer type (dynamic): (or a derived type) (maybe in
construction) offset 64 Speculative outer type:struct CompositeClass (or a
derived type) at offset 64
         Unknown alignment                                                      

This is indeed wrong. Jump function analysis seems to confuse constructors:

Modification phase of node int main(int, char**)/402
int main(int, char**) (int D.39529, char * * D.39530)
{
  void * _3;
  struct EmptyClass * _7;

  <bb 2>:
  _3 = operator new (16);
  MEM[(struct  &)_3] ={v} {CLOBBER};
  MEM[(struct CompositeClass *)_3]._vptr.CompositeClass = &MEM[(void
*)&_ZTV14CompositeClass + 16B];
  _7 = &MEM[(struct CompositeClass *)_3].object;
  EmptyClass::EmptyClass (_7);

  <bb 3>:
  staticBoolFunc (_3);
  return 0;

<L1>:
  operator delete (_3, 16);
  resx 1

EmptyClass ctor is called, but it should not type the object.

Determining dynamic type for call: staticBoolFunc (_3);
  Starting walk at: staticBoolFunc (_3);
  instance pointer: _3  Outer instance pointer: _3 offset: 0 (bits) vtbl
reference: 
  Checking constructor call: EmptyClass::EmptyClass (_7);
  Recording type: struct EmptyClass at offset -64
  Determined dynamic type.

This is quite a nonsense, because EmptyClass is not even. So there are two
bugs.
First is that we determine useless outer type. This should be just missed
optimization. But we also manage to consider to miss the case in placement_new
checking where we are completely off the structure....

Reply via email to