diff --git a/CMakeLists.txt b/CMakeLists.txt index ce06ed9de9aa2233d2eb53b7f961832d0ebf73cc..5086a02da05baf5544b49a04ff865379eeb8067c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,6 @@ # ====================================================================================================================== cmake_minimum_required(VERSION 3.14) -set(CMAKE_CXX_STANDARD 14) project (MetaDef[CXX]) # 存在`.dev_env`文件说明是蓝区开发环境,并且调用了`prepare_dev_env.sh`完成了开发环境准备 diff --git a/cmake/intf_pub_linux.cmake b/cmake/intf_pub_linux.cmake index 8759908723d370272e0659c175410b81c34ca3c8..39935e86a365810e41f81e126d391126ae740442 100644 --- a/cmake/intf_pub_linux.cmake +++ b/cmake/intf_pub_linux.cmake @@ -12,79 +12,80 @@ if (TARGET intf_pub) return() endif() -add_library(intf_pub INTERFACE) +########## intf_pub_base ########## +add_library(intf_pub_base INTERFACE) -target_compile_options(intf_pub INTERFACE - -Wall - -fPIC +target_compile_options(intf_pub_base INTERFACE + -Wall + -fPIC $,-fstack-protector-all,-fstack-protector-strong> - $<$:-std=c++11> ) -target_compile_definitions(intf_pub INTERFACE - _GLIBCXX_USE_CXX11_ABI=0 + +target_compile_definitions(intf_pub_base INTERFACE + _GLIBCXX_USE_CXX11_ABI=0 $<$:CFG_BUILD_NDEBUG> - $<$:CFG_BUILD_DEBUG> - WIN64=1 + $<$:CFG_BUILD_DEBUG> LINUX=0 LOG_CPP + $<$:SUPPORT_LARGE_MODEL_ENABLE=1> ) -target_link_options(intf_pub INTERFACE + +target_link_options(intf_pub_base INTERFACE -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack - $<$:-Wl,--build-id=none> + $<$:-Wl,--build-id=none> ) -target_link_directories(intf_pub INTERFACE -) -target_link_libraries(intf_pub INTERFACE + +target_link_libraries(intf_pub_base INTERFACE -lpthread ) -# intf_pub_base -add_library(intf_pub_base INTERFACE) -target_compile_options(intf_pub_base INTERFACE - -Wall - -fPIC - $,-fstack-protector-all,-fstack-protector-strong> -) -target_compile_definitions(intf_pub_base INTERFACE - _GLIBCXX_USE_CXX11_ABI=0 - $<$:CFG_BUILD_NDEBUG> - $<$:CFG_BUILD_DEBUG> - LINUX=0 - LOG_CPP - $<$:ENABLE_AIR_D_TEST> - $<$:SUPPORT_LARGE_MODEL_ENABLE=1> +########## intf_pub ########## +add_library(intf_pub INTERFACE) + +target_compile_options(intf_pub INTERFACE + $<$:-std=c++17> ) -target_link_options(intf_pub_base INTERFACE - -Wl,-z,relro - -Wl,-z,now - -Wl,-z,noexecstack - $<$:-Wl,--build-id=none> + +target_link_libraries(intf_pub INTERFACE + $ ) -target_link_directories(intf_pub_base INTERFACE + +########## intf_pub c++11 ########## +add_library(intf_pub_cxx11 INTERFACE) + +target_compile_options(intf_pub_cxx11 INTERFACE + $<$:-std=c++11> ) -target_link_libraries(intf_pub_base INTERFACE - -lpthread + +target_link_libraries(intf_pub_cxx11 INTERFACE + $ ) -# intf_pub c++14 +########## intf_pub c++14 ########## add_library(intf_pub_cxx14 INTERFACE) + target_compile_options(intf_pub_cxx14 INTERFACE - $<$:-std=c++14> + $<$:-std=c++14> ) + target_link_libraries(intf_pub_cxx14 INTERFACE - $ + $ ) +########## intf_pub c++17 ########## add_library(intf_pub_cxx17 INTERFACE) + target_compile_options(intf_pub_cxx17 INTERFACE - $<$:-std=c++17> + $<$:-std=c++17> ) + target_link_libraries(intf_pub_cxx17 INTERFACE - $ + $ ) +########## ccache ########## find_program(CCACHE_FOUND ccache) if (CCACHE_FOUND) set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_FOUND} CACHE PATH "cache Compiler") diff --git a/cmake/third_party/build/modules/Findsymengine.cmake b/cmake/third_party/build/modules/Findsymengine.cmake index f48a0a4f0ead4c4c84d23107254aae0d8360d3f9..1549dd7aa2ce99a545ef26113e70853df2c563bb 100644 --- a/cmake/third_party/build/modules/Findsymengine.cmake +++ b/cmake/third_party/build/modules/Findsymengine.cmake @@ -19,7 +19,7 @@ else () set(REQ_URL "https://gitee.com/mirrors/SymEngine/repository/archive/v0.11.1.zip") endif () -set(SYMENGINE_CXXFLAGS "--std=c++14 -O2 -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -s -D_FORTIFY_SOURCE=2 -Wno-maybe-uninitialized -Wno-unused-parameter -D_GLIBCXX_USE_CXX11_ABI=0 -Wl,-Bsymbolic") +set(SYMENGINE_CXXFLAGS "-O2 -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -s -D_FORTIFY_SOURCE=2 -Wno-maybe-uninitialized -Wno-unused-parameter -D_GLIBCXX_USE_CXX11_ABI=0 -Wl,-Bsymbolic") ExternalProject_Add(symengine_build URL ${REQ_URL} @@ -30,7 +30,7 @@ ExternalProject_Add(symengine_build -DBUILD_SHARED_LIBS:BOOL=OFF -DBOOST_ROOT=${CMAKE_INSTALL_PREFIX}/boost -DBUILD_TESTS=off - -DCMAKE_CXX_STANDARD=14 + -DCMAKE_CXX_STANDARD=17 -DWITH_SYMENGINE_THREAD_SAFE:BOOL=ON -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_CXX_FLAGS=${SYMENGINE_CXXFLAGS} diff --git a/graph/CMakeLists.txt b/graph/CMakeLists.txt index 8b63178bd88aa002978546627319d448160eecd1..aec03f3bd8b9887ffaf1ec731171780dde9c422a 100644 --- a/graph/CMakeLists.txt +++ b/graph/CMakeLists.txt @@ -9,8 +9,6 @@ include(${METADEF_DIR}/cmake/build_type.cmake) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) ######### for base ############# set(GRAPH_BASE_SOURCE_LIST "type/types.cc" diff --git a/graph/ascendc_ir/CMakeLists.txt b/graph/ascendc_ir/CMakeLists.txt index 646bb646b40dcb5ce9aec8485747fdcc3eacb091..30f3bd57aef6470823b37df76c985b4be3a04285 100644 --- a/graph/ascendc_ir/CMakeLists.txt +++ b/graph/ascendc_ir/CMakeLists.txt @@ -34,7 +34,7 @@ target_link_options(aihac_ir PRIVATE target_link_libraries(aihac_ir PRIVATE - intf_pub_cxx17 + intf_pub static_mmpa -Wl,--no-as-needed c_sec diff --git a/graph/expression/CMakeLists.txt b/graph/expression/CMakeLists.txt index 08c7f8b34c74c6a449014aa5e8e3549ae717003c..9d183755a2538f44916442e4e4f8bfe0f8eef4ae 100644 --- a/graph/expression/CMakeLists.txt +++ b/graph/expression/CMakeLists.txt @@ -39,7 +39,7 @@ target_link_options(aihac_symbolizer PRIVATE target_link_libraries(aihac_symbolizer PRIVATE - intf_pub_cxx14 + intf_pub static_mmpa -Wl,--no-as-needed c_sec @@ -61,6 +61,4 @@ target_link_libraries(aihac_symbolizer metadef_headers ) set_target_properties(aihac_symbolizer PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO) diff --git a/graph/fast_graph/fast_graph_utils.h b/graph/fast_graph/fast_graph_utils.h index 2e463589f651a8068e0c50c71e793c19f57cc97e..a74f715db329c9208ab8a96613a21799571e0c6e 100644 --- a/graph/fast_graph/fast_graph_utils.h +++ b/graph/fast_graph/fast_graph_utils.h @@ -104,7 +104,8 @@ class FastGraphUtils { } static inline QuickNode *GetListElementAddr(const FastNode *const fast_node) { - return reinterpret_cast(reinterpret_cast(fast_node) - offsetof(QuickNode, data)); + const auto offset = reinterpret_cast(&reinterpret_cast(0)->data); + return reinterpret_cast(reinterpret_cast(fast_node) - offset); } static inline QuickEdge *GetListElementAddr(const FastEdge *const edge) { diff --git a/inc/graph/small_vector.h b/inc/graph/small_vector.h index cd28671e1ae548c7a2704da6be549dba9ccccdcf..0b38afef991fed4a8d4d82e36e57a797639bd233 100644 --- a/inc/graph/small_vector.h +++ b/inc/graph/small_vector.h @@ -217,7 +217,8 @@ class SmallVector { void clear() noexcept { T *addr = begin(); while (addr != end()) { - allocator_.destroy(addr++); + addr->~T(); + ++addr; } FreeStorage(); capacity_ = N; @@ -254,8 +255,7 @@ class SmallVector { iterator emplace(const_iterator const pos, Args &&...args) { const auto index = static_cast(std::distance(cbegin(), pos)); auto const iter = Expand(index, 1UL); - allocator_.construct(iter, std::forward(args)...); - + new (iter) T(std::forward(args)...); return iter; } iterator erase(const_iterator const pos) { @@ -274,16 +274,16 @@ class SmallVector { } void push_back(const T &value) { auto const iter = Expand(size_, 1UL); - allocator_.construct(iter, value); + new (iter) T(value); } void push_back(T &&value) { auto const iter = Expand(size_, 1UL); - allocator_.construct(iter, std::move(value)); + new (iter) T(std::move(value)); } template void emplace_back(Args &&...args) { auto const iter = Expand(size_, 1UL); - allocator_.construct(iter, std::forward(args)...); + new (iter) T(std::forward(args)...); } void pop_back() { Shrink(size_ - 1, size_); @@ -295,7 +295,8 @@ class SmallVector { const auto expand_size = count - size_; auto iter = Expand(size_, expand_size); for (size_type i = 0UL; i < expand_size; ++i) { - allocator_.construct(iter++); + new (static_cast(iter)) T(); + ++iter; } } } @@ -362,7 +363,8 @@ class SmallVector { iterator ClearElements() { T *addr = GetPointer(); while (addr != end()) { - allocator_.destroy(addr++); + addr->~T(); + ++addr; } return GetPointer(); } @@ -382,8 +384,10 @@ class SmallVector { auto addr = PtrToPtr(&inline_storage_); auto other_addr = other.GetPointer(); for (size_type i = 0UL; i < size_; ++i) { - allocator_.construct(addr++, std::move(*other_addr)); - allocator_.destroy(other_addr++); + new (addr) T(std::move(*other_addr)); + ++addr; + other_addr->~T(); + ++other_addr; } allocated_storage_ = nullptr; } @@ -411,14 +415,18 @@ class SmallVector { auto new_ptr = new_storage; auto old_ptr = old_storage; for (size_type i = 0UL; i < range_begin; ++i) { - allocator_.construct(new_ptr++, std::move(*old_ptr)); - allocator_.destroy(old_ptr++); + new (new_ptr) T(std::move(*old_ptr)); + ++new_ptr; + old_ptr->~T(); + ++old_ptr; } new_ptr = PtrAdd(new_ptr, new_cap + 1UL, range_len); for (size_type i = range_begin; i < size_; ++i) { - allocator_.construct(new_ptr++, std::move(*old_ptr)); - allocator_.destroy(old_ptr++); + new (new_ptr) T(std::move(*old_ptr)); + ++new_ptr; + old_ptr->~T(); + ++old_ptr; } FreeStorage(); @@ -431,8 +439,10 @@ class SmallVector { auto old_end = GetPointer(size_ - 1UL); auto new_end = GetPointer(size_ + range_len - 1UL); for (size_type i = size_; i > range_begin; --i) { - allocator_.construct(new_end--, std::move(*old_end)); - allocator_.destroy(old_end--); + new (new_end) T(std::move(*old_end)); + --new_end; + old_end->~T(); + --old_end; } size_ += range_len; return begin_storage; @@ -449,13 +459,16 @@ class SmallVector { void Shrink(const size_type range_begin, const size_type range_end) { T *old_ptr = GetPointer(range_begin); for (size_type i = range_begin; i < range_end; ++i) { - allocator_.destroy(old_ptr++); + old_ptr->~T(); + ++old_ptr; } size_type new_size = range_begin; T *new_ptr = GetPointer(range_begin); for (size_type i = range_end; i < size_; ++i) { - allocator_.construct(new_ptr++, std::move(*old_ptr)); - allocator_.destroy(old_ptr++); + new (new_ptr) T(std::move(*old_ptr)); + ++new_ptr; + old_ptr->~T(); + ++old_ptr; ++new_size; } size_ = new_size; diff --git a/tests/benchmark/fast_graph/CMakeLists.txt b/tests/benchmark/fast_graph/CMakeLists.txt index 3f2ed9739163db589e6b69d1708c23db60c48cac..7bb51bd251b20d3d3f5a72ff3cd2f5e11816b9cd 100644 --- a/tests/benchmark/fast_graph/CMakeLists.txt +++ b/tests/benchmark/fast_graph/CMakeLists.txt @@ -7,8 +7,6 @@ # See LICENSE in the root of the software repository for the full text of the License. # ====================================================================================================================== -set(CMAKE_CXX_STANDARD 11) - set(BENCHMARK_TEST "compute_graph_base_unittest.cc") add_executable(fast_graph_benchmark ${BENCHMARK_TEST}) diff --git a/tests/ut/error_manager/CMakeLists.txt b/tests/ut/error_manager/CMakeLists.txt index 9aaa029a7a58512213f1b5604bb41d47f1112dae..67602389c683c4b8ec8a710e57281c155ef965d0 100644 --- a/tests/ut/error_manager/CMakeLists.txt +++ b/tests/ut/error_manager/CMakeLists.txt @@ -7,8 +7,6 @@ # See LICENSE in the root of the software repository for the full text of the License. # ====================================================================================================================== -set(CMAKE_CXX_STANDARD 11) - # include directories include_directories(${CMAKE_CURRENT_LIST_DIR}) include_directories(${METADEF_DIR}/error_manager) diff --git a/tests/ut/expression/CMakeLists.txt b/tests/ut/expression/CMakeLists.txt index 56118826389069999fde50e3ddde200de9906eba..e8d6b98be345d612be5a46a9bef45db0bbbff226 100644 --- a/tests/ut/expression/CMakeLists.txt +++ b/tests/ut/expression/CMakeLists.txt @@ -7,7 +7,6 @@ # See LICENSE in the root of the software repository for the full text of the License. # ====================================================================================================================== -set(CMAKE_CXX_STANDARD 14) # include directories include_directories(${CMAKE_CURRENT_LIST_DIR}) include_directories(${METADEF_DIR}/inc/common/util/trace_manager) diff --git a/tests/ut/graph/CMakeLists.txt b/tests/ut/graph/CMakeLists.txt index 585115e5f3cb39d9b04708e57bd8a73832b164a9..3245184d654c4b14dfbc37ad59cec612a5ff58ce 100644 --- a/tests/ut/graph/CMakeLists.txt +++ b/tests/ut/graph/CMakeLists.txt @@ -7,8 +7,6 @@ # See LICENSE in the root of the software repository for the full text of the License. # ====================================================================================================================== -set(CMAKE_CXX_STANDARD 14) - # include directories include_directories(${CMAKE_CURRENT_LIST_DIR}) include_directories(${METADEF_DIR}/inc/common/util/trace_manager) diff --git a/tests/ut/register/CMakeLists.txt b/tests/ut/register/CMakeLists.txt index c3c0cfe81ad7aa9bcac5f542920d2f02f5ca6820..3dd9519b21fafc0311b55c8fe6874b6632131880 100644 --- a/tests/ut/register/CMakeLists.txt +++ b/tests/ut/register/CMakeLists.txt @@ -7,7 +7,6 @@ # See LICENSE in the root of the software repository for the full text of the License. # ====================================================================================================================== -set(CMAKE_CXX_STANDARD 14) # include directories include_directories(${CMAKE_CURRENT_LIST_DIR}) include_directories(${CMAKE_BINARY_DIR}/proto/ge)