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

Fix all warnings & Add option TREAT_WARING_AS_ERROR to cmake #5751

Merged
merged 19 commits into from
Aug 10, 2021

Conversation

PragmaTwice
Copy link
Contributor

@PragmaTwice PragmaTwice commented Aug 5, 2021

Done:

  • fixed (almost) all warnings (in clang 12):
  • add TREAT_WARING_AS_ERROR option:
    • turned ON by default, but OFF in build and test ci (not simple ci) for not blocking merging unexpectedly
    • some error are turned off due to several special reason, including:
      • unused-const-variable unused-private-field unused-variable unused-local-typedef unused-lambda-capture instantiation-after-specialization: disable unused-* for different compile mode (maybe unused in cpu.cmake, but used in cuda.cmake)
      • deprecated-declarations: wait for all deprecated calls are fixed, then it will be removed
      • literal-conversion: wait for 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, then it will be removed
  • add gcc (version 7, 11) and clang (version 12) support
  • tested in cuda mode (with gcc)

Notice:

  • move operation in return std::move(local_var) is unnecessary because it is guaranteed the returned local variable will be moved in the standard, and the move operation here will prevent a special optimization in compiler called named return value optimization (NRVO).
  • move operation in macro CHECK_OK is removed because it will prevent RVO and developer is hard to know a macro which will implicitly do rvalue cast. (parameter type of MaybeIsOK is a rvalue reference, so for a origin rvalue, like f(x), it just works without move, and for an lvalue, a compile error is preferred)

Discovered Problems:

In oneflow/core/job/job_build_and_infer_ctx_mgr.cpp:

 Maybe<void> JobBuildAndInferCtxMgr::OpenJobBuildAndInferCtx(const std::string& job_name) {
-  CHECK_OR_RETURN(!has_cur_job_) << Error::UnknownJobBuildAndInferError
+  CHECK_OR_RETURN(!has_cur_job_) << Error::UnknownJobBuildAndInferError()
                                  << "cur job not leave before you enter this job_name:" << job_name;

In oneflow/user/kernels/upsample_kernel.h:

oneflow/user/kernels/upsample_kernel.h:141:9:
error: implicit conversion from 'double' to 'int' changes value from -0.75 to 0 [-Wliteral-conversion]

@@ -1165,7 +1165,7 @@ Maybe<void> InstructionsBuilder::StatefulCall(
};

const auto GetDelegateBlobObject =
[this, &FetchDelegateBlobObject](
[&FetchDelegateBlobObject](
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是什么原因需要捕获this的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是很清楚,可能之前有用到后来删掉了?不过这个 lambda 应该确实不需要捕获 this

Copy link
Contributor

@daquexian daquexian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改一下 CI,在 .github/workflows/test.yml:137 这些地方加上 -DTREAT_WARNINGS_AS_ERRORS=OFF 吧

@@ -126,10 +127,7 @@ if(WIN32)
#set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS} /DEBUG:FASTLINK")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_ITERATOR_DEBUG_LEVEL=0")
else()
set(EXTRA_CXX_FLAGS "-std=c++11 -Wall -Wno-sign-compare -Wno-unused-function -fPIC -Werror=return-type")
if (APPLE)
set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -Wno-deprecated-declarations -Wno-mismatched-tags")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 -Wno-deprecated-declarations 现在被换成了 -Wno-error=deprecated-declarations?是不是行为不一样

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,-Wno-deprecated-declarations 是不报出 deprecated-declarations 类型的警告,-Wno-error=deprecated-declarations 是报出 deprecated-declarations 类型的警告但不将其视为错误,我感觉这里报出来但不视为错误更合理一些

@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 10, 2021 01:35
@oneflow-ci-bot oneflow-ci-bot self-requested a review August 10, 2021 04:00
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 10, 2021 06:37
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 10, 2021 08:35
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 10, 2021 10:30
@oneflow-ci-bot oneflow-ci-bot merged commit 3aa6752 into Oneflow-Inc:master Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants