Menu

#1303 (rev 12880) (-flto enabled) Build error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]

Undefined
wont-fix
nobody
None
Undefined
2022-11-30
2022-09-02
No

On trying to build Codeblocks rev12880 (Gentoo dev-util/codeblocks-9999.ebuild) with additionally enabled GCC options -flto -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing at least 2 compilation errors arise (MAKEOPTS="-j4", GCC 11.3.0):

/bin/sh ../../../../libtool  --tag=CXX   --mode=compile x86_64-pc-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I../../../../src/include  -I../../../../src/include/scripting/include -DCB_AUTOCONF  -DNDEBUG -DPIC -DTIXML_USE_STL=YES   -march=native -O2 -pipe -flto -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fPIC -fexceptions -c -o sqcompiler.lo sqcompiler.cpp

libtool: compile:  x86_64-pc-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I../../../../src/include -I../../../../src/include/scripting/include -DCB_AUTOCONF -DNDEBUG -DPIC -DTIXML_USE_STL=YES -march=native -O2 -pipe -flto -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fPIC -fexceptions -c sqcompiler.cpp  -fPIC -DPIC -o .libs/sqcompiler.o

sqcompiler.cpp: In member function 'void SQCompiler::EmitLoadConstFloat(SQFloat, SQInteger)':
sqcompiler.cpp:892:57: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  892 |             _fs->AddInstruction(_OP_LOADFLOAT, target,*((SQInt32 *)&value));
      |                                                        ~^~~~~~~~~~~~~~~~~~
/bin/sh ../../../../libtool  --tag=CXX   --mode=compile x86_64-pc-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I../../../../src/include  -I../../../../src/include/scripting/include -DCB_AUTOCONF  -DNDEBUG -DPIC -DTIXML_USE_STL=YES   -march=native -O2 -pipe -flto -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fPIC -fexceptions -c -o sqvm.lo sqvm.cpp

libtool: compile:  x86_64-pc-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I../../../../src/include -I../../../../src/include/scripting/include -DCB_AUTOCONF -DNDEBUG -DPIC -DTIXML_USE_STL=YES -march=native -O2 -pipe -flto -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fPIC -fexceptions -c sqvm.cpp  -fPIC -DPIC -o .libs/sqvm.o

sqvm.cpp: In member function 'bool SQVM::Execute(SQObjectPtr&, SQInteger, SQInteger, SQObjectPtr&, SQBool, SQVM::ExecutionType)':
sqvm.cpp:768:44: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  768 |             case _OP_LOADFLOAT: TARGET = *((const SQFloat *)&arg1); continue;
      |                                           ~^~~~~~~~~~~~~~~~~~~~~~~
sqvm.cpp:965:43: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  965 |                     val._unVal.fFloat = *((const SQFloat *)&arg1);
      |                                          ~^~~~~~~~~~~~~~~~~~~~~~~

The full build.log is in attachment.

Disabling the -Werror=strict-aliasing (for -flto enabled) via passing option -fno-strict-aliasing workaround the problem. The could be related the distributives that use LTO profiles.

1 Attachments

Discussion

  • Miguel Gimenez

    Miguel Gimenez - 2022-09-09
    • status: open --> wont-fix
     
  • Miguel Gimenez

    Miguel Gimenez - 2022-09-09

    We use an external library that has some issues in version 3.1:
    * Breaking aliasing rules
    * Confusing indentantion
    * No return value where a bool should be returned (the function ends with assert(0))
    * Bad usage of memmove() and others.

    I have checked their current trunk, but aliasing rules are still broken. We can fix the issues on our side, but reporting them in their bug tracker is the way to go.

     

    Last edit: Miguel Gimenez 2022-09-09

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.