From b4a4fa5aac9e1fafe348f2c9d7d121ed28a35433 Mon Sep 17 00:00:00 2001 From: Jicheng Tang Date: Tue, 29 Nov 2022 01:33:53 +0800 Subject: [PATCH] Fix compile error with protobuf RepeatedIterator (#13731) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Description There are some compile errors with google::protobuf::internal::RepeatedIterator. replace reinterpret_cast with &(*iter), which iter is RepeatedIterator type. ### Motivation and Context My protobuf version is: - libprotoc 3.21.5 - g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 when I use build command: ``` ./build.sh --use_cuda --cudnn_home /usr --cuda_home /usr/local/cuda --config Debug --build_shared_lib --parallel ``` There are some compile errors like this: - error 1 onnxruntime/test/util/test_utils.cc:186:105: error: no matching function for call to ‘make_span(google::protobuf::RepeatedField::const_iterator, google::protobuf::RepeatedField::const_iterator)’ 186 | ind_span = gsl::make_span(indices_proto.int64_data().cbegin(), indices_proto.int64_data().cend()); - error 2 onnxruntime/test/onnx/tensorprotoutils.cc:101:56: error: invalid cast from type ‘google::protobuf::internal::RepeatedIterator’ to type ‘const uint32_t*’ {aka ‘const unsigned int*’} 101 | *p_data++ = *reinterpret_cast(data_iter); --- onnxruntime/test/onnx/tensorprotoutils.cc | 2 +- onnxruntime/test/util/test_utils.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/test/onnx/tensorprotoutils.cc b/onnxruntime/test/onnx/tensorprotoutils.cc index 2f9ba70d31..afafd0c6b4 100644 --- a/onnxruntime/test/onnx/tensorprotoutils.cc +++ b/onnxruntime/test/onnx/tensorprotoutils.cc @@ -98,7 +98,7 @@ static void UnpackTensorWithRawData(const void* raw_data, size_t raw_data_length OrtErrorCode::ORT_FAIL); \ auto& data = tensor.field_name(); \ for (auto data_iter = data.cbegin(); data_iter != data.cend(); ++data_iter) \ - *p_data++ = *reinterpret_cast(data_iter); \ + *p_data++ = onnxruntime::narrow(*data_iter); \ return; \ } diff --git a/onnxruntime/test/util/test_utils.cc b/onnxruntime/test/util/test_utils.cc index b2c32b486a..33d457d9d5 100644 --- a/onnxruntime/test/util/test_utils.cc +++ b/onnxruntime/test/util/test_utils.cc @@ -183,7 +183,7 @@ void SparseIndicesChecker(const ONNX_NAMESPACE::TensorProto& indices_proto, gsl: ASSERT_STATUS_OK(utils::UnpackInitializerData(indices_proto, model_path, unpack_buffer)); ind_span = ReinterpretAsSpan(gsl::make_span(unpack_buffer)); } else { - ind_span = gsl::make_span(indices_proto.int64_data().cbegin(), indices_proto.int64_data().cend()); + ind_span = gsl::make_span(indices_proto.int64_data().data(), indices_proto.int64_data_size()); } break; }