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

Clang build error with BOOST_THREAD_ATTRIBUTE_MAY_ALIAS #145

Closed
egorpugin opened this Issue Sep 13, 2017 · 24 comments

Comments

Projects
None yet
2 participants
@egorpugin

egorpugin commented Sep 13, 2017

Clang output:

-c src/pthread/thread.cpp
In file included from src/pthread/thread.cpp:17:
In file included from include/boost/thread/once.hpp:20:
include/boost/thread/pthread/once_atomic.hpp:91:5: error: unknown type name 'BOOST_THREAD_ATTRIBUTE_MAY_ALIAS'
    BOOST_THREAD_ATTRIBUTE_MAY_ALIAS thread_detail::atomic_int_type storage;
    ^
include/boost/thread/pthread/once_atomic.hpp:91:53: error: non-friend class member 'atomic_int_type' cannot have a qualified name
    BOOST_THREAD_ATTRIBUTE_MAY_ALIAS thread_detail::atomic_int_type storage;
                                     ~~~~~~~~~~~~~~~^
include/boost/thread/pthread/once_atomic.hpp:91:68: error: expected ';' at end of declaration list
    BOOST_THREAD_ATTRIBUTE_MAY_ALIAS thread_detail::atomic_int_type storage;
                                                                   ^
include/boost/thread/pthread/once_atomic.hpp:100:52: error: no member named 'storage' in 'boost::once_flag'
      return reinterpret_cast< atomic_type& >(flag.storage);
                                              ~~~~ ^

See these lines https://github.com/boostorg/thread/blob/develop/include/boost/thread/detail/config.hpp#L20

It's suspicious that in #ifndef we define macro to nothing and then instantly set it to MAY_ALIAS.
Maybe there's missing #else?

I have a custom build (b2 is not used), so it's possible that I could miss some flags set.

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 13, 2017

Collaborator

This has been introduced in 23e7135#diff-54af14da6bc000f779c91e3087132068

Please, could you just try with

#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS

Andrey, what do you think?

Collaborator

viboes commented Sep 13, 2017

This has been introduced in 23e7135#diff-54af14da6bc000f779c91e3087132068

Please, could you just try with

#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS

Andrey, what do you think?

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 13, 2017

Collaborator

BOOST_THREAD_DETAIL_USE_ATTRIBUTE_MAY_ALIAS is not used anymore.

I suspect that BOOST_MAY_ALIAS is not defined on your configuration.

Please, could you check if it is defined. If not could you try

#ifdef BOOST_MAY_ALIAS
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS
#else
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS
#endif
Collaborator

viboes commented Sep 13, 2017

BOOST_THREAD_DETAIL_USE_ATTRIBUTE_MAY_ALIAS is not used anymore.

I suspect that BOOST_MAY_ALIAS is not defined on your configuration.

Please, could you check if it is defined. If not could you try

#ifdef BOOST_MAY_ALIAS
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS
#else
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS
#endif
@egorpugin

This comment has been minimized.

Show comment
Hide comment
@egorpugin

egorpugin Sep 13, 2017

I empty-defined BOOST_THREAD_ATTRIBUTE_MAY_ALIAS and it works for me. It's ok as a workaround. (Did not try your suggestion.)

egorpugin commented Sep 13, 2017

I empty-defined BOOST_THREAD_ATTRIBUTE_MAY_ALIAS and it works for me. It's ok as a workaround. (Did not try your suggestion.)

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 14, 2017

Collaborator

Obviously, I can not define it as empty :)
Please give a try to my last suggestion:

#ifdef BOOST_MAY_ALIAS
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS
#else
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS
#endif
Collaborator

viboes commented Sep 14, 2017

Obviously, I can not define it as empty :)
Please give a try to my last suggestion:

#ifdef BOOST_MAY_ALIAS
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS
#else
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS
#endif
@egorpugin

This comment has been minimized.

Show comment
Hide comment
@egorpugin

egorpugin commented Sep 14, 2017

It works.

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 14, 2017

Collaborator

Great, I will fix it.

Thanks for reporting and supporting the test.

Collaborator

viboes commented Sep 14, 2017

Great, I will fix it.

Thanks for reporting and supporting the test.

@egorpugin

This comment has been minimized.

Show comment
Hide comment
@egorpugin

egorpugin Sep 14, 2017

Ok, thanks!

egorpugin commented Sep 14, 2017

Ok, thanks!

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 14, 2017

Collaborator

The issue comes from the fact that BOOST_MAY_ALIAS is not always defined

// Type aliasing hint.
#if __has_attribute(__may_alias__)
#  define BOOST_MAY_ALIAS __attribute__((__may_alias__))
#endif

