Community
cancel
Showing results for 
Search instead for 
Did you mean: 
ZES
Beginner
80 Views

[Bug Report] miscompiles static locals of function template instantiations icpc (ICC) 15.0.3 20150407

Using boost::function with functors defined in local namespaces of TUs is currently broken if the functor is a class that has the same name in multiple TUs, because boost::function uses static locals in its implementations. We were able to reduce the problem to the following testcase

a1.cc:

    template<typename T>
    int f(T) { static int x = T::x; return x; }

    namespace { struct A { static const int x = 1; }; }
   
    int f1() {
       return f(A());
    }

a2.cc:

    template<typename T>
    int f(T) { static int x = T::x; return x; }
    
    namespace { struct A { static const int x = 0; }; }
    
    int f2() {
       return f(A());
    }

main.cc:

    #include <cstdio>
    
    int f1();
    int f2();
    
    int main() {
       std::printf("%d != %d\n", f1(), f2());
    } 

Command line:

    # icpc a1.cc a2.cc main.cc -o main
    # ./main
    0 != 0

When inspecting the produced symbols with readelf, we noted that while `f` is has local linkage, as we think it should have, the `x` static variable receives weak linkage and gets the same mangled name and therefore the two `x`'es are merged and it becomes lottery which is chosen.
    
    # icpc a2.cc a1.cc main.cc -o main
    # ./main
    1 != 1

GCC compiles this and produces the expected output. I also asked on Stackoverflow about it, see http://stackoverflow.com/questions/33262590/are-static-locals-of-function-template-specializations-with-t-unnamed-namespace

0 Kudos
5 Replies
Melanie_B_Intel
Employee
80 Views

We have DPD200377293 tracking this issue in our internal bugs database.  Thanks for reporting it, and thanks for the test case. --Melanie

ZES
Beginner
80 Views

Thank you for that quick reply! Can you provide us any more information about your further steps? (Severity level, plans for an update)? Is it possible to get some sort of notification as soon as this issue is fixed in a future version?
Kittur_G_Intel
Employee
80 Views

Thanks Melanie, I've updated this thread with the issue number so we can monitor and let @Zes know as well. 

@Zes, Yes, this issue is being investigated and I'll keep you updated as soon as the release with the fix is out most probably at the end of this quarter (Melanie can correct me otherwise), appreciate much.

_Kittur

Kittur_G_Intel
Employee
80 Views

@Zes:  Unfortunately, the code cut off has taken place for update 1 and therefore the fix will end up in a subsequent release to the next update :-(  I'll keep you updated accordingly and again, appreciate your patience.

_Kittur

Kittur_G_Intel
Employee
80 Views

@Zes: 
Hi,
Just letting you know that this issue is fixed in the latest 16.0 update 2 release which you can download and test it out. Thanks for bringing this issue to our attention and patience through this issue as well.
_Kittur

Reply