[PATCH] D39538: [llvm-ar] Support an options string that start with a dash

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 13:09:43 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL317358: [llvm-ar] Support an options string that start with a dash (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D39538?vs=121361&id=121533#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39538

Files:
  llvm/trunk/test/tools/llvm-ar/default-add.test
  llvm/trunk/tools/llvm-ar/llvm-ar.cpp


Index: llvm/trunk/test/tools/llvm-ar/default-add.test
===================================================================
--- llvm/trunk/test/tools/llvm-ar/default-add.test
+++ llvm/trunk/test/tools/llvm-ar/default-add.test
@@ -4,7 +4,8 @@
 RUN: rm -f %t.ar
 RUN: llvm-ar crs %t.ar %t-macho.o
 RUN: grep -q __.SYMDEF %t.ar
-RUN: llvm-ar crs %t.ar %t-coff.o
+Test that an option string prefixed by a dash works.
+RUN: llvm-ar -crs %t.ar %t-coff.o
 RUN: grep -q __.SYMDEF %t.ar
 
 RUN: rm -f %t.ar
Index: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
===================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp
@@ -127,6 +127,8 @@
   "  [v] - be verbose about actions taken\n"
 );
 
+static const char OptionChars[] = "dmpqrtxabiosSTucv";
+
 // This enumeration delineates the kinds of operations on an archive
 // that are permitted.
 enum ArchiveOperation {
@@ -864,6 +866,24 @@
       Stem.find("lib") != StringRef::npos)
     return libDriverMain(makeArrayRef(argv, argc));
 
+  for (int i = 1; i < argc; i++) {
+    // If an argument starts with a dash and only contains chars
+    // that belong to the options chars set, remove the dash.
+    // We can't handle it after the command line options parsing
+    // is done, since it will error out on an unrecognized string
+    // starting with a dash.
+    // Make sure this doesn't match the actual llvm-ar specific options
+    // that start with a dash.
+    StringRef S = argv[i];
+    if (S.startswith("-") &&
+        S.find_first_not_of(OptionChars, 1) == StringRef::npos) {
+      argv[i]++;
+      break;
+    }
+    if (S == "--")
+      break;
+  }
+
   // Have the command line options parsed and handle things
   // like --help and --version.
   cl::ParseCommandLineOptions(argc, argv,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39538.121533.patch
Type: text/x-patch
Size: 1834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171103/a2cbab39/attachment.bin>


More information about the llvm-commits mailing list