[libcxx-commits] [libcxx] [libc++] Optimize vector growing of trivially relocatable types (PR #76657)

Kirill Stoimenov via libcxx-commits libcxx-commits at lists.llvm.org
Fri Feb 2 17:17:32 PST 2024


kstoimenov wrote:

@philnik777 are you running your tests under ASAN? If not can you try running them with -fsanitize=address? I don't think I can help you with a reproducer because I am not working on libc++. Also FYI this is the link to the sanitizer dashboards: https://google.github.io/sanitizers/show_bots.html. 

I also added the full report which tells you where the allocation and the deallocation happened. 

>From https://lab.llvm.org/buildbot/#/builders/5/builds/40641/steps/9/logs/stdio

```
==2097169==ERROR: AddressSanitizer: heap-use-after-free on address 0x50300000a2a0 at pc 0x55d6ac624faf bp 0x7ffd01fc2830 sp 0x7ffd01fc2828
READ of size 8 at 0x50300000a2a0 thread T0
    #0 0x55d6ac624fae in asInt /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:41:5
    #1 0x55d6ac624fae in operator long /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:45:48
    #2 0x55d6ac624fae in getPointer /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:94:58
    #3 0x55d6ac624fae in getPrevPtr /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/IR/ValueHandle.h:123:58
    #4 0x55d6ac624fae in llvm::ValueHandleBase::RemoveFromUseList() /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/IR/Value.cpp:1185:5
    #5 0x55d6ae2c476d in ~ValueHandleBase /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/IR/ValueHandle.h:66:7
    #6 0x55d6ae2c476d in destroy /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/__memory/allocator.h:176:87
    #7 0x55d6ae2c476d in destroy<llvm::WeakTrackingVH, void> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/__memory/allocator_traits.h:335:9
    #8 0x55d6ae2c476d in __base_destruct_at_end /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/vector:926:7
    #9 0x55d6ae2c476d in __clear /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/vector:920:5
    #10 0x55d6ae2c476d in std::__1::vector<llvm::WeakTrackingVH, std::__1::allocator<llvm::WeakTrackingVH>>::__destroy_vector::operator()[abi:nn190000]() /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/vector:490:16
    #11 0x55d6b183e18e in ~vector /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/vector:501:67
    #12 0x55d6b183e18e in (anonymous namespace)::MergeFunctions::runOnModule(llvm::Module&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Transforms/IPO/MergeFunctions.cpp:454:3
    #13 0x55d6b183667d in llvm::MergeFunctionsPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Transforms/IPO/MergeFunctions.cpp:300:11
    #14 0x55d6b0450d71 in llvm::detail::PassModel<llvm::Module, llvm::MergeFunctionsPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:89:17
    #15 0x55d6aca6b1f5 in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/IR/PassManager.h:543:40
    #16 0x55d6b02f48c8 in llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::__1::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/opt/NewPMDriver.cpp:532:7
    #17 0x55d6ac3a2f76 in optMain /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/opt/optdriver.cpp:741:12
    #18 0x7f21e6a23a8f  (/lib/x86_64-linux-gnu/libc.so.6+0x23a8f) (BuildId: d320ce4e63925d698610ed423fc4b1f0e8ed51f1)
    #19 0x7f21e6a23b48 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23b48) (BuildId: d320ce4e63925d698610ed423fc4b1f0e8ed51f1)
    #20 0x55d6ac2b6724 in _start (/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/opt+0xabd4724)
0x50300000a2a0 is located 0 bytes inside of 24-byte region [0x50300000a2a0,0x50300000a2b8)
freed by thread T0 here:
    #0 0x55d6ac38fe9d in operator delete(void*) /b/sanitizer-x86_64-linux-fast/build/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:152:3
    #1 0x55d6ae004b2c in __libcpp_operator_delete<void *> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/new:280:3
    #2 0x55d6ae004b2c in __do_deallocate_handle_size<> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/new:302:10
    #3 0x55d6ae004b2c in __libcpp_deallocate /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/new:317:12
    #4 0x55d6ae004b2c in deallocate /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/__memory/allocator.h:139:7
    #5 0x55d6ae004b2c in deallocate /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/__memory/allocator_traits.h:313:9
    #6 0x55d6ae004b2c in ~__split_buffer /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/__split_buffer:355:5
    #7 0x55d6ae004b2c in llvm::WeakTrackingVH* std::__1::vector<llvm::WeakTrackingVH, std::__1::allocator<llvm::WeakTrackingVH>>::__push_back_slow_path<llvm::WeakTrackingVH>(llvm::WeakTrackingVH&&) /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/vector:1474:1
    #8 0x55d6b18387be in push_back /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/vector:1496:13
    #9 0x55d6b18387be in (anonymous namespace)::MergeFunctions::runOnModule(llvm::Module&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Transforms/IPO/MergeFunctions.cpp:431:16
    #10 0x55d6b183667d in llvm::MergeFunctionsPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Transforms/IPO/MergeFunctions.cpp:300:11
    #11 0x55d6b0450d71 in llvm::detail::PassModel<llvm::Module, llvm::MergeFunctionsPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:89:17
    #12 0x55d6aca6b1f5 in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/IR/PassManager.h:543:40
    #13 0x55d6b02f48c8 in llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::__1::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/opt/NewPMDriver.cpp:532:7
    #14 0x55d6ac3a2f76 in optMain /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/opt/optdriver.cpp:741:12
    #15 0x7f21e6a23a8f  (/lib/x86_64-linux-gnu/libc.so.6+0x23a8f) (BuildId: d320ce4e63925d698610ed423fc4b1f0e8ed51f1)
previously allocated by thread T0 here:
    #0 0x55d6ac38f63d in operator new(unsigned long) /b/sanitizer-x86_64-linux-fast/build/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:95:3
    #1 0x55d6ae004de8 in __libcpp_operator_new<unsigned long> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/new:271:10
    #2 0x55d6ae004de8 in __libcpp_allocate /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/new:295:10
    #3 0x55d6ae004de8 in allocate /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/__memory/allocator.h:125:32
    #4 0x55d6ae004de8 in __allocate_at_least<std::__1::allocator<llvm::WeakTrackingVH> > /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/__memory/allocate_at_least.h:41:19
    #5 0x55d6ae004de8 in std::__1::__split_buffer<llvm::WeakTrackingVH, std::__1::allocator<llvm::WeakTrackingVH>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<llvm::WeakTrackingVH>&) /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/__split_buffer:343:25
    #6 0x55d6ae00496e in llvm::WeakTrackingVH* std::__1::vector<llvm::WeakTrackingVH, std::__1::allocator<llvm::WeakTrackingVH>>::__push_back_slow_path<llvm::WeakTrackingVH>(llvm::WeakTrackingVH&&) /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/vector:1468:47
    #7 0x55d6b18384bf in push_back /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/vector:1496:13
    #8 0x55d6b18384bf in (anonymous namespace)::MergeFunctions::runOnModule(llvm::Module&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Transforms/IPO/MergeFunctions.cpp:431:16
    #9 0x55d6b183667d in llvm::MergeFunctionsPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Transforms/IPO/MergeFunctions.cpp:300:11
    #10 0x55d6b0450d71 in llvm::detail::PassModel<llvm::Module, llvm::MergeFunctionsPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:89:17
    #11 0x55d6aca6b1f5 in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/IR/PassManager.h:543:40
    #12 0x55d6b02f48c8 in llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::__1::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/opt/NewPMDriver.cpp:532:7
    #13 0x55d6ac3a2f76 in optMain /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/opt/optdriver.cpp:741:12
    #14 0x7f21e6a23a8f  (/lib/x86_64-linux-gnu/libc.so.6+0x23a8f) (BuildId: d320ce4e63925d698610ed423fc4b1f0e8ed51f1)
```

https://github.com/llvm/llvm-project/pull/76657


More information about the libcxx-commits mailing list