Author: rsmith Date: Thu May 26 15:23:13 2016 New Revision: 270904 URL: http://llvm.org/viewvc/llvm-project?rev=270904&view=rev Log: Produce better pretty stack traces from crashes in template instantiation: add pretty stack trace entries for all cases where we instantiate the definition of something, and include the fully-qualified name with template arguments in the name of the instantiated entity.
Modified: cfe/trunk/lib/Sema/Sema.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Modified: cfe/trunk/lib/Sema/Sema.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=270904&r1=270903&r2=270904&view=diff ============================================================================== --- cfe/trunk/lib/Sema/Sema.cpp (original) +++ cfe/trunk/lib/Sema/Sema.cpp Thu May 26 15:23:13 2016 @@ -1265,10 +1265,10 @@ void PrettyDeclStackTraceEntry::print(ra } OS << Message; - if (TheDecl && isa<NamedDecl>(TheDecl)) { - std::string Name = cast<NamedDecl>(TheDecl)->getNameAsString(); - if (!Name.empty()) - OS << " '" << Name << '\''; + if (auto *ND = dyn_cast_or_null<NamedDecl>(TheDecl)) { + OS << " '"; + ND->getNameForDiagnostic(OS, ND->getASTContext().getPrintingPolicy(), true); + OS << "'"; } OS << '\n'; Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=270904&r1=270903&r2=270904&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Thu May 26 15:23:13 2016 @@ -21,6 +21,7 @@ #include "clang/Sema/DeclSpec.h" #include "clang/Sema/Initialization.h" #include "clang/Sema/Lookup.h" +#include "clang/Sema/PrettyDeclStackTrace.h" #include "clang/Sema/Template.h" #include "clang/Sema/TemplateDeduction.h" @@ -1955,6 +1956,8 @@ Sema::InstantiateClass(SourceLocation Po InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); if (Inst.isInvalid()) return true; + PrettyDeclStackTraceEntry CrashInfo(*this, Instantiation, SourceLocation(), + "instantiating class definition"); // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. @@ -2178,6 +2181,8 @@ bool Sema::InstantiateEnum(SourceLocatio InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); if (Inst.isInvalid()) return true; + PrettyDeclStackTraceEntry CrashInfo(*this, Instantiation, SourceLocation(), + "instantiating enum definition"); // The instantiation is visible here, even if it was first declared in an // unimported module. @@ -2250,6 +2255,8 @@ bool Sema::InstantiateInClassInitializer InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); if (Inst.isInvalid()) return true; + PrettyDeclStackTraceEntry CrashInfo(*this, Instantiation, SourceLocation(), + "instantiating default member init"); // Enter the scope of this instantiation. We don't use PushDeclContext because // we don't have a scope. Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=270904&r1=270903&r2=270904&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu May 26 15:23:13 2016 @@ -3649,6 +3649,8 @@ void Sema::InstantiateFunctionDefinition InstantiatingTemplate Inst(*this, PointOfInstantiation, Function); if (Inst.isInvalid()) return; + PrettyDeclStackTraceEntry CrashInfo(*this, Function, SourceLocation(), + "instantiating function definition"); // Copy the inner loc start from the pattern. Function->setInnerLocStart(PatternDecl->getInnerLocStart()); @@ -4033,6 +4035,8 @@ void Sema::InstantiateVariableDefinition InstantiatingTemplate Inst(*this, PointOfInstantiation, Var); if (Inst.isInvalid()) return; + PrettyDeclStackTraceEntry CrashInfo(*this, Var, SourceLocation(), + "instantiating variable initializer"); // If we're performing recursive template instantiation, create our own // queue of pending implicit instantiations that we will instantiate @@ -4160,6 +4164,8 @@ void Sema::InstantiateVariableDefinition InstantiatingTemplate Inst(*this, PointOfInstantiation, Var); if (Inst.isInvalid()) return; + PrettyDeclStackTraceEntry CrashInfo(*this, Var, SourceLocation(), + "instantiating variable definition"); // If we're performing recursive template instantiation, create our own // queue of pending implicit instantiations that we will instantiate later, @@ -4881,8 +4887,6 @@ void Sema::PerformPendingInstantiations( // Instantiate function definitions if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first)) { - PrettyDeclStackTraceEntry CrashInfo(*this, Function, SourceLocation(), - "instantiating function definition"); bool DefinitionRequired = Function->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition; InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function, true, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits