Fix printing of nonfunction graphs


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5487 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/DataStructure/Printer.cpp b/lib/Analysis/DataStructure/Printer.cpp
index dae4a3a..b6b843b 100644
--- a/lib/Analysis/DataStructure/Printer.cpp
+++ b/lib/Analysis/DataStructure/Printer.cpp
@@ -29,7 +29,7 @@
 
 static std::string getCaption(const DSNode *N, const DSGraph *G) {
   std::stringstream OS;
-  Module *M = G && &G->getFunction() ? G->getFunction().getParent() : 0;
+  Module *M = G && G->hasFunction() ? G->getFunction().getParent() : 0;
 
   if (N->isNodeCompletelyFolded())
     OS << "FOLDED";
@@ -86,13 +86,15 @@
   ///
   static void addCustomGraphFeatures(const DSGraph *G,
                                      GraphWriter<const DSGraph*> &GW) {
+    Module *CurMod = G->hasFunction() ? G->getFunction().getParent() : 0;
+
     // Add scalar nodes to the graph...
     const hash_map<Value*, DSNodeHandle> &VM = G->getScalarMap();
     for (hash_map<Value*, DSNodeHandle>::const_iterator I = VM.begin();
          I != VM.end(); ++I)
       if (!isa<GlobalValue>(I->first)) {
         std::stringstream OS;
-        WriteAsOperand(OS, I->first, false, true, G->getFunction().getParent());
+        WriteAsOperand(OS, I->first, false, true, CurMod);
         GW.emitSimpleNode(I->first, "", OS.str());
         
         // Add edge from return node to real destination