[llvm-branch-commits] [cfe-branch] r71626 - in /cfe/branches/Apple/Dib: lib/Lex/MacroArgs.cpp lib/Lex/PPMacroExpansion.cpp test/Preprocessor/macro_expand.c

Mike Stump mrs at apple.com
Tue May 12 20:20:41 PDT 2009


Author: mrs
Date: Tue May 12 22:20:41 2009
New Revision: 71626

URL: http://llvm.org/viewvc/llvm-project?rev=71626&view=rev
Log:
Merge in 71616:

When we expect two arguments but have zero, make sure to add
two empty arguments.  Also, add an assert so that this bug
manifests as an assertion failure, not a valgrind problem.

This fixes rdar://6880648 - [cpp] crash in ArgNeedsPreexpansion

Modified:
    cfe/branches/Apple/Dib/lib/Lex/MacroArgs.cpp
    cfe/branches/Apple/Dib/lib/Lex/PPMacroExpansion.cpp
    cfe/branches/Apple/Dib/test/Preprocessor/macro_expand.c

Modified: cfe/branches/Apple/Dib/lib/Lex/MacroArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Lex/MacroArgs.cpp?rev=71626&r1=71625&r2=71626&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Lex/MacroArgs.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Lex/MacroArgs.cpp Tue May 12 22:20:41 2009
@@ -72,6 +72,7 @@
     if (Result->is(tok::eof))
       --Arg;
   }
+  assert(Result < Start+NumUnexpArgTokens && "Invalid arg #");
   return Result;
 }
 

Modified: cfe/branches/Apple/Dib/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Lex/PPMacroExpansion.cpp?rev=71626&r1=71625&r2=71626&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Lex/PPMacroExpansion.cpp Tue May 12 22:20:41 2009
@@ -427,6 +427,11 @@
     Tok.setLocation(EndLoc);
     Tok.setLength(0);
     ArgTokens.push_back(Tok);
+
+    // If we expect two arguments, add both as empty.
+    if (NumActuals == 0 && MinArgsExpected == 2)
+      ArgTokens.push_back(Tok);
+    
   } else if (NumActuals > MinArgsExpected && !MI->isVariadic()) {
     // Emit the diagnostic at the macro name in case there is a missing ).
     // Emitting it at the , could be far away from the macro name.

Modified: cfe/branches/Apple/Dib/test/Preprocessor/macro_expand.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/Preprocessor/macro_expand.c?rev=71626&r1=71625&r2=71626&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/test/Preprocessor/macro_expand.c (original)
+++ cfe/branches/Apple/Dib/test/Preprocessor/macro_expand.c Tue May 12 22:20:41 2009
@@ -14,3 +14,6 @@
 B: f(f))
 C: for(for))
 
+// rdar://6880648
+#define f(x,y...) y
+f()





More information about the llvm-branch-commits mailing list