]> granicus.if.org Git - clang/commitdiff
Fix PR1936, a crash on malformed #if. Thanks to Neil for
authorChris Lattner <sabre@nondot.org>
Tue, 22 Jan 2008 19:34:51 +0000 (19:34 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 22 Jan 2008 19:34:51 +0000 (19:34 +0000)
noticing this!

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

Lex/Preprocessor.cpp
test/Preprocessor/ifdef-recover.c

index cb5a350758ae2cfeceefb89192ad6c55e1643722..d8310932687247b43c25169c916a638155e2c930 100644 (file)
@@ -939,9 +939,9 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,
       // an argument value in a macro could expand to ',' or '(' or ')'.
       LexUnexpandedToken(Tok);
       
-      if (Tok.is(tok::eof)) {
+      if (Tok.is(tok::eof) || Tok.is(tok::eom)) { // "#if f(<eof>" & "#if f(\n"
         Diag(MacroName, diag::err_unterm_macro_invoc);
-        // Do not lose the EOF.  Return it to the client.
+        // Do not lose the EOF/EOM.  Return it to the client.
         MacroName = Tok;
         return 0;
       } else if (Tok.is(tok::r_paren)) {
index 2009514f5e1d8b3f02d7098611e227afa92ad673..bd1d507bbc49417addc50da76dbad23334637288 100644 (file)
@@ -1,7 +1,15 @@
-/* RUN: clang %s 2>&1 | grep error: | count 1
+/* RUN: clang %s 2>&1 | grep error: | count 3
  */
 
 #ifdef
 
 #endif
 
+/* End of function-like macro invocation in #ifdef */
+/* PR1936 */
+#define f(x) x
+#if f(2
+#endif
+
+int x;
+