[LLVMbugs] [Bug 13720] New: Clang allows global initializers to take the address of __thread (TLS) variables
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Aug 28 13:48:30 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=13720
Bug #: 13720
Summary: Clang allows global initializers to take the address
of __thread (TLS) variables
Product: clang
Version: trunk
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P
Component: Frontend
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: mseaborn at chromium.org
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Clang accepts the following initializers for p1 and p2, but it should reject
them:
__thread int x;
/* gcc rejects these with "error: initializer element is not constant": */
__thread int *p1 = &x;
int *p2 = &x;
int main() {
printf("&x = %p\n", &x);
printf("p1 = %p\n", p1);
printf("p2 = %p\n", p2);
return 0;
}
The program prints the following, which suggests that p1 and p2 end up pointing
to the TLS template for x rather than the thread-local instantiation of x:
&x = 0x7f89083716f8
p1 = 0x600e18
p2 = 0x600e18
Arguably LLVM should not allow the code that Clang generates here, which is:
@x = thread_local global i32 0
@p2 = global i32* @x
...
LLVM treats @x as a constant expression, but the address of @x is not a
constant because it varies between threads.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list