forked from OSchip/llvm-project
Fix undefined behavior in debug info emission: operator* on WeakVH returns a
reference, so &* on an empty WeakVH binds a reference to a dereferenced null pointer. So don't do that; we have a perfectly good implicit conversion to Value*. llvm-svn: 162079
This commit is contained in:
parent
ab6151d6c4
commit
122a3a8e6f
|
@ -94,8 +94,10 @@ llvm::DIDescriptor CGDebugInfo::getContextDescriptor(const Decl *Context) {
|
|||
|
||||
llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator
|
||||
I = RegionMap.find(Context);
|
||||
if (I != RegionMap.end())
|
||||
return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(&*I->second));
|
||||
if (I != RegionMap.end()) {
|
||||
llvm::Value *V = I->second;
|
||||
return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(V));
|
||||
}
|
||||
|
||||
// Check namespace.
|
||||
if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Context))
|
||||
|
@ -227,8 +229,8 @@ llvm::DIFile CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
|
|||
|
||||
if (it != DIFileCache.end()) {
|
||||
// Verify that the information still exists.
|
||||
if (&*it->second)
|
||||
return llvm::DIFile(cast<llvm::MDNode>(it->second));
|
||||
if (llvm::Value *V = it->second)
|
||||
return llvm::DIFile(cast<llvm::MDNode>(V));
|
||||
}
|
||||
|
||||
llvm::DIFile F = DBuilder.createFile(PLoc.getFilename(), getCurrentDirname());
|
||||
|
@ -539,8 +541,10 @@ llvm::DIDescriptor CGDebugInfo::createContextChain(const Decl *Context) {
|
|||
// See if we already have the parent.
|
||||
llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator
|
||||
I = RegionMap.find(Context);
|
||||
if (I != RegionMap.end())
|
||||
return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(&*I->second));
|
||||
if (I != RegionMap.end()) {
|
||||
llvm::Value *V = I->second;
|
||||
return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(V));
|
||||
}
|
||||
|
||||
// Check namespace.
|
||||
if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Context))
|
||||
|
@ -1674,8 +1678,8 @@ llvm::DIType CGDebugInfo::getTypeOrNull(QualType Ty) {
|
|||
TypeCache.find(Ty.getAsOpaquePtr());
|
||||
if (it != TypeCache.end()) {
|
||||
// Verify that the debug info still exists.
|
||||
if (&*it->second)
|
||||
return llvm::DIType(cast<llvm::MDNode>(it->second));
|
||||
if (llvm::Value *V = it->second)
|
||||
return llvm::DIType(cast<llvm::MDNode>(V));
|
||||
}
|
||||
|
||||
return llvm::DIType();
|
||||
|
@ -1693,8 +1697,8 @@ llvm::DIType CGDebugInfo::getCompletedTypeOrNull(QualType Ty) {
|
|||
CompletedTypeCache.find(Ty.getAsOpaquePtr());
|
||||
if (it != CompletedTypeCache.end()) {
|
||||
// Verify that the debug info still exists.
|
||||
if (&*it->second)
|
||||
return llvm::DIType(cast<llvm::MDNode>(it->second));
|
||||
if (llvm::Value *V = it->second)
|
||||
return llvm::DIType(cast<llvm::MDNode>(V));
|
||||
}
|
||||
|
||||
return llvm::DIType();
|
||||
|
@ -1956,7 +1960,8 @@ llvm::DISubprogram CGDebugInfo::getFunctionDeclaration(const Decl *D) {
|
|||
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator
|
||||
MI = SPCache.find(FD->getCanonicalDecl());
|
||||
if (MI != SPCache.end()) {
|
||||
llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(&*MI->second));
|
||||
llvm::Value *V = MI->second;
|
||||
llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(V));
|
||||
if (SP.isSubprogram() && !llvm::DISubprogram(SP).isDefinition())
|
||||
return SP;
|
||||
}
|
||||
|
@ -1967,7 +1972,8 @@ llvm::DISubprogram CGDebugInfo::getFunctionDeclaration(const Decl *D) {
|
|||
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator
|
||||
MI = SPCache.find(NextFD->getCanonicalDecl());
|
||||
if (MI != SPCache.end()) {
|
||||
llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(&*MI->second));
|
||||
llvm::Value *V = MI->second;
|
||||
llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(V));
|
||||
if (SP.isSubprogram() && !llvm::DISubprogram(SP).isDefinition())
|
||||
return SP;
|
||||
}
|
||||
|
@ -2027,7 +2033,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType,
|
|||
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator
|
||||
FI = SPCache.find(FD->getCanonicalDecl());
|
||||
if (FI != SPCache.end()) {
|
||||
llvm::DIDescriptor SP(dyn_cast_or_null<llvm::MDNode>(&*FI->second));
|
||||
llvm::Value *V = FI->second;
|
||||
llvm::DIDescriptor SP(dyn_cast_or_null<llvm::MDNode>(V));
|
||||
if (SP.isSubprogram() && llvm::DISubprogram(SP).isDefinition()) {
|
||||
llvm::MDNode *SPN = SP;
|
||||
LexicalBlockStack.push_back(SPN);
|
||||
|
@ -2715,15 +2722,15 @@ void CGDebugInfo::finalize(void) {
|
|||
= ReplaceMap.begin(), VE = ReplaceMap.end(); VI != VE; ++VI) {
|
||||
llvm::DIType Ty, RepTy;
|
||||
// Verify that the debug info still exists.
|
||||
if (&*VI->second)
|
||||
Ty = llvm::DIType(cast<llvm::MDNode>(VI->second));
|
||||
if (llvm::Value *V = VI->second)
|
||||
Ty = llvm::DIType(cast<llvm::MDNode>(V));
|
||||
|
||||
llvm::DenseMap<void *, llvm::WeakVH>::iterator it =
|
||||
TypeCache.find(VI->first);
|
||||
if (it != TypeCache.end()) {
|
||||
// Verify that the debug info still exists.
|
||||
if (&*it->second)
|
||||
RepTy = llvm::DIType(cast<llvm::MDNode>(it->second));
|
||||
if (llvm::Value *V = it->second)
|
||||
RepTy = llvm::DIType(cast<llvm::MDNode>(V));
|
||||
}
|
||||
|
||||
if (Ty.Verify() && Ty.isForwardDecl() && RepTy.Verify()) {
|
||||
|
|
Loading…
Reference in New Issue