[llvm-bugs] [Bug 33931] New: Static variable in inline function having duplicates with shared library (compiled with GCC)
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jul 25 17:49:36 PDT 2017
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: unassignedclangbugs at nondot.org
Reporter: mikebentley15 at gmail.com
CC: dgregor at apple.com, llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170726/3981e2ca/attachment.html>
More information about the llvm-bugs
mailing list