From a6f9077b16da90204b296acd4f840769e83460ac Mon Sep 17 00:00:00 2001 From: Adam Czachorowski Date: Mon, 18 Jan 2021 23:16:05 +0100 Subject: [PATCH] [clang] Check for nullptr when instantiating late attrs This was already done in SemaTemplateInstantiateDecl.cpp, but not in SemaTemplateInstantiate.cpp. Anecdotally I've seen some clangd crashes where coredumps point to this being a problem, but I cannot reproduce this so far. Differential Revision: https://reviews.llvm.org/D94933 --- clang/lib/Sema/SemaTemplateInstantiate.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index cb74f08830c..7679063ead7 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2796,7 +2796,8 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, Attr *NewAttr = instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs); - I->NewDecl->addAttr(NewAttr); + if (NewAttr) + I->NewDecl->addAttr(NewAttr); LocalInstantiationScope::deleteScopes(I->Scope, Instantiator.getStartingScope()); } -- 2.11.0