Wondering if this should be

// Type aliasing hint.
#if __has_attribute(__may_alias__)
#  define BOOST_MAY_ALIAS __attribute__((__may_alias__))
#else
#  define BOOST_MAY_ALIAS
#endif

but BOOST_MAY_ALIAS is not documented.

I've created a Boost.Config ticket. https://svn.boost.org/trac10/ticket/13211

Collaborator

viboes commented Sep 14, 2017

The issue comes from the fact that BOOST_MAY_ALIAS is not always defined

// Type aliasing hint.
#if __has_attribute(__may_alias__)
#  define BOOST_MAY_ALIAS __attribute__((__may_alias__))
#endif

Wondering if this should be

// Type aliasing hint.
#if __has_attribute(__may_alias__)
#  define BOOST_MAY_ALIAS __attribute__((__may_alias__))
#else
#  define BOOST_MAY_ALIAS
#endif

but BOOST_MAY_ALIAS is not documented.

I've created a Boost.Config ticket. https://svn.boost.org/trac10/ticket/13211

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 14, 2017

Collaborator

It is weird. Please could you confirm you have this code in file /boost/config/detail/sufix.hpp?

#if !defined(BOOST_MAY_ALIAS)
#  define BOOST_NO_MAY_ALIAS
#  define BOOST_MAY_ALIAS
#endif
Collaborator

viboes commented Sep 14, 2017

It is weird. Please could you confirm you have this code in file /boost/config/detail/sufix.hpp?

#if !defined(BOOST_MAY_ALIAS)
#  define BOOST_NO_MAY_ALIAS
#  define BOOST_MAY_ALIAS
#endif
@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 14, 2017

Collaborator

BTW, this was as it is since the 12 Jul.
boostorg/config@4a58e53#diff-57dd29863d0bc07f45bc221f60715f97

Which version of boost are you using?

Collaborator

viboes commented Sep 14, 2017

BTW, this was as it is since the 12 Jul.
boostorg/config@4a58e53#diff-57dd29863d0bc07f45bc221f60715f97

Which version of boost are you using?

@egorpugin

This comment has been minimized.

Show comment
Hide comment
@egorpugin

egorpugin commented Sep 14, 2017

1.65.0

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 18, 2017

Collaborator

I would need the output of the pre-processor, as I don't see what is wrong.

Collaborator

viboes commented Sep 18, 2017

I would need the output of the pre-processor, as I don't see what is wrong.

@viboes viboes added the bug label Sep 18, 2017

@egorpugin

This comment has been minimized.

Show comment
Hide comment
@egorpugin

egorpugin Sep 18, 2017

In include/boost/thread/detail/config.hpp#L20 you have now:

#if BOOST_MAY_ALIAS // == #if !!BOOST_MAY_ALIAS
#define BOOST_THREAD_DETAIL_USE_ATTRIBUTE_MAY_ALIAS // define to nothing
#endif
#define BOOST_THREAD_DETAIL_USE_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS // unconditional may alias

egorpugin commented Sep 18, 2017

In include/boost/thread/detail/config.hpp#L20 you have now:

#if BOOST_MAY_ALIAS // == #if !!BOOST_MAY_ALIAS
#define BOOST_THREAD_DETAIL_USE_ATTRIBUTE_MAY_ALIAS // define to nothing
#endif
#define BOOST_THREAD_DETAIL_USE_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS // unconditional may alias
@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 18, 2017

Collaborator

This is not what I see.

#if !defined(BOOST_NO_MAY_ALIAS)

  // GCC since 3.3 and some other compilers have may_alias attribute that helps
  // to alleviate optimizer issues with regard to violation of the strict aliasing rules.

  #define BOOST_THREAD_DETAIL_USE_ATTRIBUTE_MAY_ALIAS
#endif
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS

See https://github.com/boostorg/thread/blob/develop/include/boost/thread/detail/config.hpp#L20

Collaborator

viboes commented Sep 18, 2017

This is not what I see.

#if !defined(BOOST_NO_MAY_ALIAS)

  // GCC since 3.3 and some other compilers have may_alias attribute that helps
  // to alleviate optimizer issues with regard to violation of the strict aliasing rules.

  #define BOOST_THREAD_DETAIL_USE_ATTRIBUTE_MAY_ALIAS
#endif
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS

See https://github.com/boostorg/thread/blob/develop/include/boost/thread/detail/config.hpp#L20

@egorpugin

This comment has been minimized.

Show comment
Hide comment
@egorpugin

egorpugin Sep 18, 2017

