[llvm-commits] [llvm] r83462 - /llvm/trunk/lib/VMCore/AsmWriter.cpp

Devang Patel dpatel at apple.com
Wed Oct 7 09:37:55 PDT 2009


Author: dpatel
Date: Wed Oct  7 11:37:55 2009
New Revision: 83462

URL: http://llvm.org/viewvc/llvm-project?rev=83462&view=rev
Log:
Do not assume that the module is set.

Modified:
    llvm/trunk/lib/VMCore/AsmWriter.cpp

Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=83462&r1=83461&r2=83462&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Wed Oct  7 11:37:55 2009
@@ -1303,12 +1303,14 @@
     : Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) {
     AddModuleTypesToPrinter(TypePrinter, NumberedTypes, M);
     // FIXME: Provide MDPrinter
-    MetadataContext &TheMetadata = M->getContext().getMetadata();
-    const StringMap<unsigned> *Names = TheMetadata.getHandlerNames();
-    for (StringMapConstIterator<unsigned> I = Names->begin(),
-           E = Names->end(); I != E; ++I) {
-      const StringMapEntry<unsigned> &Entry = *I;
-      MDNames[I->second] = Entry.getKeyData();
+    if (M) {
+      MetadataContext &TheMetadata = M->getContext().getMetadata();
+      const StringMap<unsigned> *Names = TheMetadata.getHandlerNames();
+      for (StringMapConstIterator<unsigned> I = Names->begin(),
+             E = Names->end(); I != E; ++I) {
+        const StringMapEntry<unsigned> &Entry = *I;
+        MDNames[I->second] = Entry.getKeyData();
+      }
     }
   }
 
@@ -2029,15 +2031,16 @@
   }
 
   // Print Metadata info
-  MetadataContext &TheMetadata = I.getContext().getMetadata();
-  const MetadataContext::MDMapTy *MDMap = TheMetadata.getMDs(&I);
-  if (MDMap)
-    for (MetadataContext::MDMapTy::const_iterator MI = MDMap->begin(),
-           ME = MDMap->end(); MI != ME; ++MI)
-      if (const MDNode *MD = dyn_cast_or_null<MDNode>(MI->second))
-        Out << ", !" << MDNames[MI->first]
-            << " !" << Machine.getMetadataSlot(MD);
-
+  if (!MDNames.empty()) {
+    MetadataContext &TheMetadata = I.getContext().getMetadata();
+    const MetadataContext::MDMapTy *MDMap = TheMetadata.getMDs(&I);
+    if (MDMap)
+      for (MetadataContext::MDMapTy::const_iterator MI = MDMap->begin(),
+             ME = MDMap->end(); MI != ME; ++MI)
+        if (const MDNode *MD = dyn_cast_or_null<MDNode>(MI->second))
+          Out << ", !" << MDNames[MI->first]
+              << " !" << Machine.getMetadataSlot(MD);
+  }
   printInfoComment(I);
 }
 





More information about the llvm-commits mailing list