strict aliasing violations in device_allocator.hpp

Issue #203 resolved
Paul Hargrove created an issue

At least g++-7.1 is reporting strict aliasing violations in the device_allocator code:

In file included from /lustre/atlas2/csc296/scratch/hargrove/upcnightly-titan/EX-titan-gemini-gnu/runtime/work/opt/upcxx/.nobs/art/47cedbcace4a9146c665fb7a741401749e1cf255/upcxx/cuda.hpp:6:0,
upcxx/.nobs/art/47cedbcace4a9146c665fb7a741401749e1cf255/upcxx/cuda.hpp:6:0,
                 from /lustre/atlas2/csc296/scratch/hargrove/upcnightly-titan/EX-titan-gemini-gnu/runtime/work/opt/upcxx/.nobs/art/47cedbcace4a9146c665fb7a741401749e1cf255/upcxx/copy.hpp:5,
                 from /lustre/atlas2/csc296/scratch/hargrove/upcnightly-titan/EX-titan-gemini-gnu/runtime/work/opt/upcxx/.nobs/art/47cedbcace4a9146c665fb7a741401749e1cf255/upcxx/upcxx.hpp:13,
                 from /lustre/atlas2/csc296/scratch/hargrove/upcnightly-titan/EX-titan-gemini-gnu/runtime/work/opt/upcxx/test/barrier.cpp:1:
/lustre/atlas2/csc296/scratch/hargrove/upcnightly-titan/EX-titan-gemini-gnu/runtime/work/opt/upcxx/.nobs/art/47cedbcace4a9146c665fb7a741401749e1cf255/upcxx/device_allocator.hpp: In destructor 'upcxx::detail::par_mutex::~par_mutex()':
/lustre/atlas2/csc296/scratch/hargrove/upcnightly-titan/EX-titan-gemini-gnu/runtime/work/opt/upcxx/.nobs/art/47cedbcace4a9146c665fb7a741401749e1cf255/upcxx/device_allocator.hpp:33:47: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
           reinterpret_cast<std::mutex*>(&raw_)->~mutex();
                                               ^~
/lustre/atlas2/csc296/scratch/hargrove/upcnightly-titan/EX-titan-gemini-gnu/runtime/work/opt/upcxx/.nobs/art/47cedbcace4a9146c665fb7a741401749e1cf255/upcxx/device_allocator.hpp: In member function 'void upcxx::detail::par_mutex::lock()':
/lustre/atlas2/csc296/scratch/hargrove/upcnightly-titan/EX-titan-gemini-gnu/runtime/work/opt/upcxx/.nobs/art/47cedbcace4a9146c665fb7a741401749e1cf255/upcxx/device_allocator.hpp:36:59: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         void lock() { reinterpret_cast<std::mutex*>(&raw_)->lock(); }
                                                           ^~

This appears, for instance, during the opt/par build of the library.

In Slack, @bonachea said:

looks fishy to me, and likely related to the comment; // TODO: need to use std::launder on the following reinterpret_cast's.

Comments (3)

  1. Log in to comment