Yes, but after simplification? You have double negation and get #ifdef BOOST_MAY_ALIAS.
Next, no matter what's inside of this ifdef, you always assign BOOST_MAY_ALIAS to BOOST_THREAD_ATTRIBUTE_MAY_ALIAS. Whole ifdef does not make sense.

Correct me if I'm getting something wrong in this small piece of code (preprocessor).

egorpugin commented Sep 18, 2017

Yes, but after simplification? You have double negation and get #ifdef BOOST_MAY_ALIAS.
Next, no matter what's inside of this ifdef, you always assign BOOST_MAY_ALIAS to BOOST_THREAD_ATTRIBUTE_MAY_ALIAS. Whole ifdef does not make sense.

Correct me if I'm getting something wrong in this small piece of code (preprocessor).

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 18, 2017

Collaborator

There are two symbols BOOST_NO_MAY_ALIAS and BOOST_MAY_ALIAS. The last is always defined. The fist not.

Collaborator

viboes commented Sep 18, 2017

There are two symbols BOOST_NO_MAY_ALIAS and BOOST_MAY_ALIAS. The last is always defined. The fist not.

@egorpugin

This comment has been minimized.

Show comment
Hide comment
@egorpugin

egorpugin Sep 19, 2017

I see, thanks.

egorpugin commented Sep 19, 2017

I see, thanks.

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 19, 2017

Collaborator

So I don't understand where is the problem. Why is there a compile error?
Could you add the command line and the preprocessed output (flag -E)?

Collaborator

viboes commented Sep 19, 2017

So I don't understand where is the problem. Why is there a compile error?
Could you add the command line and the preprocessed output (flag -E)?

@egorpugin

This comment has been minimized.

Show comment
Hide comment
@egorpugin

egorpugin Sep 19, 2017

Sure.

Full command and preprocessed output:
$ cd /Users/egor/.cppan/storage/obj/3b/8a/68a4/build/f7add531/cppan/3b8a68a4 && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DBOOST_ALL_DYN_LINK -DBOOST_ATOMIC_DYN_LINK -DBOOST_ATOMIC_USE_DLL -DBOOST_CHRONO_DYN_LINK -DBOOST_CHRONO_USE_DLL -DBOOST_DATE_TIME_DYN_LINK -DBOOST_DATE_TIME_USE_DLL -DBOOST_SYSTEM_DYN_LINK -DBOOST_SYSTEM_USE_DLL -DBOOST_THREAD_BUILDING_THE_LIB -DBOOST_THREAD_BUILD_DLL -DBOOST_THREAD_DYN_LINK -DBOOST_THREAD_SOURCE -DBOOST_THREAD_USE_DLL -DCPPAN -DCPPAN_API_pvt_cppan_demo_boost_atomic_1_65_0=CPPAN_SYMBOL_IMPORT -DCPPAN_API_pvt_cppan_demo_boost_chrono_1_65_0=CPPAN_SYMBOL_IMPORT -DCPPAN_API_pvt_cppan_demo_boost_date_time_1_65_0=CPPAN_SYMBOL_IMPORT -DCPPAN_API_pvt_cppan_demo_boost_system_1_65_0=CPPAN_SYMBOL_IMPORT -DCPPAN_API_pvt_cppan_demo_boost_thread_1_65_0=CPPAN_SYMBOL_EXPORT -DCPPAN_BUILD -DCPPAN_CONFIG=\"91a9a0e5\" -DCPPAN_SYMBOL_EXPORT="" -DCPPAN_SYMBOL_IMPORT="" -DHAVE_SIZE_T=1 -DHAVE_VOID_P=1 -DPACKAGE=\"pvt.cppan.demo.boost.thread\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_BUILD_CONFIG=\"Release\" -DPACKAGE_COPYRIGHT_YEAR=2017 -DPACKAGE_NAME=\"pvt.cppan.demo.boost.thread\" -DPACKAGE_NAME_LAST=\"thread\" -DPACKAGE_STRING=\"3b8a68a4\" -DPACKAGE_URL=\"\" -DPACKAGE_VERSION=\"1.65.0\" -DSIZEOF_SIZE_T=8 -DSIZEOF_VOID_P=8 -DSIZE_OF_SIZE_T=8 -DSIZE_OF_VOID_P=8 -D_3b8a68a4_EXPORTS @CMakeFiles/3b8a68a4.dir/includes_CXX.rsp -O3 -DNDEBUG -fPIC -Wno-macro-redefined -c /Users/egor/.cppan/storage/src/3b/8a/68a4/src/pthread/thread.cpp -E > thread.pp

thread.pp.zip

egorpugin commented Sep 19, 2017

Sure.

