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

C++ compiler error when bitfield field converted to value #1539

Closed
Tracked by #1481
bbannier opened this issue Sep 25, 2023 · 0 comments · Fixed by #1540
Closed
Tracked by #1481

C++ compiler error when bitfield field converted to value #1539

bbannier opened this issue Sep 25, 2023 · 0 comments · Fixed by #1540
Assignees
Labels
Bug Something isn't working Regression

Comments

@bbannier
Copy link
Member

bbannier commented Sep 25, 2023

In the &convert attribute we support any RHS expressions which produce a value, i.e., the RHS can e.g., be a function, a value, or a literal. This got broken for bitfield fields with #1492 (in particular f3a8bdf).

module foo;

public type X = unit {
    : uint8 &convert="foo"; # WORKS.

    : bitfield(8) {
        a: 0..7 &convert=FOO(); # WORKS.
    };

    : bitfield(8) {
        b: 0..7 &convert=FOO2; # BROKEN.
    };

    : bitfield(8) {
        c: 0..7 &convert=FOO3; # BROKEN.
    };

    : bitfield(8) {
        d: 0..7 &convert="foo"; # BROKEN.
    };
};

function FOO(): string { return "foo"; }
const FOO2 = "foo";
global FOO3 = "foo";
$ spicyc -dj foo.spicy
/private/var/folders/ht/vtb0rkbd4ws15vx02xdb84zw0000gn/T/foo_1c0ff69c973b5abc-2ab7850513fcbfef.cc:74:136: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
    const ::hilti::rt::TypeInfo __ti_bitfieldx2a8x2b_x73__d_0_7_x28convertx31_foo_x3e_x75 = { {}, "bitfield(8) {     d: 0..7 &convert="foo"; }", new ::hilti::rt::type_info::Bitfield(std::vector<::hilti::rt::type_info::bitfield::Bits>({::hilti::rt::type_info::bitfield::Bits{ "d", &::hilti::rt::type_info::string, hilti::rt::bitfield::elementOffset<hilti::rt::Bitfield<std::string, ::hilti::rt::integer::safe<uint8_t>>, 0>() }})) };
                                                                                                                                       ^
                                                                                                                                        
/private/var/folders/ht/vtb0rkbd4ws15vx02xdb84zw0000gn/T/foo_1c0ff69c973b5abc-2ab7850513fcbfef.cc:74:136: error: expected '}'
/private/var/folders/ht/vtb0rkbd4ws15vx02xdb84zw0000gn/T/foo_1c0ff69c973b5abc-2ab7850513fcbfef.cc:74:93: note: to match this '{'
    const ::hilti::rt::TypeInfo __ti_bitfieldx2a8x2b_x73__d_0_7_x28convertx31_foo_x3e_x75 = { {}, "bitfield(8) {     d: 0..7 &convert="foo"; }", new ::hilti::rt::type_info::Bitfield(std::vector<::hilti::rt::type_info::bitfield::Bits>({::hilti::rt::type_info::bitfield::Bits{ "d", &::hilti::rt::type_info::string, hilti::rt::bitfield::elementOffset<hilti::rt::Bitfield<std::string, ::hilti::rt::integer::safe<uint8_t>>, 0>() }})) };
                                                                                            ^
