]> granicus.if.org Git - clang/commitdiff
Handle -D and -U options in order, so that they can cancel each other out when
authorSam Bishop <sam@bishop.dhs.org>
Mon, 14 Apr 2008 14:41:57 +0000 (14:41 +0000)
committerSam Bishop <sam@bishop.dhs.org>
Mon, 14 Apr 2008 14:41:57 +0000 (14:41 +0000)
intermixed.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49645 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/clang.cpp

index 4c8a3525c82144c7d74e40df2b87ef0e4fb4eedb..098450d72d112a4bce28b1a800d968ae7fa0daa4 100644 (file)
@@ -598,14 +598,17 @@ static unsigned InitializePreprocessor(Preprocessor &PP,
       return 0;
     }
   }
-  
+
   // Add macros from the command line.
-  // FIXME: Should traverse the #define/#undef lists in parallel.
-  for (unsigned i = 0, e = D_macros.size(); i != e; ++i)
-    DefineBuiltinMacro(PredefineBuffer, D_macros[i].c_str());
-  for (unsigned i = 0, e = U_macros.size(); i != e; ++i)
-    DefineBuiltinMacro(PredefineBuffer, U_macros[i].c_str(), "#undef ");
-  
+  unsigned d = 0, D = D_macros.size();
+  unsigned u = 0, U = U_macros.size();
+  while (d < D || u < U) {
+    if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
+      DefineBuiltinMacro(PredefineBuffer, D_macros[d++].c_str());
+    else
+      DefineBuiltinMacro(PredefineBuffer, U_macros[u++].c_str(), "#undef ");
+  }
+
   // FIXME: Read any files specified by -imacros.
   
   // Add implicit #includes from -include.