https://bugs.llvm.org/show_bug.cgi?id=45351
Bug ID: 45351
Summary: function static variable instantiated at -O2 despite
extern template
Product: clang
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangb...@nondot.org
Reporter: sbenc...@gmail.com
CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
richard-l...@metafoo.co.uk
Created attachment 23291
--> https://bugs.llvm.org/attachment.cgi?id=23291&action=edit
example
In the below example func is inlined and function_local_static becomes a
defined symbol when compiled with -O2 and above regardless of extern template
class declaration.
The problem is solved by adding -fno-inline .
Same can be observed with clang above 5.0 (works with 4.0.1), all gcc versions
(bugzilla ID 92359), icc, but not with msvc.
This is problematic when one tries to rely on the extern template mechanism in
shared libraries. The result is that function static variables get instantiated
more than 1 times.
Attached you find a minimal example showing exactly this.
minimal example that shows function_local_static being defined at -O2:
template <typename T>
struct S {
int func() {
static int function_local_static = 0;
return ++function_local_static;
}
};
extern template class S<int>;
int user()
{
return S<int>().func();
}
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs