#1457 G++ 4.5.0: __builtin_bswap32 errors with templates

closed-invalid
nobody
gcc (462)
2014-12-16
2010-07-26
No

GCC

Passing __builtin_bswap32 or __builtin_bswap64 (or assumedly any builtin function) as an argument to a template will cause that function to be emitted twice in the generated assembly.

See the following example. (which could probably be even further simplified if needed). Attached is a .cpp/.ii/.s set for this error as well as a simple workaround which merely wraps the built in functions with an inline function which just calls the built in. compiling with any (or no) arguments / defines it does not matter.

Note that I've seen similar issues / questions in regards to warnings from printf format strings giving warnings for "format '%u' expects type 'unsigned int', but argument 2 has type 'unsigned int'". This is likely related, but not necessarily. If desired it can be reproduced with a simple "printf("%u", __builtin_bswap32(0x78563412UL) );"

template<typename expectedType, typename actualType>
inline void CompareHelper_EQ(expectedType , actualType )
{
}

int main ()
{
// One duplicate:
CompareHelper_EQ(static_cast<uint32_t>(0x12345678UL), (static_cast<uint32_t>(0x12345678UL)) );
CompareHelper_EQ(static_cast<uint32_t>(0x12345678UL), MY_BSWAP32(static_cast<uint32_t>(0x78563412UL)));
// Another duplicate
CompareHelper_EQ(static_cast<uint64_t>(0x123456789abcdef0ULL), (static_cast<uint64_t>(0x123456789abcdef0ULL)));
CompareHelper_EQ(static_cast<uint64_t>(0x123456789abcdef0ULL), MY_BSWAP64(static_cast<uint64_t>(0xf0debc9a78563412ULL)));
}

Running Windows 7 x64. Issue occurs building win32 or win64 programs. I have tested as far back as mingw G++ version 4.3.2 and the issue is still there. The issue does not occur when building in OSX (using GCC 4.2 or 4.0).

g++ 4.5.0 -v output for reference:
Using built-in specs.
COLLECT_GCC=C:\code\foundation\tools\gcc32-4.5.0\bin\g++.exe
COLLECT_LTO_WRAPPER=c:/code/foundation/tools/gcc32-4.5.0/bin/../libexec/gcc/mingw32/4.5.0/lto-wrapper.exe
Target: mingw32
Configured with: ../../gcc-4.5.0/configure --prefix=/mingw --build=mingw32 --enable-languages=c,ada,c++,fortran,objc,obj-c++ --disable-nls --disable-win32-regis
try --enable-libgomp --disable-werror --enable-threads --disable-symvers --enable-cxx-flags='-fno-function-sections -fno-data-sections' --enable-fully-dynamic-s
tring --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-pkgversion=tdm-1 --enable-sjlj-exceptions --with-bugurl=http://tdm-gcc.tdragon.net/
bugs
Thread model: win32
gcc version 4.5.0 (tdm-1)

Discussion

  • Daniel Craig

    Daniel Craig - 2010-07-26

    .cpp, .ii, .s for simple example.

     
  • Daniel Craig

    Daniel Craig - 2010-07-26

    I neglected to add the specific printed error message. It follows:

    main.s: Assembler messages:
    main.s:79: Error: symbol `__Z16CompareHelper_EQIjjEvT_T0_' is already defined
    main.s:119: Error: symbol `__Z16CompareHelper_EQIyyEvT_T0_' is already defined

     
  • Earnie Boyd

    Earnie Boyd - 2010-07-26

    gcc version 4.5.0 (tdm-1)
    --with-bugurl=http://tdm-gcc.tdragon.net/

    This is not a MinGW distributed build and therefore we do not support it.

     
  • Earnie Boyd

    Earnie Boyd - 2010-07-26
    • status: open --> closed-invalid
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks