r179447 - Annotate flavor of TLS variable (statically or dynamically initialized) onto the AST.

David Blaikie dblaikie at gmail.com
Sun Apr 14 20:05:24 PDT 2013


On Fri, Apr 12, 2013 at 7:43 PM, Richard Smith
<richard-llvm at metafoo.co.uk> wrote:
> Author: rsmith
> Date: Fri Apr 12 21:43:54 2013
> New Revision: 179447
>
> URL: http://llvm.org/viewvc/llvm-project?rev=179447&view=rev
> Log:
> Annotate flavor of TLS variable (statically or dynamically initialized) onto the AST.

This may've caused some regressions?
http://lab.llvm.org:8011/builders/clang-x86_64-darwin10-gdb/builds/1855

>
> Added:
>     cfe/trunk/test/PCH/thread-local.cpp
> Modified:
>     cfe/trunk/include/clang/AST/Decl.h
>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>     cfe/trunk/lib/AST/ASTDumper.cpp
>     cfe/trunk/lib/AST/DeclPrinter.cpp
>     cfe/trunk/lib/AST/ExprConstant.cpp
>     cfe/trunk/lib/CodeGen/CGDecl.cpp
>     cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
>     cfe/trunk/lib/CodeGen/CGExpr.cpp
>     cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>     cfe/trunk/lib/Sema/SemaDecl.cpp
>     cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>     cfe/trunk/lib/Sema/SemaOpenMP.cpp
>     cfe/trunk/lib/Sema/SemaTemplate.cpp
>     cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>     cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
>     cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
>     cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1-11.cpp
>     cfe/trunk/test/Misc/ast-dump-decl.c
>     cfe/trunk/test/Misc/ast-dump-decl.cpp
>     cfe/trunk/test/Sema/thread-specifier.c
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Fri Apr 12 21:43:54 2013
> @@ -641,6 +641,13 @@ public:
>      ListInit  ///< Direct list-initialization (C++11)
>    };
>
> +  /// \brief Kinds of thread-local storage.
> +  enum TLSKind {
> +    TLS_None,   ///< Not a TLS variable.
> +    TLS_Static, ///< TLS with a known-constant initializer.
> +    TLS_Dynamic ///< TLS with a dynamic initializer.
> +  };
> +
>  protected:
>    /// \brief Placeholder type used in Init to denote an unparsed C++ default
>    /// argument.
> @@ -664,7 +671,7 @@ private:
>      friend class ASTDeclReader;
>
>      unsigned SClass : 3;
> -    unsigned ThreadSpecified : 1;
> +    unsigned TLSKind : 2;
>      unsigned InitStyle : 2;
>
>      /// \brief Whether this variable is the exception variable in a C++ catch
> @@ -687,7 +694,7 @@ private:
>      /// \brief Whether this variable is (C++0x) constexpr.
>      unsigned IsConstexpr : 1;
>    };
> -  enum { NumVarDeclBits = 14 };
> +  enum { NumVarDeclBits = 12 };
>
>    friend class ASTDeclReader;
>    friend class StmtIteratorBase;
> @@ -771,9 +778,9 @@ public:
>    }
>    void setStorageClass(StorageClass SC);
>
> -  void setThreadSpecified(bool T) { VarDeclBits.ThreadSpecified = T; }
> -  bool isThreadSpecified() const {
> -    return VarDeclBits.ThreadSpecified;
> +  void setTLSKind(TLSKind TLS) { VarDeclBits.TLSKind = TLS; }
> +  TLSKind getTLSKind() const {
> +    return static_cast<TLSKind>(VarDeclBits.TLSKind);
>    }
>
>    /// hasLocalStorage - Returns true if a variable with function scope
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr 12 21:43:54 2013
> @@ -3369,6 +3369,9 @@ def err_non_thread_thread : Error<
>    "non-thread-local declaration of %0 follows thread-local declaration">;
>  def err_thread_non_thread : Error<
>    "thread-local declaration of %0 follows non-thread-local declaration">;
> +def err_thread_thread_different_kind : Error<
> +  "thread-local declaration of %0 with %select{static|dynamic}1 initialization "
> +  "follows declaration with %select{dynamic|static}1 initialization">;
>  def err_redefinition_different_type : Error<
>    "redefinition of %0 with a different type%diff{: $ vs $|}1,2">;
>  def err_redefinition_different_kind : Error<
>
> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDumper.cpp Fri Apr 12 21:43:54 2013
> @@ -853,8 +853,11 @@ void ASTDumper::VisitVarDecl(const VarDe
>    StorageClass SC = D->getStorageClass();
>    if (SC != SC_None)
>      OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
> -  if (D->isThreadSpecified())
> -    OS << " __thread";
> +  switch (D->getTLSKind()) {
> +  case VarDecl::TLS_None: break;
> +  case VarDecl::TLS_Static: OS << " tls"; break;
> +  case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
> +  }
>    if (D->isModulePrivate())
>      OS << " __module_private__";
>    if (D->isNRVOVariable())
>
> Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
> +++ cfe/trunk/lib/AST/DeclPrinter.cpp Fri Apr 12 21:43:54 2013
> @@ -641,14 +641,25 @@ void DeclPrinter::VisitLabelDecl(LabelDe
>
>
>  void DeclPrinter::VisitVarDecl(VarDecl *D) {
> -  StorageClass SC = D->getStorageClass();
> -  if (!Policy.SuppressSpecifiers && SC != SC_None)
> -    Out << VarDecl::getStorageClassSpecifierString(SC) << " ";
> +  if (!Policy.SuppressSpecifiers) {
> +    StorageClass SC = D->getStorageClass();
> +    if (SC != SC_None)
> +      Out << VarDecl::getStorageClassSpecifierString(SC) << " ";
>
> -  if (!Policy.SuppressSpecifiers && D->isThreadSpecified())
> -    Out << "__thread ";
> -  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
> -    Out << "__module_private__ ";
> +    switch (D->getTLSKind()) {
> +    case VarDecl::TLS_None:
> +      break;
> +    case VarDecl::TLS_Static:
> +      Out << "_Thread_local ";
> +      break;
> +    case VarDecl::TLS_Dynamic:
> +      Out << "thread_local ";
> +      break;
> +    }
> +
> +    if (D->isModulePrivate())
> +      Out << "__module_private__ ";
> +  }
>
>    QualType T = D->getType();
>    if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D))
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Apr 12 21:43:54 2013
> @@ -999,7 +999,7 @@ static bool CheckLValueConstantExpressio
>    // Check if this is a thread-local variable.
>    if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>()) {
>      if (const VarDecl *Var = dyn_cast<const VarDecl>(VD)) {
> -      if (Var->isThreadSpecified())
> +      if (Var->getTLSKind())
>          return false;
>      }
>    }
>
> Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Apr 12 21:43:54 2013
> @@ -198,7 +198,7 @@ CodeGenFunction::CreateStaticVarDecl(con
>    if (Linkage != llvm::GlobalValue::InternalLinkage)
>      GV->setVisibility(CurFn->getVisibility());
>
> -  if (D.isThreadSpecified())
> +  if (D.getTLSKind())
>      CGM.setTLSMode(GV, D);
>
>    return GV;
>
> Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Fri Apr 12 21:43:54 2013
> @@ -39,7 +39,7 @@ static void EmitDeclInit(CodeGenFunction
>      CodeGenModule &CGM = CGF.CGM;
>      if (lv.isObjCStrong())
>        CGM.getObjCRuntime().EmitObjCGlobalAssign(CGF, CGF.EmitScalarExpr(Init),
> -                                                DeclPtr, D.isThreadSpecified());
> +                                                DeclPtr, D.getTLSKind());
>      else if (lv.isObjCWeak())
>        CGM.getObjCRuntime().EmitObjCWeakAssign(CGF, CGF.EmitScalarExpr(Init),
>                                                DeclPtr);
> @@ -218,6 +218,9 @@ void CodeGenFunction::EmitCXXGuardedInit
>                "this initialization requires a guard variable, which "
>                "the kernel does not support");
>
> +  if (D.getTLSKind())
> +    CGM.ErrorUnsupported(D.getInit(), "dynamic TLS initialization");
> +
>    CGM.getCXXABI().EmitGuardedInit(*this, D, DeclPtr, PerformInit);
>  }
>
> @@ -254,6 +257,9 @@ void
>  CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
>                                              llvm::GlobalVariable *Addr,
>                                              bool PerformInit) {
> +  if (D->getTLSKind())
> +    ErrorUnsupported(D->getInit(), "dynamic TLS initialization");
> +
>    llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
>
>    // Create a variable initialization function.
>
> Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Apr 12 21:43:54 2013
> @@ -1667,7 +1667,7 @@ static void setObjCGCLValueClass(const A
>      if (const VarDecl *VD = dyn_cast<VarDecl>(Exp->getDecl())) {
>        if (VD->hasGlobalStorage()) {
>          LV.setGlobalObjCRef(true);
> -        LV.setThreadLocalRef(VD->isThreadSpecified());
> +        LV.setThreadLocalRef(VD->getTLSKind() != VarDecl::TLS_None);
>        }
>      }
>      LV.setObjCArray(E->getType()->isArrayType());
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Apr 12 21:43:54 2013
> @@ -333,7 +333,7 @@ static llvm::GlobalVariable::ThreadLocal
>
>  void CodeGenModule::setTLSMode(llvm::GlobalVariable *GV,
>                                 const VarDecl &D) const {
> -  assert(D.isThreadSpecified() && "setting TLS mode on non-TLS var!");
> +  assert(D.getTLSKind() && "setting TLS mode on non-TLS var!");
>
>    llvm::GlobalVariable::ThreadLocalMode TLM;
>    TLM = GetLLVMTLSModel(CodeGenOpts.getDefaultTLSModel());
> @@ -1485,7 +1485,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str
>          GV->setVisibility(GetLLVMVisibility(LV.getVisibility()));
>      }
>
> -    if (D->isThreadSpecified())
> +    if (D->getTLSKind())
>        setTLSMode(GV, *D);
>    }
>
> @@ -1915,7 +1915,7 @@ CodeGenModule::GetLLVMLinkageVarDefiniti
>             ((!CodeGenOpts.NoCommon && !D->getAttr<NoCommonAttr>()) ||
>               D->getAttr<CommonAttr>()) &&
>             !D->hasExternalStorage() && !D->getInit() &&
> -           !D->getAttr<SectionAttr>() && !D->isThreadSpecified() &&
> +           !D->getAttr<SectionAttr>() && !D->getTLSKind() &&
>             !D->getAttr<WeakImportAttr>()) {
>      // Thread local vars aren't considered common linkage.
>      return llvm::GlobalVariable::CommonLinkage;
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Apr 12 21:43:54 2013
> @@ -2953,12 +2953,22 @@ void Sema::MergeVarDecl(VarDecl *New, Lo
>      return New->setInvalidDecl();
>    }
>
> -  if (New->isThreadSpecified() && !Old->isThreadSpecified()) {
> -    Diag(New->getLocation(), diag::err_thread_non_thread) << New->getDeclName();
> -    Diag(Old->getLocation(), diag::note_previous_definition);
> -  } else if (!New->isThreadSpecified() && Old->isThreadSpecified()) {
> -    Diag(New->getLocation(), diag::err_non_thread_thread) << New->getDeclName();
> -    Diag(Old->getLocation(), diag::note_previous_definition);
> +  if (New->getTLSKind() != Old->getTLSKind()) {
> +    if (!Old->getTLSKind()) {
> +      Diag(New->getLocation(), diag::err_thread_non_thread) << New->getDeclName();
> +      Diag(Old->getLocation(), diag::note_previous_declaration);
> +    } else if (!New->getTLSKind()) {
> +      Diag(New->getLocation(), diag::err_non_thread_thread) << New->getDeclName();
> +      Diag(Old->getLocation(), diag::note_previous_declaration);
> +    } else {
> +      // Do not allow redeclaration to change the variable between requiring
> +      // static and dynamic initialization.
> +      // FIXME: GCC allows this, but uses the TLS keyword on the first
> +      // declaration to determine the kind. Do we need to be compatible here?
> +      Diag(New->getLocation(), diag::err_thread_thread_different_kind)
> +        << New->getDeclName() << (New->getTLSKind() == VarDecl::TLS_Dynamic);
> +      Diag(Old->getLocation(), diag::note_previous_declaration);
> +    }
>    }
>
>    // C++ doesn't have tentative definitions, so go right ahead and check here.
> @@ -4577,7 +4587,7 @@ bool Sema::inferObjCARCLifetime(ValueDec
>    if (VarDecl *var = dyn_cast<VarDecl>(decl)) {
>      // Thread-local variables cannot have lifetime.
>      if (lifetime && lifetime != Qualifiers::OCL_ExplicitNone &&
> -        var->isThreadSpecified()) {
> +        var->getTLSKind()) {
>        Diag(var->getLocation(), diag::err_arc_thread_ownership)
>          << var->getType();
>        return true;
> @@ -4851,9 +4861,9 @@ Sema::ActOnVariableDeclarator(Scope *S,
>        Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
>             diag::err_thread_unsupported);
>      else
> -      // FIXME: Track which thread specifier was used; they have different
> -      // semantics.
> -      NewVD->setThreadSpecified(true);
> +      NewVD->setTLSKind(TSCS == DeclSpec::TSCS_thread_local
> +                          ? VarDecl::TLS_Dynamic
> +                          : VarDecl::TLS_Static);
>    }
>
>    // C99 6.7.4p3
>
> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr 12 21:43:54 2013
> @@ -284,7 +284,7 @@ static bool mayBeSharedVariable(const De
>    if (isa<FieldDecl>(D))
>      return true;
>    if (const VarDecl *vd = dyn_cast<VarDecl>(D))
> -    return (vd->hasGlobalStorage() && !(vd->isThreadSpecified()));
> +    return vd->hasGlobalStorage() && !vd->getTLSKind();
>
>    return false;
>  }
> @@ -1656,7 +1656,7 @@ static void handleTLSModelAttr(Sema &S,
>      return;
>    }
>
> -  if (!isa<VarDecl>(D) || !cast<VarDecl>(D)->isThreadSpecified()) {
> +  if (!isa<VarDecl>(D) || !cast<VarDecl>(D)->getTLSKind()) {
>      S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
>        << Attr.getName() << ExpectedTLSVar;
>      return;
>
> Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Apr 12 21:43:54 2013
> @@ -165,8 +165,8 @@ OMPThreadPrivateDecl *Sema::CheckOMPThre
>        continue;
>      }
>
> -    // Check if threadspecified is set.
> -    if (VD->isThreadSpecified()) {
> +    // Check if this is a TLS variable.
> +    if (VD->getTLSKind()) {
>        Diag(ILoc, diag::err_omp_var_thread_local) << VD;
>        Diag(VD->getLocation(), diag::note_forward_declaration) << VD;
>        continue;
>
> Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Apr 12 21:43:54 2013
> @@ -3842,8 +3842,7 @@ CheckTemplateArgumentAddressOfObjectOrFu
>      }
>
>      // A template argument must have static storage duration.
> -    // FIXME: Ensure this works for thread_local as well as __thread.
> -    if (Var->isThreadSpecified()) {
> +    if (Var->getTLSKind()) {
>        S.Diag(Arg->getLocStart(), diag::err_template_arg_thread_local)
>          << Arg->getSourceRange();
>        S.Diag(Var->getLocation(), diag::note_template_arg_refers_here);
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Apr 12 21:43:54 2013
> @@ -339,7 +339,7 @@ Decl *TemplateDeclInstantiator::VisitVar
>                                   D->getLocation(), D->getIdentifier(),
>                                   DI->getType(), DI,
>                                   D->getStorageClass());
> -  Var->setThreadSpecified(D->isThreadSpecified());
> +  Var->setTLSKind(D->getTLSKind());
>    Var->setInitStyle(D->getInitStyle());
>    Var->setCXXForRangeDecl(D->isCXXForRangeDecl());
>    Var->setConstexpr(D->isConstexpr());
>
> Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Fri Apr 12 21:43:54 2013
> @@ -895,7 +895,7 @@ void ASTDeclReader::VisitVarDecl(VarDecl
>    VisitDeclaratorDecl(VD);
>
>    VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
> -  VD->VarDeclBits.ThreadSpecified = Record[Idx++];
> +  VD->VarDeclBits.TLSKind = Record[Idx++];
>    VD->VarDeclBits.InitStyle = Record[Idx++];
>    VD->VarDeclBits.ExceptionVar = Record[Idx++];
>    VD->VarDeclBits.NRVOVariable = Record[Idx++];
>
> Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Fri Apr 12 21:43:54 2013
> @@ -677,7 +677,7 @@ void ASTDeclWriter::VisitVarDecl(VarDecl
>    VisitRedeclarable(D);
>    VisitDeclaratorDecl(D);
>    Record.push_back(D->getStorageClass());
> -  Record.push_back(D->isThreadSpecified());
> +  Record.push_back(D->getTLSKind());
>    Record.push_back(D->getInitStyle());
>    Record.push_back(D->isExceptionVariable());
>    Record.push_back(D->isNRVOVariable());
> @@ -766,7 +766,7 @@ void ASTDeclWriter::VisitParmVarDecl(Par
>
>    // Check things we know are true of *every* PARM_VAR_DECL, which is more than
>    // just us assuming it.
> -  assert(!D->isThreadSpecified() && "PARM_VAR_DECL can't be __thread");
> +  assert(!D->getTLSKind() && "PARM_VAR_DECL can't use TLS");
>    assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
>    assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
>    assert(D->getPreviousDecl() == 0 && "PARM_VAR_DECL can't be redecl");
> @@ -1515,7 +1515,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs()
>    Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
>    // VarDecl
>    Abv->Add(BitCodeAbbrevOp(0));                       // StorageClass
> -  Abv->Add(BitCodeAbbrevOp(0));                       // isThreadSpecified
> +  Abv->Add(BitCodeAbbrevOp(0));                       // getTLSKind
>    Abv->Add(BitCodeAbbrevOp(0));                       // hasCXXDirectInitializer
>    Abv->Add(BitCodeAbbrevOp(0));                       // isExceptionVariable
>    Abv->Add(BitCodeAbbrevOp(0));                       // isNRVOVariable
> @@ -1594,7 +1594,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs()
>    Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
>    // VarDecl
>    Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClass
> -  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isThreadSpecified
> +  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getTLSKind
>    Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CXXDirectInitializer
>    Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
>    Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
>
> Modified: cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1-11.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1-11.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1-11.cpp (original)
> +++ cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1-11.cpp Fri Apr 12 21:43:54 2013
> @@ -4,16 +4,20 @@ namespace std {
>    typedef decltype(nullptr) nullptr_t;
>  }
>
> -template<int *ip> struct IP {  // expected-note 4 {{template parameter is declared here}}
> +template<int *ip> struct IP {  // expected-note 5 {{template parameter is declared here}}
>    IP<ip> *ip2;
>  };
>
> +template<int &ip> struct IR {};
> +
>  constexpr std::nullptr_t get_nullptr() { return nullptr; }
>
>  constexpr std::nullptr_t np = nullptr;
>
>  std::nullptr_t nonconst_np; // expected-note{{declared here}}
>
> +thread_local int tl; // expected-note {{refers here}}
> +
>  IP<0> ip0; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}}
>  IP<(0)> ip1; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}}
>  IP<nullptr> ip2;
> @@ -23,6 +27,9 @@ IP<np> ip5;
>  IP<nonconst_np> ip5; // expected-error{{non-type template argument of type 'std::nullptr_t' (aka 'nullptr_t') is not a constant expression}} \
>  // expected-note{{read of non-constexpr variable 'nonconst_np' is not allowed in a constant expression}}
>  IP<(float*)0> ip6; // expected-error{{null non-type template argument of type 'float *' does not match template parameter of type 'int *'}}
> +IP<&tl> ip7; // expected-error{{non-type template argument of type 'int *' is not a constant expression}}
> +
> +IR<tl> ir1; // expected-error{{non-type template argument refers to thread-local object}}
>
>  struct X { };
>  template<int X::*pm> struct PM { // expected-note 2 {{template parameter is declared here}}
>
> Modified: cfe/trunk/test/Misc/ast-dump-decl.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-dump-decl.c?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/test/Misc/ast-dump-decl.c (original)
> +++ cfe/trunk/test/Misc/ast-dump-decl.c Fri Apr 12 21:43:54 2013
> @@ -139,7 +139,7 @@ extern int TestVarDeclSC;
>  // CHECK:      VarDecl{{.*}} TestVarDeclSC 'int' extern
>
>  __thread int TestVarDeclThread;
> -// CHECK:      VarDecl{{.*}} TestVarDeclThread 'int' __thread
> +// CHECK:      VarDecl{{.*}} TestVarDeclThread 'int' tls{{$}}
>
>  __module_private__ int TestVarDeclPrivate;
>  // CHECK:      VarDecl{{.*}} TestVarDeclPrivate 'int' __module_private__
>
> Modified: cfe/trunk/test/Misc/ast-dump-decl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-dump-decl.cpp?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/test/Misc/ast-dump-decl.cpp (original)
> +++ cfe/trunk/test/Misc/ast-dump-decl.cpp Fri Apr 12 21:43:54 2013
> @@ -92,6 +92,9 @@ class TestCXXRecordDeclPack : public T..
>  // CHECK-NEXT:   public 'T'...
>  // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestCXXRecordDeclPack
>
> +thread_local int TestThreadLocalInt;
> +// CHECK: TestThreadLocalInt {{.*}} tls_dynamic
> +
>  __module_private__ class TestCXXRecordDeclPrivate;
>  // CHECK: CXXRecordDecl{{.*}} class TestCXXRecordDeclPrivate __module_private__
>
>
> Added: cfe/trunk/test/PCH/thread-local.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/thread-local.cpp?rev=179447&view=auto
> ==============================================================================
> --- cfe/trunk/test/PCH/thread-local.cpp (added)
> +++ cfe/trunk/test/PCH/thread-local.cpp Fri Apr 12 21:43:54 2013
> @@ -0,0 +1,20 @@
> +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t
> +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t -verify %s
> +
> +#ifndef HEADER_INCLUDED
> +
> +#define HEADER_INCLUDED
> +extern thread_local int a;
> +extern _Thread_local int b;
> +extern int c;
> +
> +#else
> +
> +_Thread_local int a; // expected-error {{thread-local declaration of 'a' with static initialization follows declaration with dynamic initialization}}
> +// expected-note at 7 {{previous declaration is here}}
> +thread_local int b; // expected-error {{thread-local declaration of 'b' with dynamic initialization follows declaration with static initialization}}
> +// expected-note at 8 {{previous declaration is here}}
> +thread_local int c; // expected-error {{thread-local declaration of 'c' follows non-thread-local declaration}}
> +// expected-note at 9 {{previous declaration is here}}
> +
> +#endif
>
> Modified: cfe/trunk/test/Sema/thread-specifier.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/thread-specifier.c?rev=179447&r1=179446&r2=179447&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/thread-specifier.c (original)
> +++ cfe/trunk/test/Sema/thread-specifier.c Fri Apr 12 21:43:54 2013
> @@ -59,11 +59,18 @@ int f(__thread int t7) { // expected-err
>  }
>
>  __thread typedef int t14; // expected-error-re {{cannot combine with previous '(__thread|_Thread_local|thread_local)' declaration specifier}}
> -__thread int t15; // expected-note {{previous definition is here}}
> +__thread int t15; // expected-note {{previous declaration is here}}
>  extern int t15; // expected-error {{non-thread-local declaration of 't15' follows thread-local declaration}}
> -extern int t16; // expected-note {{previous definition is here}}
> +extern int t16; // expected-note {{previous declaration is here}}
>  __thread int t16; // expected-error {{thread-local declaration of 't16' follows non-thread-local declaration}}
>
> +#ifdef CXX11
> +extern thread_local int t17; // expected-note {{previous declaration is here}}
> +_Thread_local int t17; // expected-error {{thread-local declaration of 't17' with static initialization follows declaration with dynamic initialization}}
> +extern _Thread_local int t18; // expected-note {{previous declaration is here}}
> +thread_local int t18; // expected-error {{thread-local declaration of 't18' with dynamic initialization follows declaration with static initialization}}
> +#endif
> +
>  // PR13720
>  __thread int thread_int;
>  int *thread_int_ptr = &thread_int;
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list