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.

llvm-svn: 162835
This commit is contained in:
Hans Wennborg 2012-08-29 08:44:49 +00:00
parent d0d96bfb86
commit 299f50b4e8
2 changed files with 9 additions and 0 deletions

View 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);

View 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.
}