OSDN Git Service

[clang] Check for nullptr when instantiating late attrs
authorAdam Czachorowski <adamcz@google.com>
Mon, 18 Jan 2021 22:16:05 +0000 (23:16 +0100)
committerAdam Czachorowski <adamcz@google.com>
Tue, 19 Jan 2021 12:43:15 +0000 (13:43 +0100)
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

index cb74f08..7679063 100644 (file)
@@ -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());
   }