Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: disable array-bounds check & treat warnings as errors for pyextobj and oneflow_internal & fix warnings #5838

Merged
merged 7 commits into from
Aug 12, 2021
56 changes: 31 additions & 25 deletions cmake/oneflow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,32 @@ function(oneflow_add_library)
endif()
endfunction()

function(target_treat_warnings_as_errors target)
if (TREAT_WARNINGS_AS_ERRORS)
target_compile_options(${target} PRIVATE -Werror)

# TODO: remove it while fixing all deprecated call
target_compile_options(${target} PRIVATE -Wno-error=deprecated-declarations)

# disable unused-* for different compile mode (maybe unused in cpu.cmake, but used in cuda.cmake)
target_compile_options(${target} PRIVATE -Wno-error=unused-const-variable)
target_compile_options(${target} PRIVATE -Wno-error=unused-variable)
target_compile_options(${target} PRIVATE -Wno-error=unused-local-typedefs)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${target} PRIVATE -Wno-error=unused-private-field)
target_compile_options(${target} PRIVATE -Wno-error=unused-lambda-capture)

target_compile_options(${target} PRIVATE -Wno-error=instantiation-after-specialization)

# the mangled name between `struct X` and `class X` is different in MSVC ABI, remove it while windows is supported (in MSVC/cl or clang-cl)
target_compile_options(${target} PRIVATE -Wno-error=mismatched-tags)
endif()

# disable for pointer operations of intrusive linked lists
target_compile_options(${target} PRIVATE -Wno-error=array-bounds)
PragmaTwice marked this conversation as resolved.
Show resolved Hide resolved
endif()
endfunction()

# source_group
if(WIN32)
set(oneflow_platform "windows")
Expand Down Expand Up @@ -257,31 +283,7 @@ if (BUILD_SHARED_LIBS)
endif()

target_compile_options(of_ccobj PRIVATE -Werror=return-type)

if (TREAT_WARNINGS_AS_ERRORS)
target_compile_options(of_ccobj PRIVATE -Werror)

# TODO: remove it while fixing all deprecated call
target_compile_options(of_ccobj PRIVATE -Wno-error=deprecated-declarations)

# disable unused-* for different compile mode (maybe unused in cpu.cmake, but used in cuda.cmake)
target_compile_options(of_ccobj PRIVATE -Wno-error=unused-const-variable)
target_compile_options(of_ccobj PRIVATE -Wno-error=unused-variable)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(of_ccobj PRIVATE -Wno-error=unused-private-field)
target_compile_options(of_ccobj PRIVATE -Wno-error=unused-local-typedef)
target_compile_options(of_ccobj PRIVATE -Wno-error=unused-lambda-capture)
target_compile_options(of_ccobj PRIVATE -Wno-error=instantiation-after-specialization)
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# the mangled name between `struct X` and `class X` is different in MSVC ABI, remove it while windows is supported (in MSVC/cl or clang-cl)
target_compile_options(of_ccobj PRIVATE -Wno-error=mismatched-tags)

# TODO: remove it while `oneflow/user/kernels/upsample_kernel.h:141:9: error: implicit conversion from 'double' to 'int' changes value from -0.75 to 0 [-Wliteral-conversion]` is fixed
target_compile_options(of_ccobj PRIVATE -Wno-error=literal-conversion)
endif()
endif()
target_treat_warnings_as_errors(of_ccobj)

# py ext lib
add_library(of_pyext_obj ${of_pyext_obj_cc})
Expand All @@ -292,6 +294,7 @@ if(BUILD_SHARED_LIBS AND APPLE)
endif()
add_dependencies(of_pyext_obj of_ccobj)
target_compile_options(of_pyext_obj PRIVATE -Werror=return-type)
target_treat_warnings_as_errors(of_pyext_obj)

if(APPLE)
set(of_libs -Wl,-force_load ${ONEFLOW_CUDA_LIBS} of_ccobj of_protoobj of_cfgobj)
Expand All @@ -310,6 +313,9 @@ set_target_properties(oneflow_internal PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${ON
target_link_libraries(oneflow_internal PRIVATE ${of_libs} ${oneflow_third_party_libs} of_pyext_obj ${oneflow_exe_third_party_libs})
target_include_directories(oneflow_internal PRIVATE ${Python_INCLUDE_DIRS} ${Python_NumPy_INCLUDE_DIRS})

target_compile_options(oneflow_internal PRIVATE -Werror=return-type)
target_treat_warnings_as_errors(oneflow_internal)

set(gen_pip_args "")
if (BUILD_CUDA)
list(APPEND gen_pip_args --cuda=${CUDA_VERSION})
Expand Down
2 changes: 1 addition & 1 deletion oneflow/api/python/functional/python_arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct AnyDataBase {
};

template<typename T>
struct AnyData : public AnyDataBase {
struct AnyData final : public AnyDataBase {
T content;
explicit AnyData(const T& v) : content(v) {}

Expand Down
2 changes: 1 addition & 1 deletion oneflow/core/framework/eager_blob_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace oneflow {

namespace compatible_py {

class EagerPhysicalBlobHeader : public BlobHeaderTrait {
class EagerPhysicalBlobHeader final : public BlobHeaderTrait {
public:
EagerPhysicalBlobHeader(const std::shared_ptr<Shape>& static_shape,
const std::shared_ptr<Shape>& shape, DataType dtype);
Expand Down
2 changes: 1 addition & 1 deletion oneflow/user/ops/batch_gather_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ REGISTER_USER_OP("batch_gather")
.PartialSum(user_op::OpArg("out", 0))
.Build();
} else {
std::shared_ptr<cfg::ErrorProto> err;
auto err = std::make_shared<cfg::ErrorProto>();
err->set_msg("BatchGatherOp: indices_num_axes equals " + std::to_string(indices_num_axes)
+ " (should be bigger than 1).");
err->mutable_check_failed_error();
Expand Down