diff --git a/objectivec/src/ort_session.mm b/objectivec/src/ort_session.mm index b2a16195b4310..070ceaa7d4da3 100644 --- a/objectivec/src/ort_session.mm +++ b/objectivec/src/ort_session.mm @@ -188,7 +188,9 @@ - (BOOL)runWithInputs:(NSDictionary*)inputs for (size_t i = 0; i < nameCount; ++i) { auto name = std::unique_ptr{getName(i, allocator), deleter}; - [result addObject:[NSString stringWithUTF8String:name.get()]]; + NSString* nameNsstr = [NSString stringWithUTF8String:name.get()]; + NSAssert(nameNsstr != nil, @"nameNsstr must not be nil"); + [result addObject:nameNsstr]; } return result; diff --git a/onnxruntime/core/providers/coreml/model/model.mm b/onnxruntime/core/providers/coreml/model/model.mm index aac2af13ace6b..06a2a8e935812 100644 --- a/onnxruntime/core/providers/coreml/model/model.mm +++ b/onnxruntime/core/providers/coreml/model/model.mm @@ -73,8 +73,10 @@ - (instancetype)initWithInputs:(const std::unordered_map()); - size_t output_data_byte_size = 0; const auto type = output_tensor.tensor_info.data_type; switch (type) { - case ONNX_NAMESPACE::TensorProto_DataType_FLOAT: - output_data_byte_size = num_elements * sizeof(float); + case ONNX_NAMESPACE::TensorProto_DataType_FLOAT: { + const auto output_data_byte_size = num_elements * sizeof(float); memcpy(output_tensor.buffer, model_output_data, output_data_byte_size); break; - case ONNX_NAMESPACE::TensorProto_DataType_INT32: - output_data_byte_size = num_elements * sizeof(int32_t); + } + case ONNX_NAMESPACE::TensorProto_DataType_INT32: { + const auto output_data_byte_size = num_elements * sizeof(int32_t); memcpy(output_tensor.buffer, model_output_data, output_data_byte_size); break; + } // For this case, since Coreml Spec only uses int32 for model output while onnx provides // int64 for model output data type. We are doing a type casting (int32 -> int64) here // when copying the model to ORT case ONNX_NAMESPACE::TensorProto_DataType_INT64: - output_data_byte_size = num_elements * sizeof(int64_t); if (model_output_type == MLMultiArrayDataTypeInt32) { int32_t* model_output_data_prime = static_cast(model_output_data); int64_t* output_tensor_buffer_prime = static_cast(output_tensor.buffer); diff --git a/tools/ci_build/github/apple/objectivec/static_analysis/requirements.txt b/tools/ci_build/github/apple/objectivec/static_analysis/requirements.txt index b3868a3a7c45c..528bdbbe906ac 100644 --- a/tools/ci_build/github/apple/objectivec/static_analysis/requirements.txt +++ b/tools/ci_build/github/apple/objectivec/static_analysis/requirements.txt @@ -1,2 +1 @@ -codechecker==6.16.0 ninja==1.10.2 diff --git a/tools/ci_build/github/azure-pipelines/mac-objc-static-analysis-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-objc-static-analysis-ci-pipeline.yml index 29e855de2fc7d..c61f71fd5c09c 100644 --- a/tools/ci_build/github/azure-pipelines/mac-objc-static-analysis-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-objc-static-analysis-ci-pipeline.yml @@ -4,7 +4,7 @@ jobs: pool: vmImage: 'macOS-10.15' - timeoutInMinutes: 10 + timeoutInMinutes: 60 steps: - task: UsePythonVersion@0 @@ -24,43 +24,16 @@ jobs: --config Debug \ --build_shared_lib --use_coreml --build_objc \ --cmake_extra_defines CMAKE_EXPORT_COMPILE_COMMANDS=ON \ - --update + --update \ + --build --parallel displayName: Generate compile_commands.json - script: | - set -e - - LLVM_DIR="$(brew --prefix llvm)" - CODECHECKER_CONFIG_FILE="$(dirname $(which codechecker))/../share/codechecker/config/package_layout.json" - - sed -i "" \ - -e 's#"clangsa": "[^"]*"#"clangsa": "'"${LLVM_DIR}"'/bin/clang"#' \ - -e 's#"clang-tidy": "[^"]*"#"clang-tidy": "'"${LLVM_DIR}"'/bin/clang-tidy"#' \ - "${CODECHECKER_CONFIG_FILE}" - - cat "${CODECHECKER_CONFIG_FILE}" - displayName: Update CodeChecker configuration - - - script: | - codechecker analyze \ - --file "$(Build.SourcesDirectory)/objectivec/*" \ - "$(Build.SourcesDirectory)/onnxruntime/core/platform/apple/logging/apple_log_sink.mm" \ - "$(Build.SourcesDirectory)/onnxruntime/core/providers/coreml/model/*.mm" \ - --output "$(Build.BinariesDirectory)/codechecker.analyze.out" \ - "$(Build.BinariesDirectory)/Debug/compile_commands.json" - - CODECHECKER_ANALYZE_EXIT_CODE=$? - echo "codechecker analyze exited with code: ${CODECHECKER_ANALYZE_EXIT_CODE}" - displayName: Run CodeChecker analysis - - - script: | - # skip results from external dependencies - echo "-$(Build.SourcesDirectory)/cmake/external/*" > "$(Build.BinariesDirectory)/codechecker.parse.skipfile" - - codechecker parse \ - --ignore "$(Build.BinariesDirectory)/codechecker.parse.skipfile" \ - "$(Build.BinariesDirectory)/codechecker.analyze.out" - - CODECHECKER_PARSE_EXIT_CODE=$? - echo "codechecker parse exited with code: ${CODECHECKER_PARSE_EXIT_CODE}" - displayName: Show CodeChecker analysis results + "$(brew --prefix llvm)/bin/clang-tidy" \ + -p="$(Build.BinariesDirectory)/Debug" \ + --checks="-*,clang-analyzer-*" \ + --header-filter="objectivec/include|objectivec/src|onnxruntime/core" \ + ./objectivec/src/*.mm \ + ./onnxruntime/core/platform/apple/logging/apple_log_sink.mm \ + ./onnxruntime/core/providers/coreml/model/*.mm + displayName: Analyze Objective-C/C++ source code