<div dir="ltr"><div>Hi,</div><div><br></div><div>For the following small test case,</div><br><div><div>#include <iostream>                                                         </div><div>#include <memory></div><div><br></div><div>class C {</div><div>public:</div><div>  std::auto_ptr<const C> pc;</div><div><br></div><div>  int f(void);</div><div>};</div><div><br></div><div>int C::f(void) {</div><div>  return (&*this->pc == 0);</div><div>}</div></div><div><br></div><div>clang/llvm -O2 optimizes (&*this->pc == 0) to be false statically, while gcc doesn't.</div><div><br></div><div>So my question is if this optimization is really safe?<br></div><div><br></div><div>Front-end result shows the auto pointer is nonnull, i.e. dereferenceable(8), and this is why llvm back-end can optimize the comparison away, but the problem is can we really assume &*this->pc is not 0? Why?</div><div><br></div><div><div>; Function Attrs: nounwind uwtable</div><div>define i32 @_ZN1C1fEv(%class.C* %this) #2 align 2 {</div><div>entry:</div><div>  %this.addr = alloca %class.C*, align 8</div><div>  store %class.C* %this, %class.C** %this.addr, align 8</div><div>  %this1 = load %class.C** %this.addr</div><div>  %pc = getelementptr inbounds %class.C* %this1, i32 0, i32 0</div><div>  %call = call dereferenceable(8) %class.C* @_ZNKSt8auto_ptrIK1CEdeEv(%"class.std::auto_ptr"* %pc) #1</div><div>  %cmp = icmp eq %class.C* %call, null</div><div>  %conv = zext i1 %cmp to i32</div><div>  ret i32 %conv</div><div>}</div></div><div><br></div><div>BTW, this issue triggered a run-time crash for one of SPEC benchmarks.</div><div><br></div><div>Thanks,</div><div>-Jiangning</div></div>