[cfe-commits] r166801 - in /cfe/trunk: lib/Driver/Option.cpp test/Index/index-with-working-dir.c

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Oct 26 12:36:33 PDT 2012


Author: akirtzidis
Date: Fri Oct 26 14:36:33 2012
New Revision: 166801

URL: http://llvm.org/viewvc/llvm-project?rev=166801&view=rev
Log:
[options] Fix mishandling of aliased options that was introduced in r166444.

Added:
    cfe/trunk/test/Index/index-with-working-dir.c
Modified:
    cfe/trunk/lib/Driver/Option.cpp

Modified: cfe/trunk/lib/Driver/Option.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Option.cpp?rev=166801&r1=166800&r2=166801&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Option.cpp (original)
+++ cfe/trunk/lib/Driver/Option.cpp Fri Oct 26 14:36:33 2012
@@ -13,6 +13,7 @@
 #include "clang/Driver/ArgList.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/ADT/Twine.h"
 #include <cassert>
 #include <algorithm>
 using namespace clang::driver;
@@ -93,21 +94,30 @@
 Arg *Option::accept(const ArgList &Args,
                     unsigned &Index,
                     unsigned ArgSize) const {
-  StringRef Spelling(Args.getArgString(Index), ArgSize);
+  const Option &UnaliasedOption = getUnaliasedOption();
+  StringRef Spelling;
+  // If the option was an alias, get the spelling from the unaliased one.
+  if (getID() == UnaliasedOption.getID()) {
+    Spelling = StringRef(Args.getArgString(Index), ArgSize);
+  } else {
+    Spelling = Args.MakeArgString(Twine(UnaliasedOption.getPrefix()) +
+                                  Twine(UnaliasedOption.getName()));
+  }
+
   switch (getKind()) {
   case FlagClass:
     if (ArgSize != strlen(Args.getArgString(Index)))
       return 0;
 
-    return new Arg(getUnaliasedOption(), Spelling, Index++);
+    return new Arg(UnaliasedOption, Spelling, Index++);
   case JoinedClass: {
     const char *Value = Args.getArgString(Index) + ArgSize;
-    return new Arg(getUnaliasedOption(), Spelling, Index++, Value);
+    return new Arg(UnaliasedOption, Spelling, Index++, Value);
   }
   case CommaJoinedClass: {
     // Always matches.
     const char *Str = Args.getArgString(Index) + ArgSize;
-    Arg *A = new Arg(getUnaliasedOption(), Spelling, Index++);
+    Arg *A = new Arg(UnaliasedOption, Spelling, Index++);
 
     // Parse out the comma separated values.
     const char *Prev = Str;
@@ -142,7 +152,7 @@
     if (Index > Args.getNumInputArgStrings())
       return 0;
 
-    return new Arg(getUnaliasedOption(), Spelling,
+    return new Arg(UnaliasedOption, Spelling,
                    Index - 2, Args.getArgString(Index - 1));
   case MultiArgClass: {
     // Matches iff this is an exact match.
@@ -154,7 +164,7 @@
     if (Index > Args.getNumInputArgStrings())
       return 0;
 
-    Arg *A = new Arg(getUnaliasedOption(), Spelling, Index - 1 - getNumArgs(),
+    Arg *A = new Arg(UnaliasedOption, Spelling, Index - 1 - getNumArgs(),
                       Args.getArgString(Index - getNumArgs()));
     for (unsigned i = 1; i != getNumArgs(); ++i)
       A->getValues().push_back(Args.getArgString(Index - getNumArgs() + i));
@@ -173,7 +183,7 @@
     if (Index > Args.getNumInputArgStrings())
       return 0;
 
-    return new Arg(getUnaliasedOption(), Spelling,
+    return new Arg(UnaliasedOption, Spelling,
                    Index - 2, Args.getArgString(Index - 1));
   }
   case JoinedAndSeparateClass:
@@ -182,7 +192,7 @@
     if (Index > Args.getNumInputArgStrings())
       return 0;
 
-    return new Arg(getUnaliasedOption(), Spelling, Index - 2,
+    return new Arg(UnaliasedOption, Spelling, Index - 2,
                    Args.getArgString(Index - 2) + ArgSize,
                    Args.getArgString(Index - 1));
   default:

Added: cfe/trunk/test/Index/index-with-working-dir.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-with-working-dir.c?rev=166801&view=auto
==============================================================================
--- cfe/trunk/test/Index/index-with-working-dir.c (added)
+++ cfe/trunk/test/Index/index-with-working-dir.c Fri Oct 26 14:36:33 2012
@@ -0,0 +1,5 @@
+
+void foo();
+
+// RUN: c-index-test -index-file -working-directory=%S %s | FileCheck %s
+// CHECK: [indexDeclaration]: kind: function | name: foo





More information about the cfe-commits mailing list