[cfe-commits] r71616 - in /cfe/trunk: lib/Lex/MacroArgs.cpp lib/Lex/PPMacroExpansion.cpp test/Preprocessor/macro_expand.c
Chris Lattner
sabre at nondot.org
Tue May 12 17:55:26 PDT 2009
Author: lattner
Date: Tue May 12 19:55:26 2009
New Revision: 71616
URL: http://llvm.org/viewvc/llvm-project?rev=71616&view=rev
Log:
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/trunk/lib/Lex/MacroArgs.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/test/Preprocessor/macro_expand.c
Modified: cfe/trunk/lib/Lex/MacroArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroArgs.cpp?rev=71616&r1=71615&r2=71616&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/MacroArgs.cpp (original)
+++ cfe/trunk/lib/Lex/MacroArgs.cpp Tue May 12 19:55:26 2009
@@ -72,6 +72,7 @@
if (Result->is(tok::eof))
--Arg;
}
+ assert(Result < Start+NumUnexpArgTokens && "Invalid arg #");
return Result;
}
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=71616&r1=71615&r2=71616&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Tue May 12 19:55:26 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/trunk/test/Preprocessor/macro_expand.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_expand.c?rev=71616&r1=71615&r2=71616&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/macro_expand.c (original)
+++ cfe/trunk/test/Preprocessor/macro_expand.c Tue May 12 19:55:26 2009
@@ -14,3 +14,6 @@
B: f(f))
C: for(for))
+// rdar://6880648
+#define f(x,y...) y
+f()
More information about the cfe-commits
mailing list