Full command and preprocessed output:
$ cd /Users/egor/.cppan/storage/obj/3b/8a/68a4/build/f7add531/cppan/3b8a68a4 && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DBOOST_ALL_DYN_LINK -DBOOST_ATOMIC_DYN_LINK -DBOOST_ATOMIC_USE_DLL -DBOOST_CHRONO_DYN_LINK -DBOOST_CHRONO_USE_DLL -DBOOST_DATE_TIME_DYN_LINK -DBOOST_DATE_TIME_USE_DLL -DBOOST_SYSTEM_DYN_LINK -DBOOST_SYSTEM_USE_DLL -DBOOST_THREAD_BUILDING_THE_LIB -DBOOST_THREAD_BUILD_DLL -DBOOST_THREAD_DYN_LINK -DBOOST_THREAD_SOURCE -DBOOST_THREAD_USE_DLL -DCPPAN -DCPPAN_API_pvt_cppan_demo_boost_atomic_1_65_0=CPPAN_SYMBOL_IMPORT -DCPPAN_API_pvt_cppan_demo_boost_chrono_1_65_0=CPPAN_SYMBOL_IMPORT -DCPPAN_API_pvt_cppan_demo_boost_date_time_1_65_0=CPPAN_SYMBOL_IMPORT -DCPPAN_API_pvt_cppan_demo_boost_system_1_65_0=CPPAN_SYMBOL_IMPORT -DCPPAN_API_pvt_cppan_demo_boost_thread_1_65_0=CPPAN_SYMBOL_EXPORT -DCPPAN_BUILD -DCPPAN_CONFIG=\"91a9a0e5\" -DCPPAN_SYMBOL_EXPORT="" -DCPPAN_SYMBOL_IMPORT="" -DHAVE_SIZE_T=1 -DHAVE_VOID_P=1 -DPACKAGE=\"pvt.cppan.demo.boost.thread\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_BUILD_CONFIG=\"Release\" -DPACKAGE_COPYRIGHT_YEAR=2017 -DPACKAGE_NAME=\"pvt.cppan.demo.boost.thread\" -DPACKAGE_NAME_LAST=\"thread\" -DPACKAGE_STRING=\"3b8a68a4\" -DPACKAGE_URL=\"\" -DPACKAGE_VERSION=\"1.65.0\" -DSIZEOF_SIZE_T=8 -DSIZEOF_VOID_P=8 -DSIZE_OF_SIZE_T=8 -DSIZE_OF_VOID_P=8 -D_3b8a68a4_EXPORTS @CMakeFiles/3b8a68a4.dir/includes_CXX.rsp -O3 -DNDEBUG -fPIC -Wno-macro-redefined -c /Users/egor/.cppan/storage/src/3b/8a/68a4/src/pthread/thread.cpp -E > thread.pp

thread.pp.zip

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 19, 2017

Collaborator

It is weird. We have

    BOOST_MAY_ALIAS thread_detail::atomic_int_type storage;

When we have

#if !defined(BOOST_MAY_ALIAS)
#  define BOOST_NO_MAY_ALIAS
#  define BOOST_MAY_ALIAS
#endif
// ....
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS

How is it that BOOST_MAY_ALIAShas not been replaced?

Collaborator

viboes commented Sep 19, 2017

It is weird. We have

    BOOST_MAY_ALIAS thread_detail::atomic_int_type storage;

When we have

#if !defined(BOOST_MAY_ALIAS)
#  define BOOST_NO_MAY_ALIAS
#  define BOOST_MAY_ALIAS
#endif
// ....
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS

How is it that BOOST_MAY_ALIAShas not been replaced?

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 19, 2017

Collaborator

Anyway, I'll commit

#ifdef BOOST_MAY_ALIAS
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS
#else
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS
#endif

As it works for you.

Collaborator

viboes commented Sep 19, 2017

Anyway, I'll commit

#ifdef BOOST_MAY_ALIAS
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS
#else
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS
#endif

As it works for you.

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 19, 2017

Collaborator
Collaborator

viboes commented Sep 19, 2017

@viboes viboes added the boost-1.66 label Sep 19, 2017

@egorpugin

This comment has been minimized.

Show comment
Hide comment
@egorpugin

egorpugin Sep 19, 2017

Thanks!
Should I close?

egorpugin commented Sep 19, 2017

Thanks!
Should I close?

@egorpugin egorpugin closed this Sep 19, 2017

@viboes

This comment has been minimized.

Show comment
Hide comment
@viboes

viboes Sep 20, 2017

Collaborator

No problem, I prefer to close once I have do the merge to master.

Collaborator

viboes commented Sep 20, 2017

No problem, I prefer to close once I have do the merge to master.

@viboes viboes added this to the 1.66 milestone Oct 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment