[cfe-commits] r67236 - in /cfe/trunk/lib/Lex: PPDirectives.cpp PPLexerChange.cpp
Chris Lattner
sabre at nondot.org
Wed Mar 18 14:00:26 PDT 2009
Author: lattner
Date: Wed Mar 18 16:00:25 2009
New Revision: 67236
URL: http://llvm.org/viewvc/llvm-project?rev=67236&view=rev
Log:
when preprocessing a .S file, unknown directives should just be passed through,
and the token after the # should be expanded if it is not a valid directive.
This allows us to transform things like:
#define FOO BAR
# FOO
into # BAR, even though FOO is not normally expanded for directives.
This should fix PR3833
Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPLexerChange.cpp
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=67236&r1=67235&r2=67236&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Mar 18 16:00:25 2009
@@ -476,6 +476,9 @@
// pp-directive.
bool ReadAnyTokensBeforeDirective = CurPPLexer->MIOpt.getHasReadAnyTokensVal();
+ // Save the '#' token in case we need to return it later.
+ Token SavedHash = Result;
+
// Read the next token, the directive flavor. This isn't expanded due to
// C99 6.10.3p8.
LexUnexpandedToken(Result);
@@ -568,6 +571,22 @@
break;
}
+ // If this is a .S file, treat unknown # directives as non-preprocessor
+ // directives. This is important because # may be a comment or introduce
+ // various pseudo-ops. Just return the # token and push back the following
+ // token to be lexed next time.
+ if (getLangOptions().AsmPreprocessor) {
+ Token *Toks = new Token[2]();
+ // Return the # and the token after it.
+ Toks[0] = SavedHash;
+ Toks[1] = Result;
+ // Enter this token stream so that we re-lex the tokens. Make sure to
+ // enable macro expansion, in case the token after the # is an identifier
+ // that is expanded.
+ EnterTokenStream(Toks, 2, false, true);
+ return;
+ }
+
// If we reached here, the preprocessing token is not valid!
Diag(Result, diag::err_pp_invalid_directive);
Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=67236&r1=67235&r2=67236&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Wed Mar 18 16:00:25 2009
@@ -18,7 +18,6 @@
#include "clang/Lex/LexDiagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/Support/MemoryBuffer.h"
-
using namespace clang;
PPCallbacks::~PPCallbacks() {}
More information about the cfe-commits
mailing list