Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_result / size_report / pointer_read.cc
1 // Copyright 2020 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 #include <cstring>
16 #include <span>
17
18 #include "pw_bytes/array.h"
19 #include "pw_log/log.h"
20 #include "pw_preprocessor/compiler.h"
21 #include "pw_status/status.h"
22
23 namespace {
24
25 // clang-format off
26 constexpr auto kArray = pw::bytes::Array<
27     0x0a, 0x14, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00,
28     0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x96, 0x00,
29     0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x12, 0x08,
30     0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01>();
31 // clang-format on
32
33 PW_NO_INLINE pw::Status Read(size_t offset,
34                              size_t size,
35                              std::span<const std::byte>* out) {
36   if (offset + size >= std::size(kArray)) {
37     return pw::Status::OutOfRange();
38   }
39
40   *out = std::span<const std::byte>(std::data(kArray) + offset, size);
41   return pw::OkStatus();
42 }
43
44 }  // namespace
45
46 size_t volatile* unoptimizable;
47
48 int main() {
49   std::span<const std::byte> data;
50   pw::Status status = Read(*unoptimizable, *unoptimizable, &data);
51   if (!status.ok()) {
52     return 1;
53   }
54
55   PW_LOG_INFO("Read %u bytes", static_cast<unsigned>(data.size()));
56   return 0;
57 }