Bug 70570 - Assembler error "symbol already defined" from nested lambdas and function-static variable
Summary: Assembler error "symbol already defined" from nested lambdas and function-sta...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.3.0
: P3 normal
Target Milestone: 6.2
Assignee: Not yet assigned to anyone
URL:
Keywords: assemble-failure, wrong-code
Depends on:
Blocks:
 
Reported: 2016-04-07 03:32 UTC by Nick Krempel
Modified: 2017-10-02 22:23 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 5.3.0, 6.0
Last reconfirmed: 2016-08-02 00:00:00


Attachments
Minimal test case, compile with g++ -std=c++14 (123 bytes, text/plain)
2016-04-07 03:32 UTC, Nick Krempel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Krempel 2016-04-07 03:32:54 UTC
Created attachment 38209 [details]
Minimal test case, compile with g++ -std=c++14

Referring to a function-static variable from within both of two nested lambda functions (the outer one being generic/polymorphic) causes an assembler error (symbol already defined).

Minimal test case attached, tested on g++ 5.3.0.
Comment 1 Richard Biener 2016-04-12 09:46:48 UTC
Confirmed.  GCC 4.9 complains:

> g++-4.9 t.C -std=c++14 
t.C: In instantiation of ‘main()::<lambda(auto:1)> [with auto:1 = int]’:
t.C:2:8:   required from ‘void foo(T) [with T = main()::<lambda(auto:1)>]’
t.C:12:3:   required from here
t.C:8:2: error: ‘x’ was not declared in this scope
  x;
  ^
Comment 2 Jesse Haber-Kucharsky 2017-07-12 21:44:21 UTC
I believe this bug manifested itself in Seastar (https://github.com/scylladb/seastar/commit/3d21ef5959bedb3ea15032d1632b0b2d7012044a).

The original snippet from Nick causes the error on Fedora 23:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/5.3.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --disable-libgcj --with-isl --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 5.3.1 20160406 (Red Hat 5.3.1-6) (GCC)

and on Ubuntu 16.04:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)

On both platforms, the error is the same:

g++ -std=c++14 test.cc -o test
/tmp/ccTNkOnu.s: Assembler messages:
/tmp/ccTNkOnu.s:34: Error: symbol `_ZL1x' is already defined


On gcc 7.1.1, the error is not present:

Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 7.1.1 20170622 (Red Hat 7.1.1-3) (GCC)

To reproduce the exact compilation error with Seastar:

docker pull fedora:23
docker run -it --rm fedora:23 bash
dnf install -y git
cd opt && git clone https://github.com/scylladb/seastar
git checkout a2be7a4f312a62c67c79cf818970d0c954f5fc15
git submodule update --init
./install-dependencies.sh
./configure.py --mode=debug
ninja-build build/debug/tests/lowres_clock_test.o

The error:

g++ -MD -MT build/debug/tests/lowres_clock_test.o -MF build/debug/tests/lowres_clock_test.o.d -fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-sanitize=vptr -DASAN_ENABLED -O0 -DDEBUG -DDEBUG_SHARED_PTR -DDEFAULT_ALLOCATOR -DSEASTAR_THREAD_STACK_GUARDS -I/opt/seastar/build/debug/gen -I/opt/seastar/build/debug/c-ares -std=gnu++1y -g  -Wall -Werror -Wno-error=deprecated-declarations -fvisibility=hidden  -pthread -I/opt/seastar -U_FORTIFY_SOURCE  -I/opt/seastar/fmt -DBOOST_TEST_DYN_LINK -Wno-overloaded-virtual -Wno-maybe-uninitialized -DFMT_HEADER_ONLY -DHAVE_HWLOC -DHAVE_NUMA -DHAVE_LZ4_COMPRESS_DEFAULT -c -o build/debug/tests/lowres_clock_test.o tests/lowres_clock_test.cc
/tmp/cch6C9Km.s: Assembler messages:
/tmp/cch6C9Km.s:19986: Error: symbol `_ZL14sleep_duration' is already defined


I've attached the lowres_clock_test.ii file.
Comment 3 Jesse Haber-Kucharsky 2017-07-12 21:49:24 UTC
The .ii file is too large to attach. I hope the previous information I supplied is sufficient and helpful.
Comment 4 paolo@gcc.gnu.org 2017-10-02 22:21:47 UTC
Author: paolo
Date: Mon Oct  2 22:21:16 2017
New Revision: 253370

URL: https://gcc.gnu.org/viewcvs?rev=253370&root=gcc&view=rev
Log:
2017-10-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/70570
	* g++.dg/cpp1y/lambda-generic-70570.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/lambda-generic-70570.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 5 Paolo Carlini 2017-10-02 22:23:21 UTC
Fixed a while ago, in 6.2.0. I added the testcase.