problem with attribute aligned for struct/union in boost

Hi

it seems that pgc++ (15.7) does not support

__attribute__ ((__aligned__(x)))

with x>= 0x100, smaller values seem to be OK.

In boost/config/suffix.hpp the following alignment specifcation appears:

// Type and data alignment specification
//
#if !defined(BOOST_NO_CXX11_ALIGNAS)
#  define BOOST_ALIGNMENT(x) alignas(x)
#elif defined(_MSC_VER)
#  define BOOST_ALIGNMENT(x) __declspec(align(x))
#elif defined(__GNUC__)
#  define BOOST_ALIGNMENT(x) __attribute__ ((__aligned__(x)))
#else
#  define BOOST_NO_ALIGNMENT
#  define BOOST_ALIGNMENT(x)
#endif

pgc++ seems to define GNUC so BOOST_ALLIGNMENT(x) is defined as attribute ((aligned(x))).
In boost/move/detail/type_traits.hpp the BOOST_ALIGNMENT macro is used:

/////////////////////////////
//    aligned_storage
/////////////////////////////

#if !defined(BOOST_NO_ALIGNMENT)

template<std::size_t Len, std::size_t Align>
struct aligned_storage_impl;

#define BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(A)\
template<std::size_t Len>\
struct BOOST_ALIGNMENT(A) aligned_storage_impl<Len, A>\
{\
   char dummy[Len];\
   typedef aligned_storage_impl<Len, A> type;\
};\
//

//Up to 4K alignment (typical page size)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x2)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x4)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x8)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x10)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x20)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x40)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x80)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x100)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x200)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x400)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x800)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1000)

#undef BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT

#else //BOOST_NO_ALIGNMENT

When including e.g. boost/move/move.hpp pgc++ produces the following errors:

../boost/move/detail/type_traits.hpp", line 921: error:
          invalid alignment value specified by attribute
  BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x100)
  ^

"../boost/move/detail/type_traits.hpp", line 922: error:
          invalid alignment value specified by attribute
  BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x200)
  ^

"../boost/move/detail/type_traits.hpp", line 923: error:
          invalid alignment value specified by attribute
  BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x400)
  ^

"../boost/move/detail/type_traits.hpp", line 924: error:
          invalid alignment value specified by attribute
  BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x800)
  ^

"../boost/move/detail/type_traits.hpp", line 925: error:
          invalid alignment value specified by attribute
  BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1000)
  ^

5 errors detected in the compilation of "main.C".

The only workaround I found was to add

#elif defined(__PGI)
#  define BOOST_NO_ALIGNMENT
#  define BOOST_ALIGNMENT(x)

above

#elif defined(__GNUC__)
#  define BOOST_ALIGNMENT(x) __attribute__ ((__aligned__(x)))

to basically switch off alignment. However, this probably has an impact on performance.

Thanks,
LS

Hi LS,

Correct, we don’t support attribute align with the these larger values. I think you should be fine with your work around, though I thought there’s a Boost define which will disable alignment (Sorry, I don’t remember the name off-hand).

  • Mat

Hi Mat

thanks for confirming this issue. Are you referring to the following Boost define:

BOOST_DISABLE_ABI_HEADERS
Stops boost headers from including any prefix/suffix headers that normally control things like struct packing and alignment.

Or how about just commenting out

BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x100)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x200)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x400)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x800)
BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1000)

i.e. to avoid using attribute align with these larger values?
What would you recommend?

Thanks,
LS

Without looking at it in detail, it’s difficult to give a good recommendation. Though, we tend to ignore alignment directives since we align by default with 64-bit compilations. Hence, I think in this case it’s probably better to use the define instead of adding additional conditional compilation directives.