diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-18 21:00:25 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-18 21:00:25 +0000 |
commit | 2d17ab783b24df7e53bf3d02fe0deb70f63c14ab (patch) | |
tree | f8aff2b957f64819aa093eca74eec56cf26c8226 /clang/lib/Lex/PPDirectives.cpp | |
parent | 2534324a4e6b5137d7eb786f5c1b07215e1e650d (diff) | |
download | bcm5719-llvm-2d17ab783b24df7e53bf3d02fe0deb70f63c14ab.tar.gz bcm5719-llvm-2d17ab783b24df7e53bf3d02fe0deb70f63c14ab.zip |
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
llvm-svn: 67236
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 8e76b920aab..5797b12ebc8 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -476,6 +476,9 @@ void Preprocessor::HandleDirective(Token &Result) { // 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 @@ TryAgain: 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); |