diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -1957,6 +1957,15 @@ } }; +/// "\#pragma managed" +/// "\#pragma managed(...)" +/// "\#pragma unmanaged" +/// MSVC ignores this pragma when not compiling using /clr, which clang doesn't +/// support. We parse it and ignore it to avoid -Wunknown-pragma warnings. +struct PragmaManagedHandler : public EmptyPragmaHandler { + PragmaManagedHandler(const char *pragma) : EmptyPragmaHandler(pragma) {} +}; + /// This handles parsing pragmas that take a macro name and optional message static IdentifierInfo *HandleMacroAnnotationPragma(Preprocessor &PP, Token &Tok, const char *Pragma, @@ -2129,6 +2138,8 @@ AddPragmaHandler(new PragmaIncludeAliasHandler()); AddPragmaHandler(new PragmaHdrstopHandler()); AddPragmaHandler(new PragmaSystemHeaderHandler()); + AddPragmaHandler(new PragmaManagedHandler("managed")); + AddPragmaHandler(new PragmaManagedHandler("unmanaged")); } // Pragmas added by plugins diff --git a/clang/test/Preprocessor/pragma_microsoft.c b/clang/test/Preprocessor/pragma_microsoft.c --- a/clang/test/Preprocessor/pragma_microsoft.c +++ b/clang/test/Preprocessor/pragma_microsoft.c @@ -235,6 +235,12 @@ #pragma optimize("", on) // expected-error {{'#pragma optimize' can only appear at file scope}} } +#pragma managed // no-warning +#pragma unmanaged // no-warning +#pragma managed(push, on) // no-warning +#pragma managed(pop) // no-warning +#pragma managed2 // expected-warning{{unknown pragma ignored}} + #pragma execution_character_set // expected-warning {{expected '('}} #pragma execution_character_set( // expected-warning {{expected 'push' or 'pop'}} #pragma execution_character_set() // expected-warning {{expected 'push' or 'pop'}}