diff --git a/clang/include/clang/Lex/Pragma.h b/clang/include/clang/Lex/Pragma.h index 70fcfda6e754..274f0dad3dd0 100644 --- a/clang/include/clang/Lex/Pragma.h +++ b/clang/include/clang/Lex/Pragma.h @@ -76,7 +76,7 @@ public: /// used to ignore particular pragmas. class EmptyPragmaHandler : public PragmaHandler { public: - EmptyPragmaHandler(); + explicit EmptyPragmaHandler(StringRef Name = StringRef()); void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &FirstToken) override; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index d2afff592511..274cb4d12858 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -163,6 +163,7 @@ class Parser : public CodeCompletionHandler { std::unique_ptr MSConstSeg; std::unique_ptr MSCodeSeg; std::unique_ptr MSSection; + std::unique_ptr MSRuntimeChecks; std::unique_ptr OptimizeHandler; std::unique_ptr LoopHintHandler; std::unique_ptr UnrollHintHandler; diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index db8e3055b85c..3134790ccb90 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -38,7 +38,7 @@ PragmaHandler::~PragmaHandler() { // EmptyPragmaHandler Implementation. //===----------------------------------------------------------------------===// -EmptyPragmaHandler::EmptyPragmaHandler() {} +EmptyPragmaHandler::EmptyPragmaHandler(StringRef Name) : PragmaHandler(Name) {} void EmptyPragmaHandler::HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp index 5ffce0003647..ab2b52ec396c 100644 --- a/clang/lib/Parse/ParsePragma.cpp +++ b/clang/lib/Parse/ParsePragma.cpp @@ -156,6 +156,10 @@ struct PragmaUnrollHintHandler : public PragmaHandler { Token &FirstToken) override; }; +struct PragmaMSRuntimeChecksHandler : public EmptyPragmaHandler { + PragmaMSRuntimeChecksHandler() : EmptyPragmaHandler("runtime_checks") {} +}; + } // end namespace void Parser::initializePragmaHandlers() { @@ -222,6 +226,8 @@ void Parser::initializePragmaHandlers() { PP.AddPragmaHandler(MSCodeSeg.get()); MSSection.reset(new PragmaMSPragma("section")); PP.AddPragmaHandler(MSSection.get()); + MSRuntimeChecks.reset(new PragmaMSRuntimeChecksHandler()); + PP.AddPragmaHandler(MSRuntimeChecks.get()); } OptimizeHandler.reset(new PragmaOptimizeHandler(Actions)); @@ -288,6 +294,8 @@ void Parser::resetPragmaHandlers() { MSCodeSeg.reset(); PP.RemovePragmaHandler(MSSection.get()); MSSection.reset(); + PP.RemovePragmaHandler(MSRuntimeChecks.get()); + MSRuntimeChecks.reset(); } PP.RemovePragmaHandler("STDC", FPContractHandler.get()); diff --git a/clang/test/Preprocessor/pragma_microsoft.c b/clang/test/Preprocessor/pragma_microsoft.c index b6921fa42fc7..2a9e7bab35b5 100644 --- a/clang/test/Preprocessor/pragma_microsoft.c +++ b/clang/test/Preprocessor/pragma_microsoft.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions +// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions -Wunknown-pragmas // RUN: not %clang_cc1 %s -fms-extensions -E | FileCheck %s // REQUIRES: non-ps4-sdk @@ -53,7 +53,7 @@ __pragma(comment(linker," bar=" BAR)) void f() { - __pragma() + __pragma() // expected-warning{{unknown pragma ignored}} // CHECK: #pragma // If we ever actually *support* __pragma(warning(disable: x)), @@ -159,3 +159,6 @@ void g() {} #pragma warning(default 321) // expected-warning {{expected ':'}} #pragma warning(asdf : 321) // expected-warning {{expected 'push', 'pop'}} #pragma warning(push, -1) // expected-warning {{requires a level between 0 and 4}} + +// Test that runtime_checks is parsed but ignored. +#pragma runtime_checks("sc", restore) // no-warning