https://bugs.llvm.org/show_bug.cgi?id=33931

            Bug ID: 33931
           Summary: Static variable in inline function having duplicates
                    with shared library (compiled with GCC)
           Product: clang
           Version: 3.9
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: mikebentle...@gmail.com
                CC: dgre...@apple.com, llvm-bugs@lists.llvm.org

Created attachment 18847
  --> https://bugs.llvm.org/attachment.cgi?id=18847&action=edit
minimal reproducible example

This is a strange use case, but it is my use case.

Suppose you have an inline function with a static variable, such as

inline std::map<std::string, void*>& get_tests() {
  static std::map<std::string, void*> tests;
  return tests;
}

that is defined in a header file for a shared library.  Seems reasonable,
right?  Now suppose the shared library is compiled with GCC 5.4.0, also
reasonable.  Then you create an application that uses this inline function and
compile your application with Clang.  What happens is that the shared library,
when it calls this function, will have one copy of the static variable
different from the one in the application.

I have attached code that can duplicate this problem.  This has been tested
with GCC 5.4.0 (and a little with GCC 6.1).  I notice that this problem is NOT
there with GCC 4.9.  So, I actually do not know if this is a Clang bug or a GCC
bug.

In the example code, I demonstrate that everything is okay when using a static
integer, but it fails when using a static map.  I don't know what other kinds
of objects would have this problem.

Tested with the following versions of Clang:
- 3.9.0 final release
- 3.9.1 final release
- 4.0.0 final release
- 4.0.1 final release
- 5.0.0
  - This is the one I have installed from building cling
  - http://root.cern.ch/git/clang.git 1f8b137c7eb06ed8e321649ef7e3f3e7a96f361c
  - http://root.cern.ch/git/llvm.git 2a34248cb945d63ded5ee55128e68efd7e5b87c8

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to