diff --git a/CMakeLists.txt b/CMakeLists.txt index 00bb5c4f3..158a6c69a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,20 @@ else() ) endif() +set(IS_ACC OFF CACHE INTERNAL "Whether the current compiler is ACC") +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +try_compile(IS_ACC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/cmake/IsACC.cpp) +if (${IS_ACC}) + message("-- Using ACC") + # It is super rare that the destructor of an exception can be throwable. + # But such little probability prevents optimizations for coroutines + # significantly. + # Since the the body of coroutines are wrapped into a big try-catch. + # So the coroutines can be marked as noexcept automatically if all its + # promise functions and the allocation functions matches the behavior. + list(APPEND CXX_FLAGS "-fdisable-exception-with-may-throw-dtor") +endif() + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") list(APPEND CXX_FLAGS "-fcoroutines") endif() diff --git a/cmake/IsACC.cpp b/cmake/IsACC.cpp new file mode 100644 index 000000000..70b749723 --- /dev/null +++ b/cmake/IsACC.cpp @@ -0,0 +1,3 @@ +#ifndef __alibaba_clang__ +#error "The current compiler is not ACC" +#endif