]> granicus.if.org Git - clang/commitdiff
Fix two problems from PR3916, and one problem I noticed while hacking
authorChris Lattner <sabre@nondot.org>
Fri, 17 Apr 2009 23:56:52 +0000 (23:56 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 17 Apr 2009 23:56:52 +0000 (23:56 +0000)
on the code.

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

lib/Lex/Lexer.cpp
lib/Lex/PPDirectives.cpp
test/Preprocessor/include-directive2.c

index d04b1c2b69e982007b1c873a730e28a539b985db..490a0b53049d93f94d4bb0be550594f6a66dbe55 100644 (file)
@@ -674,7 +674,7 @@ void Lexer::LexStringLiteral(Token &Result, const char *CurPtr, bool Wide) {
 /// after having lexed the '<' character.  This is used for #include filenames.
 void Lexer::LexAngledStringLiteral(Token &Result, const char *CurPtr) {
   const char *NulCharacter = 0; // Does this string contain the \0 character?
-  
+  const char *AfterLessPos = CurPtr;
   char C = getAndAdvanceChar(CurPtr, Result);
   while (C != '>') {
     // Skip escaped characters.
@@ -683,9 +683,9 @@ void Lexer::LexAngledStringLiteral(Token &Result, const char *CurPtr) {
       C = getAndAdvanceChar(CurPtr, Result);
     } else if (C == '\n' || C == '\r' ||             // Newline.
                (C == 0 && CurPtr-1 == BufferEnd)) {  // End of file.
-      if (!isLexingRawMode() && !Features.AsmPreprocessor)
-        Diag(BufferPtr, diag::err_unterminated_angled_string);
-      FormTokenWithChars(Result, CurPtr-1, tok::unknown);
+      // If the filename is unterminated, then it must just be a lone <
+      // character.  Return this as such.
+      FormTokenWithChars(Result, AfterLessPos, tok::less);
       return;
     } else if (C == 0) {
       NulCharacter = CurPtr-1;
@@ -1635,7 +1635,7 @@ LexNextToken:
   case '<':
     Char = getCharAndSize(CurPtr, SizeTmp);
     if (ParsingFilename) {
-      return LexAngledStringLiteral(Result, CurPtr+SizeTmp);
+      return LexAngledStringLiteral(Result, CurPtr);
     } else if (Char == '<' &&
                getCharAndSize(CurPtr+SizeTmp, SizeTmp2) == '=') {
       Kind = tok::lesslessequal;
index 2dfb6233bdf4983a6ffd0b41b954e2c273b1acac..502da7384258d135f7f1055c581a1cf34b328970 100644 (file)
@@ -1066,8 +1066,11 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok,
     return;
   }
   
-  // Verify that there is nothing after the filename, other than EOM.
-  CheckEndOfDirective(IncludeTok.getIdentifierInfo()->getName());
+  // Verify that there is nothing after the filename, other than EOM.  Note that
+  // we allow macros that expand to nothing after the filename, because this
+  // falls into the category of "#include pp-tokens new-line" specified in
+  // C99 6.10.2p4.
+  CheckEndOfDirective(IncludeTok.getIdentifierInfo()->getName(), true);
 
   // Check that we don't have infinite #include recursion.
   if (IncludeMacroStack.size() == MaxAllowedIncludeStackDepth-1) {
index 785b77cbdd85cc35ae2010ba51f9e38e0931bad0..123998246bff5d697b2495349bb6d6c9d41f92a5 100644 (file)
@@ -1,4 +1,17 @@
-// RUN: clang-cc -Eonly %s 
+// RUN: clang-cc -Eonly -verify %s 
 #  define HEADER <float.h>
 
 #  include HEADER
+
+#include <limits.h> NON_EMPTY // expected-warning {{extra tokens at end of #include directive}}
+
+// PR3916: these are ok.
+#define EMPTY
+#include <limits.h> EMPTY
+#include HEADER  EMPTY
+
+// PR3916
+#define FN limits.h>
+#include <FN
+
+#include <>    // expected-error {{empty filename}}