commit fad2daaae6fd1cccb38f30034d18b238f0a903ed
Author: Martin Vejnar <martin.vejnar@avg.com>
Date:   Fri Jun 29 14:13:49 2012 +0200

    Elided __VA_ARGS__ now erase preceding comma in MS mode. bug 12845

diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index ade40da..3a92540 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -192,6 +192,23 @@ void TokenLexer::ExpandFunctionArguments() {
     // input.
     MadeChange = true;
 
+    if (PP.getLangOpts().MicrosoftMode &&
+        (unsigned)ArgNo == Macro->getNumArgs()-1 && // is __VA_ARGS__
+        ActualArgs->isVarargsElidedUse() &&       // Argument elided.
+        !ResultToks.empty() && ResultToks.back().is(tok::comma)) {
+      // Never add a space, even if the comma or arg had a space.
+      NextTokGetsSpace = false;
+
+      // Remove the comma
+      ResultToks.pop_back();
+
+      // If the comma was right after another paste (e.g. "X##,__VA_ARGS__"),
+      // the paste is ignored by MS compilers.
+      if (!ResultToks.empty() && ResultToks.back().is(tok::hashhash))
+        ResultToks.pop_back();
+      continue;
+    }
+
     // Otherwise, this is a use of the argument.  Find out if there is a paste
     // (##) operator before or after the argument.
     bool PasteBefore =
diff --git a/test/Preprocessor/macro_fn_comma_swallow.c b/test/Preprocessor/macro_fn_comma_swallow.c
index 726a889..b805e39 100644
--- a/test/Preprocessor/macro_fn_comma_swallow.c
+++ b/test/Preprocessor/macro_fn_comma_swallow.c
@@ -26,3 +26,8 @@
 // CHECK: 5: 1
 #define X5(x,...) x##,##__VA_ARGS__
 5: X5(1)
+
+// should not eat the comma.
+// CHECK: 6: {foo,}
+#define X6(b, ...) {b,__VA_ARGS__}
+6: X6(foo)
diff --git a/test/Preprocessor/macro_fn_ms_comma_swallow.c b/test/Preprocessor/macro_fn_ms_comma_swallow.c
new file mode 100644
index 0000000..a9496c6
--- /dev/null
+++ b/test/Preprocessor/macro_fn_ms_comma_swallow.c
@@ -0,0 +1,7 @@
+// Test the GNU comma swallowing extension.
+// RUN: %clang_cc1 %s -E -fms-compatibility | FileCheck -strict-whitespace %s
+
+// should eat the comma before emtpy varargs
+// CHECK: 1: {foo}
+#define X1(b, ...) {b,__VA_ARGS__}
+1: X1(foo)
