[cfe-commits] r162079 - /cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Thu Aug 16 21:17:54 PDT 2012
Author: rsmith
Date: Thu Aug 16 23:17:54 2012
New Revision: 162079
URL: http://llvm.org/viewvc/llvm-project?rev=162079&view=rev
Log:
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*.
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=162079&r1=162078&r2=162079&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Aug 16 23:17:54 2012
@@ -94,8 +94,10 @@
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 @@
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 @@
// 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 @@
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 @@
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::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::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 @@
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 @@
= 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()) {
More information about the cfe-commits
mailing list