ImageMagick / ImageMagick/libfpx

Buid fails with -Werror=strict-aliasing (lto)

Open
#6 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
5
Forks
8
PR merge metrics
No merged PRs in 30d

Description

When using CFLAGS="-Werror=strict-aliasing, the build fails:

oleprop.cpp: In member function ‘virtual OLEProperty::operator FILETIME() const’:
oleprop.cpp:179:59: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing]]
  179 | OLEProperty::operator FILETIME() const          { return *(FILETIME *)(&V_CY(&val)); }
      |                                                           ^~~~~~~~~~~~~~~~~~~~~~~~~
oleprop.cpp:179:59: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing]]
oleprop.cpp: In member function ‘virtual FILETIME& OLEProperty::operator=(const FILETIME&)’:
oleprop.cpp:260:99: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing]]
  260 |  FILETIME& v) { Clear(); V_CY(&val) = *((CY *)&v); return *((FILETIME *)&V_CY(&val)); }
      |                                                            ~^~~~~~~~~~~~~~~~~~~~~~~~

olestrm.cpp: In member function ‘Boolean OLEStream::VTtoString(VARIANT*, char**)’:
olestrm.cpp:2228:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing]]
 2228 |       li = *(LARGE_INTEGER *)&V_CY(variant);
olestrm.cpp:2228:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing]]
olestrm.cpp:2238:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing]]
 2238 |       li = *(LARGE_INTEGER *)&V_CY(variant);
olestrm.cpp:2238:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing]]

This was reported to us in Gentoo bug 859913.

Why would we enable this if it makes the build fail? Newer compilers are becoming more strict about what they will accept, and especially with link-time optimization (LTO), are beginning to make some more assumptions about the code. Gentoo is a source-based distribution and one of the main benefits of that is that users are free to enable link-time optimization themselves. But, as a safety net, it's a good idea to enable -Werror=strict-aliasing when doing so. You want the build to fail if the optimization pass might break the code; this prevents our users from winding up with a broken package installed.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported expressions in oleprop.cpp at lines 179 and 260, then inspect the VTtoString code in olestrm.cpp at lines 2228 and 2238. Reproduce the failure with -Werror=strict-aliasing and LTO enabled. Done means the build completes without strict-aliasing errors while preserving the affected conversions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.