Skip to content

Commit

Permalink
Fix SDL warnings in CPU EP (microsoft#9975)
Browse files Browse the repository at this point in the history
  • Loading branch information
snnn authored Dec 20, 2021
1 parent bd4fb4c commit 4e9e01c
Show file tree
Hide file tree
Showing 188 changed files with 1,329 additions and 954 deletions.
9 changes: 6 additions & 3 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,6 @@ if (onnxruntime_USE_MIGRAPHX)
list(APPEND ORT_PROVIDER_CMAKE_FLAGS -Donnxruntime_USE_MIGRAPHX=1)
list(APPEND ONNXRUNTIME_PROVIDER_NAMES migraphx)
endif()

if (onnxruntime_USE_ARMNN)
list(APPEND ORT_PROVIDER_FLAGS -DUSE_ARMNN=1)
list(APPEND ORT_PROVIDER_CMAKE_FLAGS -Donnxruntime_USE_ARMNN=1)
Expand Down Expand Up @@ -1142,8 +1141,8 @@ function(onnxruntime_set_compile_flags target_name)
set_target_properties(${target_name}
PROPERTIES VS_GLOBAL_CAExcludePath "${ORT_BINARY_DIR};${ORT_SOURCE_DIR}")
if (onnxruntime_ENABLE_STATIC_ANALYSIS)
target_compile_options(${target_name} PRIVATE "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:/analyze:stacksize 131072>")
target_compile_options(${target_name} PRIVATE "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:/analyze:external->")
target_compile_options(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /analyze>" "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:/analyze>")
target_compile_options(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /analyze:external->" "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:/analyze:external->")
endif()
else()
# Enable warning
Expand Down Expand Up @@ -1190,6 +1189,10 @@ function(onnxruntime_configure_target target_name)
target_link_directories(${target_name} PRIVATE ${onnxruntime_LINK_DIRS})
onnxruntime_set_compile_flags(${target_name})
onnxruntime_set_source_file_properties(${target_name})
#Uncomment the following three lines to reproduce static analysis errors locally
#if(WIN32 AND onnxruntime_ENABLE_STATIC_ANALYSIS)
# set_target_properties(${target_name} PROPERTIES VS_USER_PROPS ${PROJECT_SOURCE_DIR}/EnableVisualStudioCodeAnalysis.props)
#endif()
target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT})
if (onnxruntime_ENABLE_LTO)
set_target_properties(${target_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
Expand Down
12 changes: 12 additions & 0 deletions cmake/EnableVisualStudioCodeAnalysis.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)Sdl.ruleset</CodeAnalysisRuleSet>
<!-- External libraries are in or below the directory with the sln file. Source is under \onnxruntime so not affected by this.
Also need to exclude things under \cmake such as \cmake\external\protobuf, and the easiest way to do that in all
environments is to use the directory this file is in.
-->
<CAExcludePath>$(SolutionDir);$(MSBuildThisFileDirectory)</CAExcludePath>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
</Project>
268 changes: 268 additions & 0 deletions cmake/Sdl.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="ONNX Runtime SDL Rules" Description="These rules focus on the most critical and common problems in your native code, including potential security holes and application crashes. You should include this rule set in any custom rule set you create for your native projects. This ruleset is designed to work with Visual Studio Professional edition and higher." ToolsVersion="16.0">
<Rules AnalyzerId="Microsoft.Analyzers.NativeCodeAnalysis" RuleNamespace="Microsoft.Rules.Native">
<Rule Id="C26100" Action="Error" />
<Rule Id="C26101" Action="Error" />
<Rule Id="C26110" Action="Error" />
<Rule Id="C26111" Action="Error" />
<Rule Id="C26112" Action="Error" />
<Rule Id="C26115" Action="Error" />
<Rule Id="C26116" Action="Error" />
<Rule Id="C26117" Action="Error" />
<Rule Id="C26140" Action="Error" />
<Rule Id="C26400" Action="Error" />
<Rule Id="C26404" Action="Error" />
<Rule Id="C26406" Action="Error" />
<Rule Id="C26408" Action="Error" />
<Rule Id="C26409" Action="Error" />
<Rule Id="C26437" Action="Error" />
<Rule Id="C26439" Action="Error" />
<Rule Id="C26441" Action="Error" />
<Rule Id="C26444" Action="Error" />
<Rule Id="C26449" Action="Error" />
<Rule Id="C26450" Action="Error" />
<Rule Id="C26451" Action="Error" />
<Rule Id="C26452" Action="Error" />
<Rule Id="C26453" Action="Error" />
<Rule Id="C26454" Action="Error" />
<Rule Id="C26464" Action="Error" />
<Rule Id="C26478" Action="Error" />
<Rule Id="C26479" Action="Error" />
<Rule Id="C26488" Action="Error" />
<Rule Id="C26497" Action="Error" />
<Rule Id="C26498" Action="Error" />
<Rule Id="C26810" Action="Error" />
<Rule Id="C26811" Action="Error" />
<Rule Id="C26812" Action="Error" />
<Rule Id="C26814" Action="Error" />
<Rule Id="C26815" Action="Error" />
<Rule Id="C26816" Action="Error" />
<Rule Id="C26817" Action="Error" />
<Rule Id="C26819" Action="Error" />
<Rule Id="C26820" Action="Error" />
<Rule Id="C28020" Action="Error" />
<Rule Id="C28021" Action="Error" />
<Rule Id="C28022" Action="Error" />
<Rule Id="C28023" Action="Error" />
<Rule Id="C28024" Action="Error" />
<Rule Id="C28039" Action="Error" />
<Rule Id="C28112" Action="Error" />
<Rule Id="C28113" Action="Error" />
<Rule Id="C28125" Action="Error" />
<Rule Id="C28137" Action="Error" />
<Rule Id="C28138" Action="Error" />
<Rule Id="C28159" Action="Error" />
<Rule Id="C28160" Action="Error" />
<Rule Id="C28163" Action="Error" />
<Rule Id="C28164" Action="Error" />
<Rule Id="C28182" Action="Error" />
<Rule Id="C28183" Action="Error" />
<Rule Id="C28193" Action="Error" />
<Rule Id="C28196" Action="Error" />
<Rule Id="C28202" Action="Error" />
<Rule Id="C28203" Action="Error" />
<Rule Id="C28204" Action="Error" />
<Rule Id="C28205" Action="Error" />
<Rule Id="C28206" Action="Error" />
<Rule Id="C28207" Action="Error" />
<Rule Id="C28208" Action="Error" />
<Rule Id="C28209" Action="Error" />
<Rule Id="C28210" Action="Error" />
<Rule Id="C28211" Action="Error" />
<Rule Id="C28212" Action="Error" />
<Rule Id="C28213" Action="Error" />
<Rule Id="C28214" Action="Error" />
<Rule Id="C28215" Action="Error" />
<Rule Id="C28216" Action="Error" />
<Rule Id="C28217" Action="Error" />
<Rule Id="C28218" Action="Error" />
<Rule Id="C28219" Action="Error" />
<Rule Id="C28220" Action="Error" />
<Rule Id="C28221" Action="Error" />
<Rule Id="C28222" Action="Error" />
<Rule Id="C28223" Action="Error" />
<Rule Id="C28224" Action="Error" />
<Rule Id="C28225" Action="Error" />
<Rule Id="C28226" Action="Error" />
<Rule Id="C28227" Action="Error" />
<Rule Id="C28228" Action="Error" />
<Rule Id="C28229" Action="Error" />
<Rule Id="C28230" Action="Error" />
<Rule Id="C28231" Action="Error" />
<Rule Id="C28232" Action="Error" />
<Rule Id="C28233" Action="Error" />
<Rule Id="C28234" Action="Error" />
<Rule Id="C28235" Action="Error" />
<Rule Id="C28236" Action="Error" />
<Rule Id="C28237" Action="Error" />
<Rule Id="C28238" Action="Error" />
<Rule Id="C28239" Action="Error" />
<Rule Id="C28240" Action="Error" />
<Rule Id="C28241" Action="Error" />
<Rule Id="C28243" Action="Error" />
<Rule Id="C28244" Action="Error" />
<Rule Id="C28245" Action="Error" />
<Rule Id="C28246" Action="Error" />
<Rule Id="C28250" Action="Error" />
<Rule Id="C28251" Action="Error" />
<Rule Id="C28252" Action="Error" />
<Rule Id="C28253" Action="Error" />
<Rule Id="C28254" Action="Error" />
<Rule Id="C28260" Action="Error" />
<Rule Id="C28262" Action="Error" />
<Rule Id="C28263" Action="Error" />
<Rule Id="C28266" Action="Error" />
<Rule Id="C28267" Action="Error" />
<Rule Id="C28272" Action="Error" />
<Rule Id="C28273" Action="Error" />
<Rule Id="C28275" Action="Error" />
<Rule Id="C28279" Action="Error" />
<Rule Id="C28280" Action="Error" />
<Rule Id="C28282" Action="Error" />
<Rule Id="C28285" Action="Error" />
<Rule Id="C28286" Action="Error" />
<Rule Id="C28287" Action="Error" />
<Rule Id="C28288" Action="Error" />
<Rule Id="C28289" Action="Error" />
<Rule Id="C28290" Action="Error" />
<Rule Id="C28291" Action="Error" />
<Rule Id="C28300" Action="Error" />
<Rule Id="C28301" Action="Error" />
<Rule Id="C28302" Action="Error" />
<Rule Id="C28303" Action="Error" />
<Rule Id="C28304" Action="Error" />
<Rule Id="C28305" Action="Error" />
<Rule Id="C28306" Action="Error" />
<Rule Id="C28307" Action="Error" />
<Rule Id="C28308" Action="Error" />
<Rule Id="C28309" Action="Error" />
<Rule Id="C28350" Action="Error" />
<Rule Id="C28351" Action="Error" />
<Rule Id="C33001" Action="Error" />
<Rule Id="C33004" Action="Error" />
<Rule Id="C33005" Action="Error" />
<Rule Id="C33010" Action="Error" />
<Rule Id="C33011" Action="Error" />
<Rule Id="C33020" Action="Error" />
<Rule Id="C6001" Action="Error" />
<Rule Id="C6011" Action="Error" />
<Rule Id="C6029" Action="Error" />
<Rule Id="C6031" Action="Error" />
<Rule Id="C6053" Action="Error" />
<Rule Id="C6054" Action="Error" />
<Rule Id="C6059" Action="Error" />
<Rule Id="C6063" Action="Error" />
<Rule Id="C6064" Action="Error" />
<Rule Id="C6066" Action="Error" />
<Rule Id="C6067" Action="Error" />
<Rule Id="C6101" Action="Error" />
<Rule Id="C6200" Action="Error" />
<Rule Id="C6201" Action="Error" />
<Rule Id="C6214" Action="Error" />
<Rule Id="C6215" Action="Error" />
<Rule Id="C6216" Action="Error" />
<Rule Id="C6217" Action="Error" />
<Rule Id="C6220" Action="Error" />
<Rule Id="C6226" Action="Error" />
<Rule Id="C6230" Action="Error" />
<Rule Id="C6235" Action="Error" />
<Rule Id="C6236" Action="Error" />
<Rule Id="C6237" Action="Error" />
<Rule Id="C6242" Action="Error" />
<Rule Id="C6248" Action="Error" />
<Rule Id="C6250" Action="Error" />
<Rule Id="C6255" Action="Error" />
<Rule Id="C6258" Action="Error" />
<Rule Id="C6259" Action="Error" />
<Rule Id="C6260" Action="Error" />
<Rule Id="C6262" Action="Error" />
<Rule Id="C6263" Action="Error" />
<Rule Id="C6268" Action="Error" />
<Rule Id="C6269" Action="Error" />
<Rule Id="C6270" Action="Error" />
<Rule Id="C6271" Action="Error" />
<Rule Id="C6272" Action="Error" />
<Rule Id="C6273" Action="Error" />
<Rule Id="C6274" Action="Error" />
<Rule Id="C6276" Action="Error" />
<Rule Id="C6277" Action="Error" />
<Rule Id="C6278" Action="Error" />
<Rule Id="C6279" Action="Error" />
<Rule Id="C6280" Action="Error" />
<Rule Id="C6281" Action="Error" />
<Rule Id="C6282" Action="Error" />
<Rule Id="C6283" Action="Error" />
<Rule Id="C6284" Action="Error" />
<Rule Id="C6285" Action="Error" />
<Rule Id="C6286" Action="Error" />
<Rule Id="C6287" Action="Error" />
<Rule Id="C6288" Action="Error" />
<Rule Id="C6289" Action="Error" />
<Rule Id="C6290" Action="Error" />
<Rule Id="C6291" Action="Error" />
<Rule Id="C6292" Action="Error" />
<Rule Id="C6293" Action="Error" />
<Rule Id="C6294" Action="Error" />
<Rule Id="C6295" Action="Error" />
<Rule Id="C6296" Action="Error" />
<Rule Id="C6297" Action="Error" />
<Rule Id="C6299" Action="Error" />
<Rule Id="C6302" Action="Error" />
<Rule Id="C6303" Action="Error" />
<Rule Id="C6305" Action="Error" />
<Rule Id="C6306" Action="Error" />
<Rule Id="C6308" Action="Error" />
<Rule Id="C6310" Action="Error" />
<Rule Id="C6312" Action="Error" />
<Rule Id="C6314" Action="Error" />
<Rule Id="C6317" Action="Error" />
<Rule Id="C6318" Action="Error" />
<Rule Id="C6319" Action="Error" />
<Rule Id="C6324" Action="Error" />
<Rule Id="C6326" Action="Error" />
<Rule Id="C6328" Action="Error" />
<Rule Id="C6331" Action="Error" />
<Rule Id="C6332" Action="Error" />
<Rule Id="C6333" Action="Error" />
<Rule Id="C6335" Action="Error" />
<Rule Id="C6381" Action="Error" />
<Rule Id="C6383" Action="Error" />
<Rule Id="C6384" Action="Error" />
<Rule Id="C6385" Action="Error" />
<Rule Id="C6386" Action="Error" />
<Rule Id="C6387" Action="Error" />
<Rule Id="C6388" Action="Error" />
<Rule Id="C6500" Action="Error" />
<Rule Id="C6501" Action="Error" />
<Rule Id="C6503" Action="Error" />
<Rule Id="C6504" Action="Error" />
<Rule Id="C6505" Action="Error" />
<Rule Id="C6506" Action="Error" />
<Rule Id="C6508" Action="Error" />
<Rule Id="C6509" Action="Error" />
<Rule Id="C6510" Action="Error" />
<Rule Id="C6511" Action="Error" />
<Rule Id="C6513" Action="Error" />
<Rule Id="C6514" Action="Error" />
<Rule Id="C6515" Action="Error" />
<Rule Id="C6516" Action="Error" />
<Rule Id="C6517" Action="Error" />
<Rule Id="C6518" Action="Error" />
<Rule Id="C6522" Action="Error" />
<Rule Id="C6525" Action="Error" />
<Rule Id="C6527" Action="Error" />
<Rule Id="C6530" Action="Error" />
<Rule Id="C6540" Action="Error" />
<Rule Id="C6551" Action="Error" />
<Rule Id="C6552" Action="Error" />
<Rule Id="C6701" Action="Error" />
<Rule Id="C6702" Action="Error" />
<Rule Id="C6703" Action="Error" />
<Rule Id="C6704" Action="Error" />
<Rule Id="C6705" Action="Error" />
<Rule Id="C6706" Action="Error" />
<Rule Id="C6993" Action="Error" />
<Rule Id="C6995" Action="Error" />
<Rule Id="C6997" Action="Error" />
</Rules>
</RuleSet>
5 changes: 0 additions & 5 deletions cmake/onnxruntime_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/common DEST
set_target_properties(onnxruntime_common PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(onnxruntime_common PROPERTIES FOLDER "ONNXRuntime")

if(WIN32)
# Add Code Analysis properties to enable C++ Core checks. Have to do it via a props file include.
set_target_properties(onnxruntime_common PROPERTIES VS_USER_PROPS ${PROJECT_SOURCE_DIR}/EnableVisualStudioCodeAnalysis.props)
endif()

# check if we need to link against librt on Linux
include(CheckLibraryExists)
include(CheckFunctionExists)
Expand Down
5 changes: 1 addition & 4 deletions cmake/onnxruntime_graph.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,5 @@ if (WIN32)
target_compile_options(onnxruntime_graph PRIVATE
/EHsc # exception handling - C++ may throw, extern "C" will not
)
endif()

# Add Code Analysis properties to enable C++ Core checks. Have to do it via a props file include.
set_target_properties(onnxruntime_graph PROPERTIES VS_USER_PROPS ${PROJECT_SOURCE_DIR}/EnableVisualStudioCodeAnalysis.props)
endif()
endif()
3 changes: 3 additions & 0 deletions cmake/onnxruntime_mlas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,7 @@ endforeach()
set_target_properties(onnxruntime_mlas PROPERTIES FOLDER "ONNXRuntime")
if (WIN32)
target_compile_options(onnxruntime_mlas PRIVATE "/wd6385" "/wd4127")
if (onnxruntime_ENABLE_STATIC_ANALYSIS)
target_compile_options(onnxruntime_mlas PRIVATE "/analyze:stacksize 131072")
endif()
endif()
4 changes: 4 additions & 0 deletions cmake/onnxruntime_providers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ if (onnxruntime_USE_DNNL)
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_dnnl_cc_srcs})
onnxruntime_add_shared_library_module(onnxruntime_providers_dnnl ${onnxruntime_providers_dnnl_cc_srcs})
target_link_directories(onnxruntime_providers_dnnl PRIVATE ${DNNL_LIB_DIR})
if (MSVC AND onnxruntime_ENABLE_STATIC_ANALYSIS)
# dnnl_convgrad.cc(47,0): Warning C6262: Function uses '38816' bytes of stack: exceeds /analyze:stacksize '16384'. Consider moving some data to heap.
target_compile_options(onnxruntime_providers_dnnl PRIVATE "/analyze:stacksize 131072")
endif()

add_dependencies(onnxruntime_providers_dnnl onnxruntime_providers_shared project_dnnl ${onnxruntime_EXTERNAL_DEPENDENCIES})
target_include_directories(onnxruntime_providers_dnnl PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} ${DNNL_INCLUDE_DIR} ${DNNL_OCL_INCLUDE_DIR})
Expand Down
Loading

0 comments on commit 4e9e01c

Please sign in to comment.