From: Alexey Samsonov Date: Wed, 3 Sep 2014 18:45:45 +0000 (+0000) Subject: Fix member function call on null pointer in Sema::FindInstantiatedDecl. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92e627868987d35c43224fcfa8801ea991667fd0;p=clang Fix member function call on null pointer in Sema::FindInstantiatedDecl. This bug was reported by UBSan. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217059 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index e9d95f2b29..ce18f6e369 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4400,17 +4400,17 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, (isa(D) && cast(D)->isLambda())) { // D is a local of some kind. Look into the map of local // declarations to their instantiations. - typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; - llvm::PointerUnion *Found - = CurrentInstantiationScope->findInstantiationOf(D); - - if (Found) { - if (Decl *FD = Found->dyn_cast()) - return cast(FD); - - int PackIdx = ArgumentPackSubstitutionIndex; - assert(PackIdx != -1 && "found declaration pack but not pack expanding"); - return cast((*Found->get())[PackIdx]); + if (CurrentInstantiationScope) { + if (auto Found = CurrentInstantiationScope->findInstantiationOf(D)) { + if (Decl *FD = Found->dyn_cast()) + return cast(FD); + + int PackIdx = ArgumentPackSubstitutionIndex; + assert(PackIdx != -1 && + "found declaration pack but not pack expanding"); + typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; + return cast((*Found->get())[PackIdx]); + } } // If we're performing a partial substitution during template argument