Bug 1448666 - gcc 7.1 warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
Summary: gcc 7.1 warning: dereferencing type-punned pointer will break strict-aliasing...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 26
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 1463739 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-05-07 00:13 UTC by Brad Hubbard
Modified: 2017-06-26 17:28 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-06-26 17:28:56 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Ceph Project Bug Tracker 19864 0 None None None 2017-05-07 00:16:05 UTC
GNU Compiler Collection 80593 0 None None None 2017-05-07 00:14:00 UTC

Description Brad Hubbard 2017-05-07 00:13:04 UTC
Description of problem:

Code that previously compiled without warning on f25 gcc 6.3.1 now generates the warning in the summary.


Version-Release number of selected component (if applicable):
gcc-c++-7.1.1-1.fc26.x86_64

How reproducible:
100%

Steps to Reproduce:
$ lsb_release -r
Release:        25
$ gcc --version
gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1)
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat << EOF > punning.cpp
#include <type_traits>
#include <mutex>

int main()
{
  std::aligned_storage<sizeof(std::mutex)>::type state_mutex_bytes;
  new (&state_mutex_bytes) std::mutex;
  std::mutex& r = *static_cast<std::mutex*>(static_cast<void*>(&state_mutex_bytes));
  (void)r;
}
EOF
$ g++ -Wall -O2 -c punning.cpp
$

$ lsb_release -r
Release:        26
$ gcc --version
gcc (GCC) 7.1.1 20170503 (Red Hat 7.1.1-1)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat << EOF > punning.cpp
#include <type_traits>
#include <mutex>

int main()
{
  std::aligned_storage<sizeof(std::mutex)>::type state_mutex_bytes;
  new (&state_mutex_bytes) std::mutex;
  std::mutex& r = *static_cast<std::mutex*>(static_cast<void*>(&state_mutex_bytes));
  (void)r;
}
EOF
$ g++ -Wall -O2 -c punning.cpp
punning.cpp: In function ‘int main()’:
punning.cpp:8:83: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   std::mutex& r = *static_cast<std::mutex*>(static_cast<void*>(&state_mutex_bytes));
                                                                                   ^


Actual results:
punning.cpp: In function ‘int main()’:
punning.cpp:8:83: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   std::mutex& r = *static_cast<std::mutex*>(static_cast<void*>(&state_mutex_bytes));

Expected results:
No warning generated

Additional info:
I believe this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80593

There is also a reproducer in the upstream bug bug I included mine because it is closer to the actual issue seen here, https://copr-be.cloud.fedoraproject.org/results/badone/Ceph-nightlies/fedora-26-x86_64/00546644-ceph/build.log.gz

Comment 2 Brad Hubbard 2017-05-30 04:52:16 UTC
I created a test package here https://copr-be.cloud.fedoraproject.org/results/badone/misc/fedora-26-x86_64/00557857-gcc/ which includes the patch for pr80593 and can confirm it allows both the test case and the original ceph (rocksdb) code to build successfully without this warning.

Comment 3 Jeff Layton 2017-06-21 23:27:51 UTC
*** Bug 1463739 has been marked as a duplicate of this bug. ***

Comment 4 Jeff Layton 2017-06-21 23:34:23 UTC
Jakub, any chance we can get the patch for this into the F26 package until it gets synched up to mainline? It's kind of a hinderance for building ceph at the moment.

Comment 5 Jakub Jelinek 2017-06-26 17:28:56 UTC
Should be fixed now.


Note You need to log in before you can comment on or make changes to this bug.