]> granicus.if.org Git - clang/commitdiff
Simplify this code: don't check for the same error two
authorDan Gohman <gohman@apple.com>
Tue, 26 Oct 2010 21:13:51 +0000 (21:13 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 26 Oct 2010 21:13:51 +0000 (21:13 +0000)
different ways. Check once, and use an assert to handle
consistency checking.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117397 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/CompilerInstance.cpp

index 2777e4dae4833bfdf7d4135f8baf9ccc2b240cff..a187140ca04153a3d80503f6282de3156206db96 100644 (file)
@@ -468,20 +468,22 @@ bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
   // Figure out where to get and map in the main file.
   if (InputFile != "-") {
     const FileEntry *File = FileMgr.getFile(InputFile);
-    if (File) SourceMgr.createMainFileID(File);
-    if (SourceMgr.getMainFileID().isInvalid()) {
+    if (!File) {
       Diags.Report(diag::err_fe_error_reading) << InputFile;
       return false;
     }
+    SourceMgr.createMainFileID(File);
   } else {
     llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
-    if (SB) SourceMgr.createMainFileIDForMemBuffer(SB);
-    if (SourceMgr.getMainFileID().isInvalid()) {
+    if (!SB) {
       Diags.Report(diag::err_fe_error_reading_stdin);
       return false;
     }
+    SourceMgr.createMainFileIDForMemBuffer(SB);
   }
 
+  assert(!SourceMgr.getMainFileID().isInvalid() &&
+         "Couldn't establish MainFileID!");
   return true;
 }