If Loc is invalid (e.g. "self" in Objective-C) then use MainFileID's compile unit.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65403 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index a48c247..53e2872 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -52,10 +52,13 @@
   // "well formed" debug info.
   const FileEntry *FE = 0;
 
+  SourceManager &SM = M->getContext().getSourceManager();
   if (Loc.isValid()) {
-    SourceManager &SM = M->getContext().getSourceManager();
     Loc = SM.getInstantiationLoc(Loc);
     FE = SM.getFileEntryForID(SM.getFileID(Loc));
+  } else {
+    // If Loc is not valid then use main file id.
+    FE = SM.getFileEntryForID(SM.getMainFileID());
   }
    
   // See if this compile unit has been used before.