[cfe-commits] r162835 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/init.c
Hans Wennborg
hans at hanshq.net
Wed Aug 29 01:44:49 PDT 2012
Author: hans
Date: Wed Aug 29 03:44:49 2012
New Revision: 162835
URL: http://llvm.org/viewvc/llvm-project?rev=162835&view=rev
Log:
The address of a TLS var is not compile-time constant (PR13720)
This makes Clang produce an error for code such as:
__thread int x;
int *p = &x;
The lvalue of a thread-local variable cannot be evaluated at compile
time.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/init.c
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=162835&r1=162834&r2=162835&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Aug 29 03:44:49 2012
@@ -2832,6 +2832,8 @@
}
bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
+ if (VD->isThreadSpecified())
+ return false;
if (!VD->getType()->isReferenceType()) {
if (isa<ParmVarDecl>(VD)) {
Result.set(VD, Info.CurrentCall->Index);
Modified: cfe/trunk/test/Sema/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/init.c?rev=162835&r1=162834&r2=162835&view=diff
==============================================================================
--- cfe/trunk/test/Sema/init.c (original)
+++ cfe/trunk/test/Sema/init.c Wed Aug 29 03:44:49 2012
@@ -157,3 +157,10 @@
typedef char strty[10];
struct vortexstruct { strty s; };
struct vortexstruct vortexvar = { "asdf" };
+
+// PR13720
+__thread int thread_int;
+int *thread_int_ptr = &thread_int; // expected-error{{initializer element is not a compile-time constant}}
+void f() {
+ int *p = &thread_int; // This is perfectly fine, though.
+}
More information about the cfe-commits
mailing list