Repository: rust
Issue: Empty drop() causes cross-language LTO LLVM segfault
Labels: I-crash,A-LLVM,T-compiler,C-bug,A-LTO

This is a little esoteric, but on Debian testing (LLVM 9, rustc 1.43, obviously can't use rustup since clang's LLVM has to match rustc's LLVM for cross-language LTO), when doing cross-language LTO compilations, if a Rust struct has an `impl Drop` with an empty body in `drop()`, LLVM segfaults doing cross-language LTO. Dropping the impl Drop results in valgrind-clean (at least the parts I tested) code that compiles fine with -Wall. Linking with only-Rust LTO works fine, the issue only kicks in with cross-language LTO.

Built as:
```
cargo rustc -v --release -- -C linker-plugin-lto -C lto -C link-arg=-fuse-ld=lld
clang++ -Wall -flto -O2 -pthread demo.cpp ../target/release/liblightning.a -ldl
```

BT in ld:
```
#0  0x00007ffff4c7609d in ?? () from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#1  0x00007ffff4c95aab in llvm::InternalizePass::maybeInternalize(llvm::GlobalValue&, llvm::DenseSet<llvm::Comdat const*, llvm::DenseMapInfo<llvm::Comdat const*> > const&) () from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#2  0x00007ffff4c95ff6 in llvm::InternalizePass::internalizeModule(llvm::Module&, llvm::CallGraph*) ()
   from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#3  0x00007ffff4c722fa in llvm::thinLTOInternalizeModule(llvm::Module&, llvm::DenseMap<unsigned long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long>, llvm::detail::DenseMapPair<unsigned long, llvm::GlobalValueSummary*> > const&) ()
   from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#4  0x00007ffff4f83222 in llvm::lto::thinBackend(llvm::lto::Config&, unsigned int, std::function<std::unique_ptr<llvm::lto::NativeObjectStream, std::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>, llvm::Module&, llvm::ModuleSummaryIndex const&, llvm::StringMap<std::unordered_set<unsigned long, std::hash<unsigned long>, std::equal_to<unsigned long>, std::allocator<unsigned long> >, llvm::MallocAllocator> const&, llvm::DenseMap<unsigned long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long>, llvm::detail::DenseMapPair<unsigned long, llvm::GlobalValueSummary*> > const&, llvm::MapVector<llvm::StringRef, llvm::BitcodeModule, llvm::DenseMap<llvm::StringRef, unsigned int, llvm::DenseMapInfo<llvm::StringRef>, llvm::detail::DenseMapPair<llvm::StringRef, unsigned int> >, std::vector<std::pair<llvm::StringRef, llvm::BitcodeModule>, std::allocator<std::pair<llvm::StringRef, llvm::BitcodeModule> > > >&) ()
   from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#5  0x00007ffff4f7d836 in ?? () from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#6  0x00007ffff4f7d3a5 in ?? () from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#7  0x00007ffff4103d8f in ?? () from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#8  0x00007ffff4103ce7 in ?? () from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#9  0x00007ffff321134f in __pthread_once_slow (once_control=0x55555653d168, init_routine=0x7ffff34cbd50 <__once_proxy>)
    at pthread_once.c:116
#10 0x00007ffff4103c7d in ?? () from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#11 0x00007ffff410392d in ?? () from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#12 0x00007ffff41034b8 in ?? () from /usr/lib/llvm-9/bin/../lib/../lib/libLLVM-9.so.1
#13 0x00007ffff34ccc60 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#14 0x00007ffff3208ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#15 0x00007ffff7d94dcf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
```