]> granicus.if.org Git - clang/commitdiff
The address of a TLS var is not compile-time constant (PR13720)
authorHans Wennborg <hans@hanshq.net>
Wed, 29 Aug 2012 08:44:49 +0000 (08:44 +0000)
committerHans Wennborg <hans@hanshq.net>
Wed, 29 Aug 2012 08:44:49 +0000 (08:44 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162835 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/Sema/init.c

index e2d5c7515a914c2c7b930c9c7222185377d9c904..6b88246f82fbb4f41499ebed926e847a924fa943 100644 (file)
@@ -2832,6 +2832,8 @@ bool LValueExprEvaluator::VisitDeclRefExpr(const DeclRefExpr *E) {
 }
 
 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);
index 81a665dc6297d589c7e7f8e1d3a50a071424dc94..ee3e256b58865a92a9e5d37ec5428adf69555a4b 100644 (file)
@@ -157,3 +157,10 @@ int PR4386_zed() __attribute((weak));
 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.
+}