Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Incorrect resolution of class in anonymous namespace

Andrew_Smith1
Beginner
323 Views

Hii

We came across an issue in our Intel (2016) compiler build where it appears separate, but identically named, classes in anonymous namespaces are not being resolved correctly. We've managed to create small example that illustrates the problem, and wondered if somebody could please investigate.

In the attached source you can see two definitions of class Local within anaonymous namespaces in separate translation units (case1.cpp and case2.cpp). What appears to be happening is that the two objects are not being resolved correctly, and in this case a segmentation fault ensues when the object is accessed.

Compare the output from g++ (4.9):

We are in case1
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): new N12_GLOBAL__N_15LocalE sized as 8 @ 0x1cad7010

We are in case2
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): new N12_GLOBAL__N_15LocalE sized as 8 @ 0x1cad7080

We are in case1
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0x1cad7010
myA=XXX

We are in case2
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0x1cad7080
myA=1234567

and that from icpc:

We are in case1
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): new N12_GLOBAL__N_15LocalE sized as 8 @ 0x6d59010

We are in case2
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0x6d59010

We are in case1
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0x6d59010
Segmentation fault

In the latter you will see that both the case1 and case2 objects are at the same address, and then we get a segfault, according to gdb, on attempting to print the member variable (at case1.cpp:26)

To build this example just run "make CXX=icpc" and/or "make CXX=g++"

Thanks,
Andrew

PS Just noticed the issue has already been raised here: https://software.intel.com/en-us/forums/intel-c-compiler/topic/597089

 

 

0 Kudos
3 Replies
Judith_W_Intel
Employee
323 Views

 

The bug report mentioned in the other thread (DPD200377293) was fixed on 11/23 and I tried you test case and it appears to have fixed this too. So the next 16.0 update (update 2) should contain the fix. Sorry for the inconvenience.

This is what I see with the current 16.0 development compiler:

sptel37-33> make "CXX=icc49"
icc49 -g -std=c++11   -c -o case1.o case1.cpp
icc49 -g -std=c++11   -c -o case2.o case2.cpp
icc49 -g -std=c++11   -c -o main.o main.cpp
icc49 case1.o case2.o main.o -o example
sptel37-34> ./example

We are in case1
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): new N12_GLOBAL__N_15LocalE sized as 8 @ 0xd79010

We are in case2
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): new N12_GLOBAL__N_15LocalE sized as 8 @ 0xd79080

We are in case1
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0xd79010
myA=XXX

We are in case2
instance(): N12_GLOBAL__N_15LocalE sized as 8
getThreadLocalInstance(): current N12_GLOBAL__N_15LocalE sized as 8 @ 0xd79080
myA=1234567
sptel37-35>

0 Kudos
KitturGanesh
Employee
323 Views

I agree, thanks Judy.  As soon as the release (16.0 update 2) is out, I'll update the thread here, fyi.

_Kittur

0 Kudos
KitturGanesh
Employee
323 Views

Hi Andrew, 
This issue is fixed in the latest 16.0 update 2 release which you can download from the Intel registration center and test it out, thanks.

Kittur

0 Kudos
Reply