assert(0) -> LLVM_UNREACHABLE.
[oota-llvm.git] / lib / Support / CommandLine.cpp
index 87dfc5a703fa885d9a36ecd1effd3c4214c258ec..400241f4d4bb92585fa59ec624b652b93a3bc55e 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/Config/config.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Streams.h"
@@ -45,10 +46,12 @@ TEMPLATE_INSTANTIATION(class basic_parser<unsigned>);
 TEMPLATE_INSTANTIATION(class basic_parser<double>);
 TEMPLATE_INSTANTIATION(class basic_parser<float>);
 TEMPLATE_INSTANTIATION(class basic_parser<std::string>);
+TEMPLATE_INSTANTIATION(class basic_parser<char>);
 
 TEMPLATE_INSTANTIATION(class opt<unsigned>);
 TEMPLATE_INSTANTIATION(class opt<int>);
 TEMPLATE_INSTANTIATION(class opt<std::string>);
+TEMPLATE_INSTANTIATION(class opt<char>);
 TEMPLATE_INSTANTIATION(class opt<bool>);
 
 void Option::anchor() {}
@@ -60,6 +63,7 @@ void parser<unsigned>::anchor() {}
 void parser<double>::anchor() {}
 void parser<float>::anchor() {}
 void parser<std::string>::anchor() {}
+void parser<char>::anchor() {}
 
 //===----------------------------------------------------------------------===//
 
@@ -201,8 +205,7 @@ static inline bool ProvideOption(Option *Handler, const char *ArgName,
     cerr << ProgramName
          << ": Bad ValueMask flag! CommandLine usage error:"
          << Handler->getValueExpectedFlag() << "\n";
-    abort();
-    break;
+    llvm_unreachable();
   }
 
   // If this isn't a multi-arg option, just run the handler.
@@ -388,23 +391,27 @@ static void ExpandResponseFiles(int argc, char** argv,
       // Check that the response file is not empty (mmap'ing empty
       // files can be problematic).
       const sys::FileStatus *FileStat = respFile.getFileStatus();
-      if (!FileStat)
-        continue;
-      if (FileStat->getSize() == 0)
-        continue;
+      if (FileStat && FileStat->getSize() != 0) {
 
-      // Mmap the response file into memory.
-      OwningPtr<MemoryBuffer>
-        respFilePtr(MemoryBuffer::getFile(respFile.c_str()));
+        // Mmap the response file into memory.
+        OwningPtr<MemoryBuffer>
+          respFilePtr(MemoryBuffer::getFile(respFile.c_str()));
 
-      if (respFilePtr == 0)
-        continue;
+        // If we could open the file, parse its contents, otherwise
+        // pass the @file option verbatim.
 
-      ParseCStringVector(newArgv, respFilePtr->getBufferStart());
-    }
-    else {
-      newArgv.push_back(strdup(arg));
+        // TODO: we should also support recursive loading of response files,
+        // since this is how gcc behaves. (From their man page: "The file may
+        // itself contain additional @file options; any such options will be
+        // processed recursively.")
+
+        if (respFilePtr != 0) {
+          ParseCStringVector(newArgv, respFilePtr->getBufferStart());
+          continue;
+        }
+      }
     }
+    newArgv.push_back(strdup(arg));
   }
 }
 
@@ -686,7 +693,7 @@ void cl::ParseCommandLineOptions(int argc, char **argv,
           ValNo++;
           break;
         default:
-          assert(0 && "Internal error, unexpected NumOccurrences flag in "
+          LLVM_UNREACHABLE("Internal error, unexpected NumOccurrences flag in "
                  "positional argument processing!");
         }
       }
@@ -878,7 +885,8 @@ bool parser<boolOrDefault>::parse(Option &O, const char *ArgName,
   if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
       Arg == "1") {
     Value = BOU_TRUE;
-  } else if (Arg == "false" || Arg == "FALSE" || Arg == "False" || Arg == "0") {
+  } else if (Arg == "false" || Arg == "FALSE"
+             || Arg == "False" || Arg == "0") {
     Value = BOU_FALSE;
   } else {
     return O.error(": '" + Arg +