Skip to content

Compilation error InsertHoistableInstruction on GCC15 #384

@jeroenbakker-atmind

Description

@jeroenbakker-atmind

This lambda expression isDuplicate in InsertHoistableInstruction performs a copy of the instruction list, which cannot be safely destroyed. (Error when compiling using GCC15)

In file included from /usr/include/x86_64-linux-gnu/c++/15/bits/c++allocator.h:33,
                 from /usr/include/c++/15/bits/allocator.h:46,
                 from /usr/include/c++/15/string:45,
                 from /home/jeroen/blender-git/build_linux/deps_x64/build/igc/src/external_igc-build/IGC/llvm-deps-15.0.7/src/llvm/include/llvm/ADT/Hashing.h:54,
                 from /home/jeroen/blender-git/build_linux/deps_x64/build/igc/src/external_igc-build/IGC/llvm-deps-15.0.7/src/llvm/include/llvm/ADT/ArrayRef.h:12,
                 from /home/jeroen/blender-git/build_linux/deps_x64/build/igc/src/external_igc-build/IGC/llvm-deps-15.0.7/src/llvm/include/llvm/Analysis/AssumptionCache.h:18,
                 from /home/jeroen/blender-git/build_linux/deps_x64/build/igc/src/external_igc/IGC/Compiler/CISACodeGen/helper.h:12,
                 from /home/jeroen/blender-git/build_linux/deps_x64/build/igc/src/external_igc/IGC/Compiler/Optimizer/InstructionHoistingOptimization.cpp:10:
In member function ‘void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = llvm::Instruction*]’,
    inlined from ‘constexpr void std::allocator< <template-parameter-1-1> >::deallocate(_Tp*, std::size_t) [with _Tp = llvm::Instruction*]’ at /usr/include/c++/15/bits/allocator.h:215:35,
    inlined from ‘static constexpr void std::allocator_traits<std::allocator<_CharT> >::deallocate(allocator_type&, pointer, size_type) [with _Tp = llvm::Instruction*]’ at /usr/include/c++/15/bits/alloc_traits.h:649:23,
    inlined from ‘constexpr void std::_Vector_base<_Tp, _Alloc>::_M_deallocate(pointer, std::size_t) [with _Tp = llvm::Instruction*; _Alloc = std::allocator<llvm::Instruction*>]’ at /usr/include/c++/15/bits/stl_vector.h:396:19,
    inlined from ‘constexpr void std::_Vector_base<_Tp, _Alloc>::_M_deallocate(pointer, std::size_t) [with _Tp = llvm::Instruction*; _Alloc = std::allocator<llvm::Instruction*>]’ at /usr/include/c++/15/bits/stl_vector.h:392:7,
    inlined from ‘constexpr std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = llvm::Instruction*; _Alloc = std::allocator<llvm::Instruction*>]’ at /usr/include/c++/15/bits/stl_vector.h:375:15,
    inlined from ‘constexpr std::vector<_Tp, _Alloc>::~vector() [with _Tp = llvm::Instruction*; _Alloc = std::allocator<llvm::Instruction*>]’ at /usr/include/c++/15/bits/stl_vector.h:805:7,
    inlined from ‘void IGC::InstructionHoistingOptimization::InsertHoistableInstruction(llvm::Instruction*)’ at /home/jeroen/blender-git/build_linux/deps_x64/build/igc/src/external_igc/IGC/Compiler/Optimizer/InstructionHoistingOptimization.cpp:153:21:
/usr/include/c++/15/bits/new_allocator.h:172:66: error: ‘void operator delete(void*, std::size_t)’ called on pointer ‘<unknown>’ with nonzero offset [8, 9223372036854775800] [-Werror=free-nonheap-object]
  172 |         _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
      |                                                                  ^
In member function ‘_Tp* std::__new_allocator<_Tp>::allocate(size_type, const void*) [with _Tp = llvm::Instruction*]’,
    inlined from ‘constexpr _Tp* std::allocator< <template-parameter-1-1> >::allocate(std::size_t) [with _Tp = llvm::Instruction*]’ at /usr/include/c++/15/bits/allocator.h:203:40,
    inlined from ‘static constexpr _Tp* std::allocator_traits<std::allocator<_CharT> >::allocate(allocator_type&, size_type) [with _Tp = llvm::Instruction*]’ at /usr/include/c++/15/bits/alloc_traits.h:614:28,
    inlined from ‘constexpr std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = llvm::Instruction*; _Alloc = std::allocator<llvm::Instruction*>]’ at /usr/include/c++/15/bits/stl_vector.h:387:33,
    inlined from ‘constexpr void std::_Vector_base<_Tp, _Alloc>::_M_create_storage(std::size_t) [with _Tp = llvm::Instruction*; _Alloc = std::allocator<llvm::Instruction*>]’ at /usr/include/c++/15/bits/stl_vector.h:405:44,
    inlined from ‘constexpr std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t, const allocator_type&) [with _Tp = llvm::Instruction*; _Alloc = std::allocator<llvm::Instruction*>]’ at /usr/include/c++/15/bits/stl_vector.h:341:26,
    inlined from ‘constexpr std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = llvm::Instruction*; _Alloc = std::allocator<llvm::Instruction*>]’ at /usr/include/c++/15/bits/stl_vector.h:633:61,
    inlined from ‘void IGC::InstructionHoistingOptimization::InsertHoistableInstruction(llvm::Instruction*)’ at /home/jeroen/blender-git/build_linux/deps_x64/build/igc/src/external_igc/IGC/Compiler/Optimizer/InstructionHoistingOptimization.cpp:153:21:
/usr/include/c++/15/bits/new_allocator.h:151:73: note: returned from ‘void* operator new(std::size_t)’
  151 |         return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp)));
      |                                                                         ^

auto isDuplicate = [](std::vector<Instruction *> hoistedInstr, Instruction *newInstr) -> bool {

This was fixed by passing by reference.

diff --git a/IGC/Compiler/Optimizer/InstructionHoistingOptimization.cpp b/IGC/Compiler/Optimizer/InstructionHoistingOptimization.cpp
index 838ea8b..a821e3b 100644
--- a/IGC/Compiler/Optimizer/InstructionHoistingOptimization.cpp
+++ b/IGC/Compiler/Optimizer/InstructionHoistingOptimization.cpp
@@ -145,7 +145,7 @@ private:
   }
 
   inline void InsertHoistableInstruction(Instruction *hoistInstr) {
-    auto isDuplicate = [](std::vector<Instruction *> hoistedInstr, Instruction *newInstr) -> bool {
+    auto isDuplicate = [](const std::vector<Instruction *> &hoistedInstr, Instruction *newInstr) -> bool {
       auto it = std::find(hoistedInstr.begin(), hoistedInstr.end(), newInstr);
       return it != hoistedInstr.end();
     };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions