diff options
| author | Alexey Samsonov <vonosmas@gmail.com> | 2014-09-03 18:45:45 +0000 |
|---|---|---|
| committer | Alexey Samsonov <vonosmas@gmail.com> | 2014-09-03 18:45:45 +0000 |
| commit | 2c0aac2591a7440bcb58f3d629024b83b535cbcd (patch) | |
| tree | b5823af03e78aef71f48a6e00b2c76f00a380e7d /clang/lib/Sema | |
| parent | 029634e99e8c533238b67229b90fd4e764160ccc (diff) | |
| download | bcm5719-llvm-2c0aac2591a7440bcb58f3d629024b83b535cbcd.tar.gz bcm5719-llvm-2c0aac2591a7440bcb58f3d629024b83b535cbcd.zip | |
Fix member function call on null pointer in Sema::FindInstantiatedDecl.
This bug was reported by UBSan.
llvm-svn: 217059
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index e9d95f2b292..ce18f6e3698 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4400,17 +4400,17 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(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<Decl *, DeclArgumentPack *> *Found - = CurrentInstantiationScope->findInstantiationOf(D); - - if (Found) { - if (Decl *FD = Found->dyn_cast<Decl *>()) - return cast<NamedDecl>(FD); - - int PackIdx = ArgumentPackSubstitutionIndex; - assert(PackIdx != -1 && "found declaration pack but not pack expanding"); - return cast<NamedDecl>((*Found->get<DeclArgumentPack *>())[PackIdx]); + if (CurrentInstantiationScope) { + if (auto Found = CurrentInstantiationScope->findInstantiationOf(D)) { + if (Decl *FD = Found->dyn_cast<Decl *>()) + return cast<NamedDecl>(FD); + + int PackIdx = ArgumentPackSubstitutionIndex; + assert(PackIdx != -1 && + "found declaration pack but not pack expanding"); + typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; + return cast<NamedDecl>((*Found->get<DeclArgumentPack *>())[PackIdx]); + } } // If we're performing a partial substitution during template argument |

