r270642 - clang-cl: Fix unused argument warning when combining /O2 and /Ob2

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Tue May 24 17:43:45 PDT 2016


Author: hans
Date: Tue May 24 19:43:45 2016
New Revision: 270642

URL: http://llvm.org/viewvc/llvm-project?rev=270642&view=rev
Log:
clang-cl: Fix unused argument warning when combining /O2 and /Ob2

Modified:
    cfe/trunk/lib/Driver/MSVCToolChain.cpp
    cfe/trunk/test/Driver/cl-options.c

Modified: cfe/trunk/lib/Driver/MSVCToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MSVCToolChain.cpp?rev=270642&r1=270641&r2=270642&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp Tue May 24 19:43:45 2016
@@ -819,7 +819,12 @@ MSVCToolChain::TranslateArgs(const llvm:
       continue;
     StringRef OptStr = A->getValue();
     for (size_t I = 0, E = OptStr.size(); I != E; ++I) {
-      const char &OptChar = *(OptStr.data() + I);
+      char OptChar = OptStr[I];
+      char PrevChar = I > 0 ? OptStr[I - 1] : '0';
+      if (PrevChar == 'b') {
+        // OptChar does not expand; it's an argument to the previous char.
+        continue;
+      }
       if (OptChar == '1' || OptChar == '2' || OptChar == 'x' || OptChar == 'd')
         ExpandChar = OptStr.data() + I;
     }

Modified: cfe/trunk/test/Driver/cl-options.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=270642&r1=270641&r2=270642&view=diff
==============================================================================
--- cfe/trunk/test/Driver/cl-options.c (original)
+++ cfe/trunk/test/Driver/cl-options.c Tue May 24 19:43:45 2016
@@ -99,6 +99,8 @@
 
 // RUN: %clang_cl /Ob2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s
 // RUN: %clang_cl /Odb2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s
+// RUN: %clang_cl /O2 /Ob2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s
+// Ob2-NOT: warning: argument unused during compilation: '/O2'
 // Ob2: -finline-functions
 
 // RUN: %clang_cl /Od -### -- %s 2>&1 | FileCheck -check-prefix=Od %s




More information about the cfe-commits mailing list