[cfe-commits] r68525 - in /cfe/trunk: lib/Driver/OptTable.cpp test/Driver/parsing.c

Daniel Dunbar daniel at zuster.org
Tue Apr 7 11:21:48 PDT 2009


Author: ddunbar
Date: Tue Apr  7 13:21:47 2009
New Revision: 68525

URL: http://llvm.org/viewvc/llvm-project?rev=68525&view=rev
Log:
Driver: Fix a parsing bug where some options were matched
incorrectly. I'm blanking on the smartest way to write this search,
but we should just do the right thing when we move to TableGen.
 - <rdar://problem/6761194> [driver] -Wextra-tokens isn't parsed
   correctly

Modified:
    cfe/trunk/lib/Driver/OptTable.cpp
    cfe/trunk/test/Driver/parsing.c

Modified: cfe/trunk/lib/Driver/OptTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/OptTable.cpp?rev=68525&r1=68524&r2=68525&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/OptTable.cpp (original)
+++ cfe/trunk/lib/Driver/OptTable.cpp Tue Apr  7 13:21:47 2009
@@ -230,19 +230,26 @@
   struct Info *Start = OptionInfos + FirstSearchableOption - 1;
   struct Info *End = OptionInfos + LastOption - 1;
 
-  // Find the first option which could be a prefix.
+  // Search for the first next option which could be a prefix.
   Start = std::lower_bound(Start, End, Str);
 
-  // Scan for first option which is a proper prefix.
-  for (; Start != End; ++Start)
-    if (memcmp(Str, Start->Name, strlen(Start->Name)) == 0)
-      break;
-
-  // Look for a match until we don't have a prefix.
+  // Options are stored in sorted order, with '\0' at the end of the
+  // alphabet. Since the only options which can accept a string must
+  // prefix it, we iteratively search for the next option which could
+  // be a prefix.
+  //
+  // FIXME: This is searching much more than necessary, but I am
+  // blanking on the simplest way to make it fast. We can solve this
+  // problem when we move to TableGen.
   for (; Start != End; ++Start) {
-    if (memcmp(Start->Name, Str, strlen(Start->Name)) != 0)
+    // Scan for first option which is a proper prefix.
+    for (; Start != End; ++Start)
+      if (memcmp(Str, Start->Name, strlen(Start->Name)) == 0)
+        break;
+    if (Start == End)
       break;
 
+    // See if this option matches.
     options::ID id = (options::ID) (Start - OptionInfos + 1);
     if (Arg *A = getOption(id)->accept(Args, Index))
       return A;

Modified: cfe/trunk/test/Driver/parsing.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/parsing.c?rev=68525&r1=68524&r2=68525&view=diff

==============================================================================
--- cfe/trunk/test/Driver/parsing.c (original)
+++ cfe/trunk/test/Driver/parsing.c Tue Apr  7 13:21:47 2009
@@ -15,6 +15,10 @@
 // RUN: not clang -sectalign 1 2 2> %t &&
 // RUN: grep "error: argument to '-sectalign' is missing (expected 3 values)" %t &&
 
+// Verify that search continues after find the first option.
+// RUN: clang -ccc-print-options -Wally 2> %t &&
+// RUN: grep 'Option 0 - Name: "-W", Values: {"ally"}' %t &&
+
 // RUN: true
 
 





More information about the cfe-commits mailing list