Skip to content
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

Fatal error in serialization.hpp of cpp output #254

Closed
JustinOng opened this issue May 16, 2022 · 12 comments · Fixed by #255 or #257
Closed

Fatal error in serialization.hpp of cpp output #254

JustinOng opened this issue May 16, 2022 · 12 comments · Fixed by #255 or #257

Comments

@JustinOng
Copy link

Hi! I've been playing with the cpp language support and I've found that serialization.hpp fails to build, even in the test suite. The following is from the Docker container specified in verification/, with the tldr specified here.

root@49afb38cf9df:/workspace/verification/build_cpp# cmake --build . --target test_bitarray
Scanning dependencies of target o1heap
[  7%] Building C object CMakeFiles/o1heap.dir/workspace/submodules/o1heap/o1heap/o1heap.c.o
[ 14%] Linking C static library libo1heap.a
[ 14%] Built target o1heap
Scanning dependencies of target dsdl-regulated-gen
[ 21%] Running nnvg
[ 21%] Built target dsdl-regulated-gen
Scanning dependencies of target nunavut-support-c-gen
[ 28%] Running nnvg
[ 28%] Built target nunavut-support-c-gen
Scanning dependencies of target dsdl-test-c-gen
[ 35%] Running nnvg
[ 35%] Built target dsdl-test-c-gen
Scanning dependencies of target dsdl-test-gen
[ 42%] Running nnvg
[ 42%] Built target dsdl-test-gen
Scanning dependencies of target gmock_main
[ 50%] Building CXX object CMakeFiles/gmock_main.dir/workspace/submodules/googletest/googletest/src/gtest-all.cc.o
[ 57%] Building CXX object CMakeFiles/gmock_main.dir/workspace/submodules/googletest/googlemock/src/gmock-all.cc.o
[ 64%] Building CXX object CMakeFiles/gmock_main.dir/workspace/submodules/googletest/googlemock/src/gmock_main.cc.o
[ 71%] Linking CXX static library libgmock_main.a
[ 71%] Built target gmock_main
Scanning dependencies of target dsdl-regulated-c-gen
[ 78%] Running nnvg
[ 78%] Built target dsdl-regulated-c-gen
Scanning dependencies of target nunavut-support-gen
[ 85%] Running nnvg
[ 85%] Built target nunavut-support-gen
Scanning dependencies of target test_bitarray
[ 92%] Building CXX object CMakeFiles/test_bitarray.dir/cpp/suite/test_bitarray.cpp.o
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp: In member function ‘nunavut::support::VoidResult nunavut::support::bitspan::setUxx(uint64_t, uint8_t)’:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:654:81: error: no matching function for call to ‘nunavut::support::bitspan::bitspan(<brace-enclosed initializer list>)’
         bitspan{ { reinterpret_cast<const uint8_t*>(&value), sizeof(uint64_t) } }.copyTo(*this, saturated_len_bits);
                                                                                 ^
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:303:5: note: candidate: nunavut::support::bitspan::bitspan(nunavut::support::bytespan, std::size_t)
     bitspan(bytespan data, std::size_t offset_bits=0)
     ^~~~~~~
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:303:5: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘nunavut::support::bytespan {aka nunavut::support::span<unsigned char>}’
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:296:8: note: candidate: constexpr nunavut::support::bitspan::bitspan(const nunavut::support::bitspan&)
 struct bitspan: public detail::any_bitspan<bitspan>{
        ^~~~~~~
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:296:8: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const nunavut::support::bitspan&’
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:296:8: note: candidate: constexpr nunavut::support::bitspan::bitspan(nunavut::support::bitspan&&)
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:296:8: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘nunavut::support::bitspan&&’
CMakeFiles/test_bitarray.dir/build.make:62: recipe for target 'CMakeFiles/test_bitarray.dir/cpp/suite/test_bitarray.cpp.o' failed
make[3]: *** [CMakeFiles/test_bitarray.dir/cpp/suite/test_bitarray.cpp.o] Error 1
CMakeFiles/Makefile2:977: recipe for target 'CMakeFiles/test_bitarray.dir/all' failed
make[2]: *** [CMakeFiles/test_bitarray.dir/all] Error 2
CMakeFiles/Makefile2:989: recipe for target 'CMakeFiles/test_bitarray.dir/rule' failed
make[1]: *** [CMakeFiles/test_bitarray.dir/rule] Error 2
Makefile:469: recipe for target 'test_bitarray' failed
make: *** [test_bitarray] Error 2

Full trace can be found here

Could I get some assistance with determining whether this is a library issue?

@pavel-kirienko
Copy link
Member

@asmfreak can you please assist?

@asmfreak
Copy link
Contributor

Well, it is a library issue, yes. I'll look into it.

@asmfreak
Copy link
Contributor

@JustinOng , can you please try #255 PR. Does it fix the error for you?

@JustinOng
Copy link
Author

Thanks for getting back so quickly! Unfortunately, it seems like its still breaking when configured for little endian systems:

root@0e779372b434:/workspace/verification/build_cpp# cmake -DNUNAVUT_VERIFICATION_TARGET_ENDIANNESS=little ..
...
root@0e779372b434:/workspace/verification/build_cpp# cmake --build . --target test_bitarray
[ 14%] Built target o1heap
Scanning dependencies of target dsdl-regulated-gen
[ 21%] Built target dsdl-regulated-gen
[ 28%] Running nnvg
[ 28%] Built target nunavut-support-c-gen
[ 35%] Running nnvg
[ 35%] Built target dsdl-test-c-gen
[ 42%] Running nnvg
[ 42%] Built target dsdl-test-gen
[ 71%] Built target gmock_main
Scanning dependencies of target dsdl-regulated-c-gen
[ 78%] Built target dsdl-regulated-c-gen
[ 85%] Running nnvg
[ 85%] Built target nunavut-support-gen
Scanning dependencies of target test_bitarray
[ 92%] Building CXX object CMakeFiles/test_bitarray.dir/cpp/suite/test_bitarray.cpp.o
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp: In member function ‘nunavut::support::VoidResult nunavut::support::bitspan::setUxx(uint64_t, uint8_t)’:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:690:77: error: no matching function for call to ‘nunavut::support::bitspan::bitspan(<brace-enclosed initializer list>)’
         bitspan{ reinterpret_cast<const uint8_t*>(&value), sizeof(uint64_t) }.copyTo(*this, saturated_len_bits);
                                                                             ^
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:327:5: note: candidate: nunavut::support::bitspan::bitspan(nunavut::support::bitspan::value_type*, std::size_t, std::size_t) <near match>
     bitspan(value_type* ptr,  std::size_t size, std::size_t offset_bits=0)
     ^~~~~~~
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:327:5: note:   conversion of argument 1 would be ill-formed:
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:690:18: error: invalid conversion from ‘const uint8_t* {aka const unsigned char*}’ to ‘nunavut::support::bitspan::value_type* {aka unsigned char*}’ [-fpermissive]
         bitspan{ reinterpret_cast<const uint8_t*>(&value), sizeof(uint64_t) }.copyTo(*this, saturated_len_bits);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:324:5: note: candidate: template<long unsigned int N> nunavut::support::bitspan::bitspan(nunavut::support::bitspan::value_type (&)[N], std::size_t)
     bitspan(value_type (&data)[N], std::size_t offset_bits=0)
     ^~~~~~~
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:324:5: note:   template argument deduction/substitution failed:
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:690:77: note:   mismatched types ‘nunavut::support::bitspan::value_type [N]’ and ‘const uint8_t* {aka const unsigned char*}’
         bitspan{ reinterpret_cast<const uint8_t*>(&value), sizeof(uint64_t) }.copyTo(*this, saturated_len_bits);
                                                                             ^
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:320:5: note: candidate: template<long unsigned int N> nunavut::support::bitspan::bitspan(const std::array<unsigned char, N>&, std::size_t)
     bitspan(const std::array<value_type, N>& data, std::size_t offset_bits=0)
     ^~~~~~~
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:320:5: note:   template argument deduction/substitution failed:
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:690:77: note:   mismatched types ‘const std::array<unsigned char, N>’ and ‘const uint8_t* {aka const unsigned char*}’
         bitspan{ reinterpret_cast<const uint8_t*>(&value), sizeof(uint64_t) }.copyTo(*this, saturated_len_bits);
                                                                             ^
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:316:5: note: candidate: template<long unsigned int N> nunavut::support::bitspan::bitspan(std::array<unsigned char, N>&, std::size_t)
     bitspan(std::array<value_type, N>& data, std::size_t offset_bits=0)
     ^~~~~~~
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:316:5: note:   template argument deduction/substitution failed:
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:690:77: note:   mismatched types ‘std::array<unsigned char, N>’ and ‘const uint8_t* {aka const unsigned char*}’
         bitspan{ reinterpret_cast<const uint8_t*>(&value), sizeof(uint64_t) }.copyTo(*this, saturated_len_bits);
                                                                             ^
In file included from /workspace/verification/cpp/suite/test_helpers.hpp:10:0,
                 from /workspace/verification/cpp/suite/test_bitarray.cpp:9:
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:306:8: note: candidate: constexpr nunavut::support::bitspan::bitspan(const nunavut::support::bitspan&)
 struct bitspan final: public detail::any_bitspan<bitspan>{
        ^~~~~~~
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:306:8: note:   candidate expects 1 argument, 2 provided
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:306:8: note: candidate: constexpr nunavut::support::bitspan::bitspan(nunavut::support::bitspan&&)
/workspace/verification/build_cpp/generated/cpp/nunavut/support/serialization.hpp:306:8: note:   candidate expects 1 argument, 2 provided
CMakeFiles/test_bitarray.dir/build.make:62: recipe for target 'CMakeFiles/test_bitarray.dir/cpp/suite/test_bitarray.cpp.o' failed
make[3]: *** [CMakeFiles/test_bitarray.dir/cpp/suite/test_bitarray.cpp.o] Error 1
CMakeFiles/Makefile2:977: recipe for target 'CMakeFiles/test_bitarray.dir/all' failed
make[2]: *** [CMakeFiles/test_bitarray.dir/all] Error 2
CMakeFiles/Makefile2:989: recipe for target 'CMakeFiles/test_bitarray.dir/rule' failed
make[1]: *** [CMakeFiles/test_bitarray.dir/rule] Error 2
Makefile:469: recipe for target 'test_bitarray' failed
make: *** [test_bitarray] Error 2

@JustinOng
Copy link
Author

I would also like to add that serialization.hpp seems to be missing a few includes:

array: for std::array
limits: std::numeric_limits and std::min

Not sure why this dosen't show up in the tests, but I have to include these before serialization.hpp in my project.

@asmfreak
Copy link
Contributor

I think it's about a different version of compiler/stdlib/platform you are using. Can it be, that you are using some kind of an ARM platform?

@JustinOng
Copy link
Author

JustinOng commented May 18, 2022

Yep, I'm compiling for the ESP32 with the ESP-IDF which is little endian. However, the issue is also present when the test suite is configured for little endian - this case here seems to be problematic. (unless you're referring to the missing includes, which could be a platform-specific issue yes)

@pavel-kirienko
Copy link
Member

@thirtytwobits is it really resolved though?

@asmfreak
Copy link
Contributor

@pavel-kirienko @thirtytwobits I think we need to change the test suite and/or CI workers somehow to catch this break. It's better to work in a tests-first approach. Fixing the actual compilation problem is trivial - it's a matter of changing to a different class.

@JustinOng For now you can use any endian, which definitely works. I'm actually also using this implementation on ESP32. The little endian is an optimization for (de)serialization of certain integers, which is just a copy. I think and hope that the compiler is actually capable of optimizing bit shifts and or's into byte-access, but I didn't actually check if it is doing that optimization in our case.

@thirtytwobits
Copy link
Member

On it

thirtytwobits added a commit to thirtytwobits/nunavut that referenced this issue May 20, 2022
1. Adding explicit little-endian tests to CI
2. Fixing issues found by said tests.
3. Small documentation fixes and update to public_regulated_data_types
   submodule.
thirtytwobits added a commit that referenced this issue May 20, 2022
* Fixing #254 with tests

1. Adding explicit little-endian tests to CI
2. Fixing issues found by said tests.
3. Small documentation fixes and update to public_regulated_data_types
   submodule.

* fixing build
@asmfreak
Copy link
Contributor

@JustinOng You can try #257 to fix missing includes alongside merged #256

@JustinOng
Copy link
Author

Looks great! I can confirm both the initial compilation error, and the missing includes are fixed as of #257.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants