diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-07-08 02:38:24 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-07-08 02:38:24 +0000 |
commit | 8a874c93d9c1728ca923ecc1ff09da6b6d78c0aa (patch) | |
tree | 9bbec5def2bc86bac80310b13a52a9c04b90942e /clang/lib | |
parent | 17a2ff2494dc140e47b40b05995a654b6989513b (diff) | |
download | bcm5719-llvm-8a874c93d9c1728ca923ecc1ff09da6b6d78c0aa.tar.gz bcm5719-llvm-8a874c93d9c1728ca923ecc1ff09da6b6d78c0aa.zip |
PR9793: Treat substitution as an instantiation step for the purpose of the
-ftemplate-depth limit. There are various ways to get an infinite (or merely
huge) stack of substitutions with no intervening instantiations. This is also
consistent with gcc's behavior.
llvm-svn: 159907
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 14 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiate.cpp | 91 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 1 |
4 files changed, 58 insertions, 50 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index cfc55e5715c..6dbf7047658 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3383,6 +3383,8 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc, = ArgList.getInnermost(); InstantiatingTemplate Inst(*this, CallLoc, Param, Innermost.first, Innermost.second); + if (Inst) + return ExprError(); ExprResult Result; { diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 77695c199d5..4605e01fa25 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -1990,6 +1990,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, TemplateArgLists.addOuterTemplateArguments(0, 0); InstantiatingTemplate Inst(*this, TemplateLoc, Template); + if (Inst) + return QualType(); CanonType = SubstType(Pattern->getUnderlyingType(), TemplateArgLists, AliasTemplate->getLocation(), AliasTemplate->getDeclName()); @@ -2550,6 +2552,8 @@ SubstDefaultTemplateArgument(Sema &SemaRef, Template, Converted.data(), Converted.size(), SourceRange(TemplateLoc, RAngleLoc)); + if (Inst) + return 0; Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext()); ArgType = SemaRef.SubstType(ArgType, AllTemplateArgs, @@ -2599,6 +2603,8 @@ SubstDefaultTemplateArgument(Sema &SemaRef, Template, Converted.data(), Converted.size(), SourceRange(TemplateLoc, RAngleLoc)); + if (Inst) + return ExprError(); Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext()); EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); @@ -2648,6 +2654,8 @@ SubstDefaultTemplateArgument(Sema &SemaRef, Template, Converted.data(), Converted.size(), SourceRange(TemplateLoc, RAngleLoc)); + if (Inst) + return TemplateName(); Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext()); // Substitute into the nested-name-specifier first, @@ -2781,6 +2789,8 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param, InstantiatingTemplate Inst(*this, TemplateLoc, Template, NTTP, Converted.data(), Converted.size(), SourceRange(TemplateLoc, RAngleLoc)); + if (Inst) + return true; TemplateArgumentList TemplateArgs(TemplateArgumentList::OnStack, Converted.data(), Converted.size()); @@ -2913,6 +2923,8 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param, InstantiatingTemplate Inst(*this, TemplateLoc, Template, TempParm, Converted.data(), Converted.size(), SourceRange(TemplateLoc, RAngleLoc)); + if (Inst) + return true; TemplateArgumentList TemplateArgs(TemplateArgumentList::OnStack, Converted.data(), Converted.size()); @@ -3144,6 +3156,8 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, InstantiatingTemplate Instantiating(*this, RAngleLoc, Template, *Param, Converted.data(), Converted.size(), SourceRange(TemplateLoc, RAngleLoc)); + if (Instantiating) + return true; // Check the default template argument. if (CheckTemplateArgument(*Param, Arg, Template, TemplateLoc, diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 8973916f371..7416d123017 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -156,11 +156,11 @@ bool Sema::ActiveTemplateInstantiation::isInstantiationRecord() const { case ExceptionSpecInstantiation: case DefaultTemplateArgumentInstantiation: case DefaultFunctionArgumentInstantiation: - return true; - case ExplicitTemplateArgumentSubstitution: case DeducedTemplateArgumentSubstitution: case PriorTemplateArgumentSubstitution: + return true; + case DefaultTemplateArgumentChecking: return false; } @@ -252,8 +252,7 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, SavedInNonInstantiationSFINAEContext( SemaRef.InNonInstantiationSFINAEContext) { - Invalid = CheckInstantiationDepth(PointOfInstantiation, - InstantiationRange); + Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); if (!Invalid) { ActiveTemplateInstantiation Inst; Inst.Kind = Kind; @@ -282,21 +281,19 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, SavedInNonInstantiationSFINAEContext( SemaRef.InNonInstantiationSFINAEContext) { - Invalid = false; - - ActiveTemplateInstantiation Inst; - Inst.Kind = ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution; - Inst.PointOfInstantiation = PointOfInstantiation; - Inst.Entity = reinterpret_cast<uintptr_t>(PartialSpec); - Inst.TemplateArgs = TemplateArgs; - Inst.NumTemplateArgs = NumTemplateArgs; - Inst.DeductionInfo = &DeductionInfo; - Inst.InstantiationRange = InstantiationRange; - SemaRef.InNonInstantiationSFINAEContext = false; - SemaRef.ActiveTemplateInstantiations.push_back(Inst); - - assert(!Inst.isInstantiationRecord()); - ++SemaRef.NonInstantiationEntries; + Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); + if (!Invalid) { + ActiveTemplateInstantiation Inst; + Inst.Kind = ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution; + Inst.PointOfInstantiation = PointOfInstantiation; + Inst.Entity = reinterpret_cast<uintptr_t>(PartialSpec); + Inst.TemplateArgs = TemplateArgs; + Inst.NumTemplateArgs = NumTemplateArgs; + Inst.DeductionInfo = &DeductionInfo; + Inst.InstantiationRange = InstantiationRange; + SemaRef.InNonInstantiationSFINAEContext = false; + SemaRef.ActiveTemplateInstantiations.push_back(Inst); + } } Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, @@ -310,7 +307,6 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, SemaRef.InNonInstantiationSFINAEContext) { Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); - if (!Invalid) { ActiveTemplateInstantiation Inst; Inst.Kind @@ -336,21 +332,19 @@ InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, SavedInNonInstantiationSFINAEContext( SemaRef.InNonInstantiationSFINAEContext) { - Invalid = false; - - ActiveTemplateInstantiation Inst; - Inst.Kind = ActiveTemplateInstantiation::PriorTemplateArgumentSubstitution; - Inst.PointOfInstantiation = PointOfInstantiation; - Inst.Template = Template; - Inst.Entity = reinterpret_cast<uintptr_t>(Param); - Inst.TemplateArgs = TemplateArgs; - Inst.NumTemplateArgs = NumTemplateArgs; - Inst.InstantiationRange = InstantiationRange; - SemaRef.InNonInstantiationSFINAEContext = false; - SemaRef.ActiveTemplateInstantiations.push_back(Inst); - - assert(!Inst.isInstantiationRecord()); - ++SemaRef.NonInstantiationEntries; + Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); + if (!Invalid) { + ActiveTemplateInstantiation Inst; + Inst.Kind = ActiveTemplateInstantiation::PriorTemplateArgumentSubstitution; + Inst.PointOfInstantiation = PointOfInstantiation; + Inst.Template = Template; + Inst.Entity = reinterpret_cast<uintptr_t>(Param); + Inst.TemplateArgs = TemplateArgs; + Inst.NumTemplateArgs = NumTemplateArgs; + Inst.InstantiationRange = InstantiationRange; + SemaRef.InNonInstantiationSFINAEContext = false; + SemaRef.ActiveTemplateInstantiations.push_back(Inst); + } } Sema::InstantiatingTemplate:: @@ -364,20 +358,19 @@ InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, SavedInNonInstantiationSFINAEContext( SemaRef.InNonInstantiationSFINAEContext) { - Invalid = false; - ActiveTemplateInstantiation Inst; - Inst.Kind = ActiveTemplateInstantiation::PriorTemplateArgumentSubstitution; - Inst.PointOfInstantiation = PointOfInstantiation; - Inst.Template = Template; - Inst.Entity = reinterpret_cast<uintptr_t>(Param); - Inst.TemplateArgs = TemplateArgs; - Inst.NumTemplateArgs = NumTemplateArgs; - Inst.InstantiationRange = InstantiationRange; - SemaRef.InNonInstantiationSFINAEContext = false; - SemaRef.ActiveTemplateInstantiations.push_back(Inst); - - assert(!Inst.isInstantiationRecord()); - ++SemaRef.NonInstantiationEntries; + Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); + if (!Invalid) { + ActiveTemplateInstantiation Inst; + Inst.Kind = ActiveTemplateInstantiation::PriorTemplateArgumentSubstitution; + Inst.PointOfInstantiation = PointOfInstantiation; + Inst.Template = Template; + Inst.Entity = reinterpret_cast<uintptr_t>(Param); + Inst.TemplateArgs = TemplateArgs; + Inst.NumTemplateArgs = NumTemplateArgs; + Inst.InstantiationRange = InstantiationRange; + SemaRef.InNonInstantiationSFINAEContext = false; + SemaRef.ActiveTemplateInstantiations.push_back(Inst); + } } Sema::InstantiatingTemplate:: diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index bbf8f50a3c7..cce0b0d0930 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2446,7 +2446,6 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, (void) FunTmpl; ActiveInst.Kind = ActiveInstType::TemplateInstantiation; ActiveInst.Entity = reinterpret_cast<uintptr_t>(New); - --SemaRef.NonInstantiationEntries; } } |