[PATCH] Driver: Use the canonical command line arguments.

David Majnemer david.majnemer at gmail.com
Fri Oct 4 05:20:23 PDT 2013


Hi aaron.ballman, Bigcheese, rnk, ruiu,

Use the arguments given to the OS at process creation-time instead of
the arguments passed into main() by the C runtime environment.  The ones
that main() received may not be suitable (e.g. not Unicode).

Depends on D1834

http://llvm-reviews.chandlerc.com/D1835

Files:
  tools/driver/driver.cpp

Index: tools/driver/driver.cpp
===================================================================
--- tools/driver/driver.cpp
+++ tools/driver/driver.cpp
@@ -37,6 +37,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/Signals.h"
@@ -292,8 +293,19 @@
   llvm::sys::PrintStackTraceOnErrorSignal();
   llvm::PrettyStackTraceProgram X(argc_, argv_);
 
+  llvm::OwningArrayPtr<char *> NewArgVectorPointers;
+  std::vector<char> NewArgVectorStrings;
+  Optional<ArrayRef<const char *> > NewArgs =
+      llvm::sys::Process::GetArgumentVector(
+          llvm::ArrayRef<const char *>(argv_, argv_ + argc_),
+          NewArgVectorPointers, NewArgVectorStrings);
+  if (!NewArgs) {
+    llvm::errs() << "error: arguments are malformed'\n";
+    return 1;
+  }
+
+  SmallVector<const char *, 256> argv(NewArgs->begin(), NewArgs->end());
   std::set<std::string> SavedStrings;
-  SmallVector<const char*, 256> argv(argv_, argv_ + argc_);
   StringSetSaver Saver(SavedStrings);
   llvm::cl::ExpandResponseFiles(Saver, llvm::cl::TokenizeGNUCommandLine, argv);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1835.1.patch
Type: text/x-patch
Size: 1248 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131004/6c86fac3/attachment.bin>


More information about the cfe-commits mailing list