In file included from /private/var/folders/ht/vtb0rkbd4ws15vx02xdb84zw0000gn/T/foo_1c0ff69c973b5abc-2ab7850513fcbfef.cc:1:
In file included from /Users/bbannier/src/spicy/hilti/runtime/include/hilti/rt/libhilti.h:9:
In file included from /Users/bbannier/src/spicy/build/include/hilti/rt/autogen/config.h:5:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/string:576:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/string_view:1027:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/functional:515:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__functional/boyer_moore_searcher.h:25:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/unordered_map:530:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__node_handle:65:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/optional:646:5: error: static assertion failed due to requirement '!is_reference_v<const std::string &>': instantiation of optional with a reference type is ill-formed
    static_assert(!is_reference_v<value_type>,
    ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__type_traits/is_empty.h:23:38: note: in instantiation of template class 'std::optional<const std::string &>' requested here
    : public integral_constant<bool, __is_empty(_Tp)> {};
                                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/tuple:273:16: note: in instantiation of template class 'std::is_empty<std::optional<const std::string &>>' requested here
          bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
               ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/tuple:480:14: note: in instantiation of default argument for '__tuple_leaf<0UL, std::optional<const std::string &>>' required here
    : public __tuple_leaf<_Indx, _Tp>...
             ^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/tuple:570:12: note: in instantiation of template class 'std::__tuple_impl<std::__tuple_indices<0, 1>, std::optional<const std::string &>, std::optional<SafeInt<unsigned char, hilti::rt::integer::detail::SafeIntException>>>' requested here
    _BaseT __base_;
           ^
/Users/bbannier/src/spicy/hilti/runtime/include/hilti/rt/types/bitfield.h:26:38: note: in instantiation of template class 'std::tuple<std::optional<const std::string &>, std::optional<SafeInt<unsigned char, hilti::rt::integer::detail::SafeIntException>>>' requested here
    std::tuple<std::optional<Ts>...> value;
                                     ^
/private/var/folders/ht/vtb0rkbd4ws15vx02xdb84zw0000gn/T/foo_1c0ff69c973b5abc-2ab7850513fcbfef.cc:163:229: note: in instantiation of template class 'hilti::rt::Bitfield<const std::string &, SafeInt<unsigned char, hilti::rt::integer::detail::SafeIntException>>' requested here
    std::tie(::hilti::rt::optional::valueOrInit((*__self)._anon_3), __cur) = (__x_2 = ::hilti::rt::integer::unpack<uint8_t>(__cur, ::hilti::rt::ByteOrder{::hilti::rt::ByteOrder::Network}), hilti::rt::make_result(std::make_tuple(hilti::rt::make_bitfield(__hlt::foo::FOO2, hilti::rt::integer::noop(std::get<0>(*__x_2))), std::get<1>(*__x_2)))).valueOrThrow();
                                                                                                                                                                                                                                    ^
In file included from /private/var/folders/ht/vtb0rkbd4ws15vx02xdb84zw0000gn/T/foo_1c0ff69c973b5abc-2ab7850513fcbfef.cc:1:
In file included from /Users/bbannier/src/spicy/hilti/runtime/include/hilti/rt/libhilti.h:9:
In file included from /Users/bbannier/src/spicy/build/include/hilti/rt/autogen/config.h:5:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/string:576:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/string_view:1027:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/functional:515:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__functional/boyer_moore_searcher.h:25:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/unordered_map:530:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__node_handle:65:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/optional:646:5: error: static assertion failed due to requirement '!is_reference_v<std::string &>': instantiation of optional with a reference type is ill-formed
    static_assert(!is_reference_v<value_type>,
    ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__type_traits/is_empty.h:23:38: note: in instantiation of template class 'std::optional<std::string &>' requested here
    : public integral_constant<bool, __is_empty(_Tp)> {};
                                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/tuple:273:16: note: in instantiation of template class 'std::is_empty<std::optional<std::string &>>' requested here
          bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
               ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/tuple:480:14: note: in instantiation of default argument for '__tuple_leaf<0UL, std::optional<std::string &>>' required here
    : public __tuple_leaf<_Indx, _Tp>...
             ^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/tuple:570:12: note: in instantiation of template class 'std::__tuple_impl<std::__tuple_indices<0, 1>, std::optional<std::string &>, std::optional<SafeInt<unsigned char, hilti::rt::integer::detail::SafeIntException>>>' requested here
    _BaseT __base_;
           ^
/Users/bbannier/src/spicy/hilti/runtime/include/hilti/rt/types/bitfield.h:26:38: note: in instantiation of template class 'std::tuple<std::optional<std::string &>, std::optional<SafeInt<unsigned char, hilti::rt::integer::detail::SafeIntException>>>' requested here
    std::tuple<std::optional<Ts>...> value;
                                     ^
/private/var/folders/ht/vtb0rkbd4ws15vx02xdb84zw0000gn/T/foo_1c0ff69c973b5abc-2ab7850513fcbfef.cc:186:229: note: in instantiation of template class 'hilti::rt::Bitfield<std::string &, SafeInt<unsigned char, hilti::rt::integer::detail::SafeIntException>>' requested here
    std::tie(::hilti::rt::optional::valueOrInit((*__self)._anon_4), __cur) = (__x_3 = ::hilti::rt::integer::unpack<uint8_t>(__cur, ::hilti::rt::ByteOrder{::hilti::rt::ByteOrder::Network}), hilti::rt::make_result(std::make_tuple(hilti::rt::make_bitfield((*__hlt::foo::FOO3), hilti::rt::integer::noop(std::get<0>(*__x_3))), std::get<1>(*__x_3)))).valueOrThrow();
                                                                                                                                                                                                                                    ^
4 errors generated.
[error] spicyc: JIT compilation failed
@bbannier bbannier added Bug Something isn't working Regression labels Sep 25, 2023
@bbannier bbannier mentioned this issue Sep 22, 2023
9 tasks
@bbannier bbannier self-assigned this Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant