-
Notifications
You must be signed in to change notification settings - Fork 3k
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 SDL warnings in CPU EP #9975
Conversation
orttraining/orttraining/test/graph/optimizer_graph_builder_test.cc
Outdated
Show resolved
Hide resolved
orttraining/orttraining/test/graph/optimizer_graph_builder_test.cc
Outdated
Show resolved
Hide resolved
ed05fe4
to
02dfabb
Compare
9ad19d4
to
5ae6b24
Compare
@@ -253,13 +254,6 @@ void LogRuntimeError(uint32_t session_id, const common::Status& status, const ch | |||
} \ | |||
} while (0) | |||
|
|||
// C++ Core Guideline check suppression. | |||
#if defined(_MSC_VER) && !defined(__NVCC__) && !defined(__clang__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved it to a new file because onnxruntime::Status also wants to use this macro. But this file includes "core/common/status.h"
@@ -37,7 +37,7 @@ class KernelRegistry { | |||
// TODO(Task:132) Make usage of unique_ptr/shared_ptr as out param consistent | |||
Status TryCreateKernel(const Node& node, const IExecutionProvider& execution_provider, | |||
const std::unordered_map<int, OrtValue>& constant_initialized_tensors, | |||
const OrtValueNameIdxMap& mlvalue_name_idx_map, const FuncManager& funcs_mgr, | |||
const OrtValueNameIdxMap& mlvalue_name_idx_map, FuncManager& funcs_mgr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change funcs_mgr to non-const. Because this function may modify funcs_mgr's internal states. Previously we hided the fact.
using KernelCreateFn = std::function<OpKernel*(const OpKernelInfo& info)>; | ||
using KernelCreatePtrFn = std::add_pointer<OpKernel*(const OpKernelInfo& info)>::type; | ||
class FuncManager; | ||
using KernelCreateFn = std::function<Status(FuncManager& func_mgr, const OpKernelInfo& info, std::unique_ptr<OpKernel>& out)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use unique_ptr to replace raw pointer. And make it be more obvious that it depends on a non-const FuncManager.
@@ -950,8 +950,14 @@ struct CustomOpBase : OrtCustomOp { | |||
OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); }; | |||
|
|||
OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) { static_cast<TKernel*>(op_kernel)->Compute(context); }; | |||
#if defined(_MSC_VER) && !defined(__clang__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file can not use GSL macros. Because it is directly used by outside users.
@@ -50,7 +50,7 @@ struct ConvTransposeAttributes : public ConvAttributes { | |||
const TensorShape& F_Shape = (filter_shape != nullptr) ? *filter_shape : F->Shape(); | |||
const Tensor* Pads = dynamic_padding ? context->Input<Tensor>(2) : nullptr; | |||
const Tensor* B = has_bias ? (dynamic_padding ? context->Input<Tensor>(3) : context->Input<Tensor>(2)) : nullptr; | |||
const TensorShape& input_shape = X->Shape().Slice(2); | |||
TensorShape input_shape = X->Shape().Slice(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change fixed a bug.
The small program below reproduces the issue:
void BadCode(const std::string& s) {
std::string p = std::move(s);
std::cout << p << std::endl;
}
int _tmain(int argc, TCHAR* argv[])
{
std::string s = "abc";
std::cout << s << std::endl; //now it is empty.
return 0;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the comment read - s "may" be empty after calling BadCode() ? I think the standard only expects that the source object is in a "valid" state after std::move is invoked (which may not necessarily be empty).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right.
Description:
When this PR is checked in, if you have code like:
It will be rejected by static analyzer. Because 26400 is in our SDL.rules file. You may convert it to:
We still have a lot C26451 warnings that I couldn't get them fixed this time. So I disabled them to make the CI pass. Next, I will add "C26406 DONT_ASSIGN_RAW_TO_OWNER" to the warning list.
To try the static analyzer locally, please open CMakeLists.txt and uncomment the following lines:
Then build it with "--extra_cmake_defines onnxruntime_ENABLE_STATIC_ANALYSIS=ON".
Motivation and Context
To meet compliance requirement and have better code quality. For example, C26478 is one of the warnings we will enable through this PR. And it helped me found a bug in conv_transpose_attributes.h