[llvm-commits] [llvm] r77559 - in /llvm/trunk: include/llvm/Metadata.h lib/VMCore/AsmWriter.cpp
Devang Patel
dpatel at apple.com
Wed Jul 29 18:02:04 PDT 2009
Author: dpatel
Date: Wed Jul 29 20:02:04 2009
New Revision: 77559
URL: http://llvm.org/viewvc/llvm-project?rev=77559&view=rev
Log:
Check null NameMDNode elements.
Modified:
llvm/trunk/include/llvm/Metadata.h
llvm/trunk/lib/VMCore/AsmWriter.cpp
Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=77559&r1=77558&r2=77559&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Wed Jul 29 20:02:04 2009
@@ -168,7 +168,7 @@
}
operator MetadataBase*() const {
- return cast<MetadataBase>(getValPtr());
+ return dyn_cast_or_null<MetadataBase>(getValPtr());
}
};
Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=77559&r1=77558&r2=77559&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Wed Jul 29 20:02:04 2009
@@ -647,7 +647,8 @@
const NamedMDNode *NMD = I;
for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
MDNode *MD = dyn_cast_or_null<MDNode>(NMD->getElement(i));
- CreateMetadataSlot(MD);
+ if (MD)
+ CreateMetadataSlot(MD);
}
}
@@ -1392,7 +1393,7 @@
Out << "!" << NMD->getName() << " = !{";
for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
if (i) Out << ", ";
- MDNode *MD = cast<MDNode>(NMD->getElement(i));
+ MDNode *MD = dyn_cast_or_null<MDNode>(NMD->getElement(i));
Out << '!' << Machine.getMetadataSlot(MD);
}
Out << "}\n";
@@ -2047,8 +2048,11 @@
OS << "!" << N->getName() << " = !{";
for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
if (i) OS << ", ";
- MDNode *MD = cast<MDNode>(N->getElement(i));
- OS << '!' << SlotTable.getMetadataSlot(MD);
+ MDNode *MD = dyn_cast_or_null<MDNode>(N->getElement(i));
+ if (MD)
+ OS << '!' << SlotTable.getMetadataSlot(MD);
+ else
+ OS << "null";
}
OS << "}\n";
WriteMDNodes(OS, TypePrinter, SlotTable);
More information about the llvm-commits
mailing list