[cfe-commits] r69404 - in /cfe/trunk: lib/Lex/Lexer.cpp lib/Lex/PPDirectives.cpp test/Preprocessor/include-directive2.c
Chris Lattner
sabre at nondot.org
Fri Apr 17 16:56:53 PDT 2009
Author: lattner
Date: Fri Apr 17 18:56:52 2009
New Revision: 69404
URL: http://llvm.org/viewvc/llvm-project?rev=69404&view=rev
Log:
Fix two problems from PR3916, and one problem I noticed while hacking
on the code.
Modified:
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Preprocessor/include-directive2.c
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=69404&r1=69403&r2=69404&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Fri Apr 17 18:56:52 2009
@@ -674,7 +674,7 @@
/// 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 @@
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 @@
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;
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=69404&r1=69403&r2=69404&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Apr 17 18:56:52 2009
@@ -1066,8 +1066,11 @@
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) {
Modified: cfe/trunk/test/Preprocessor/include-directive2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-directive2.c?rev=69404&r1=69403&r2=69404&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/include-directive2.c (original)
+++ cfe/trunk/test/Preprocessor/include-directive2.c Fri Apr 17 18:56:52 2009
@@ -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}}
More information about the cfe-commits
mailing list