diff options
-rw-r--r-- | Lex/Pragma.cpp | 20 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 1 | ||||
-rw-r--r-- | test/Lexer/pragma-mark.c | 11 |
3 files changed, 32 insertions, 0 deletions
diff --git a/Lex/Pragma.cpp b/Lex/Pragma.cpp index 05e524c0c1..f32e06bbcd 100644 --- a/Lex/Pragma.cpp +++ b/Lex/Pragma.cpp @@ -177,6 +177,12 @@ void Preprocessor::HandlePragmaOnce(Token &OnceTok) { HeaderInfo.MarkFileIncludeOnce(SourceMgr.getFileEntryForLoc(FileLoc)); } +void Preprocessor::HandlePragmaMark() { + assert(CurLexer && "No current lexer?"); + CurLexer->ReadToEndOfLine(); +} + + /// HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'. /// void Preprocessor::HandlePragmaPoison(Token &PoisonTok) { @@ -323,6 +329,7 @@ void Preprocessor::AddPragmaHandler(const char *Namespace, } namespace { +/// PragmaOnceHandler - "#pragma once" marks the file as atomically included. struct PragmaOnceHandler : public PragmaHandler { PragmaOnceHandler(const IdentifierInfo *OnceID) : PragmaHandler(OnceID) {} virtual void HandlePragma(Preprocessor &PP, Token &OnceTok) { @@ -331,6 +338,16 @@ struct PragmaOnceHandler : public PragmaHandler { } }; +/// PragmaMarkHandler - "#pragma mark ..." is ignored by the compiler, and the +/// rest of the line is not lexed. +struct PragmaMarkHandler : public PragmaHandler { + PragmaMarkHandler(const IdentifierInfo *MarkID) : PragmaHandler(MarkID) {} + virtual void HandlePragma(Preprocessor &PP, Token &MarkTok) { + PP.HandlePragmaMark(); + } +}; + +/// PragmaPoisonHandler - "#pragma poison x" marks x as not usable. struct PragmaPoisonHandler : public PragmaHandler { PragmaPoisonHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {} virtual void HandlePragma(Preprocessor &PP, Token &PoisonTok) { @@ -338,6 +355,8 @@ struct PragmaPoisonHandler : public PragmaHandler { } }; +/// PragmaSystemHeaderHandler - "#pragma system_header" marks the current file +/// as a system header, which silences warnings in it. struct PragmaSystemHeaderHandler : public PragmaHandler { PragmaSystemHeaderHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {} virtual void HandlePragma(Preprocessor &PP, Token &SHToken) { @@ -358,6 +377,7 @@ struct PragmaDependencyHandler : public PragmaHandler { /// #pragma GCC poison/system_header/dependency and #pragma once. void Preprocessor::RegisterBuiltinPragmas() { AddPragmaHandler(0, new PragmaOnceHandler(getIdentifierInfo("once"))); + AddPragmaHandler(0, new PragmaMarkHandler(getIdentifierInfo("mark"))); AddPragmaHandler("GCC", new PragmaPoisonHandler(getIdentifierInfo("poison"))); AddPragmaHandler("GCC", new PragmaSystemHeaderHandler( getIdentifierInfo("system_header"))); diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index c8c1da6b6e..a92962f423 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -494,6 +494,7 @@ private: void HandlePragmaDirective(); public: void HandlePragmaOnce(Token &OnceTok); + void HandlePragmaMark(); void HandlePragmaPoison(Token &PoisonTok); void HandlePragmaSystemHeader(Token &SysHeaderTok); void HandlePragmaDependency(Token &DependencyTok); diff --git a/test/Lexer/pragma-mark.c b/test/Lexer/pragma-mark.c new file mode 100644 index 0000000000..388fef5575 --- /dev/null +++ b/test/Lexer/pragma-mark.c @@ -0,0 +1,11 @@ +// RUN: clang %s -fsyntax-only -verify + +// Lexer diagnostics shouldn't be included in #pragma mark. +#pragma mark Mike's world +_Pragma("mark foo ' bar") + +#define X(S) _Pragma(S) +X("mark foo ' bar") + +int i; + |