forked from OSchip/llvm-project
[ms] Parse #pragma optimize and ignore it behind its own flag
This allows users to turn off warnings about this pragma specifically, while still receiving warnings about other ignored pragmas. Differential Revision: https://reviews.llvm.org/D44630 llvm-svn: 327959
This commit is contained in:
parent
8ad035d8e5
commit
1bbe00e0ca
|
@ -515,8 +515,13 @@ def UninitializedStaticSelfInit : DiagGroup<"static-self-init">;
|
|||
def Uninitialized : DiagGroup<"uninitialized", [UninitializedSometimes,
|
||||
UninitializedStaticSelfInit]>;
|
||||
def IgnoredPragmaIntrinsic : DiagGroup<"ignored-pragma-intrinsic">;
|
||||
// #pragma optimize is often used to avoid to work around MSVC codegen bugs or
|
||||
// to disable inlining. It's not completely clear what alternative to suggest
|
||||
// (#pragma clang optimize, noinline) so suggest nothing for now.
|
||||
def IgnoredPragmaOptimize : DiagGroup<"ignored-pragma-optimize">;
|
||||
def UnknownPragmas : DiagGroup<"unknown-pragmas">;
|
||||
def IgnoredPragmas : DiagGroup<"ignored-pragmas", [IgnoredPragmaIntrinsic]>;
|
||||
def IgnoredPragmas : DiagGroup<"ignored-pragmas",
|
||||
[IgnoredPragmaIntrinsic, IgnoredPragmaOptimize]>;
|
||||
def PragmaClangAttribute : DiagGroup<"pragma-clang-attribute">;
|
||||
def PragmaPackSuspiciousInclude : DiagGroup<"pragma-pack-suspicious-include">;
|
||||
def PragmaPack : DiagGroup<"pragma-pack", [PragmaPackSuspiciousInclude]>;
|
||||
|
|
|
@ -895,6 +895,12 @@ def warn_pragma_expected_rparen : Warning<
|
|||
"missing ')' after '#pragma %0' - ignoring">, InGroup<IgnoredPragmas>;
|
||||
def warn_pragma_expected_identifier : Warning<
|
||||
"expected identifier in '#pragma %0' - ignored">, InGroup<IgnoredPragmas>;
|
||||
def warn_pragma_expected_string : Warning<
|
||||
"expected string literal in '#pragma %0' - ignoring">, InGroup<IgnoredPragmas>;
|
||||
def warn_pragma_missing_argument : Warning<
|
||||
"missing argument to '#pragma %0'%select{|; expected %2}1">, InGroup<IgnoredPragmas>;
|
||||
def warn_pragma_invalid_argument : Warning<
|
||||
"unexpected argument '%0' to '#pragma %1'%select{|; expected %3}2">, InGroup<IgnoredPragmas>;
|
||||
|
||||
// '#pragma clang section' related errors
|
||||
def err_pragma_expected_clang_section_name : Error<
|
||||
|
@ -923,6 +929,8 @@ def warn_pragma_ms_struct : Warning<
|
|||
def warn_pragma_extra_tokens_at_eol : Warning<
|
||||
"extra tokens at end of '#pragma %0' - ignored">,
|
||||
InGroup<IgnoredPragmas>;
|
||||
def warn_pragma_expected_comma : Warning<
|
||||
"expected ',' in '#pragma %0'">, InGroup<IgnoredPragmas>;
|
||||
def warn_pragma_expected_punc : Warning<
|
||||
"expected ')' or ',' in '#pragma %0'">, InGroup<IgnoredPragmas>;
|
||||
def warn_pragma_expected_non_wide_string : Warning<
|
||||
|
@ -960,6 +968,10 @@ def warn_pragma_pack_malformed : Warning<
|
|||
def warn_pragma_intrinsic_builtin : Warning<
|
||||
"%0 is not a recognized builtin%select{|; consider including <intrin.h> to access non-builtin intrinsics}1">,
|
||||
InGroup<IgnoredPragmaIntrinsic>;
|
||||
// - #pragma optimize
|
||||
def warn_pragma_optimize : Warning<
|
||||
"'#pragma optimize' is not supported">,
|
||||
InGroup<IgnoredPragmaOptimize>;
|
||||
// - #pragma unused
|
||||
def warn_pragma_unused_expected_var : Warning<
|
||||
"expected '#pragma unused' argument to be a variable name">,
|
||||
|
|
|
@ -179,6 +179,7 @@ class Parser : public CodeCompletionHandler {
|
|||
std::unique_ptr<PragmaHandler> MSSection;
|
||||
std::unique_ptr<PragmaHandler> MSRuntimeChecks;
|
||||
std::unique_ptr<PragmaHandler> MSIntrinsic;
|
||||
std::unique_ptr<PragmaHandler> MSOptimize;
|
||||
std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
|
||||
std::unique_ptr<PragmaHandler> OptimizeHandler;
|
||||
std::unique_ptr<PragmaHandler> LoopHintHandler;
|
||||
|
|
|
@ -220,6 +220,12 @@ struct PragmaMSIntrinsicHandler : public PragmaHandler {
|
|||
Token &FirstToken) override;
|
||||
};
|
||||
|
||||
struct PragmaMSOptimizeHandler : public PragmaHandler {
|
||||
PragmaMSOptimizeHandler() : PragmaHandler("optimize") {}
|
||||
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
||||
Token &FirstToken) override;
|
||||
};
|
||||
|
||||
struct PragmaForceCUDAHostDeviceHandler : public PragmaHandler {
|
||||
PragmaForceCUDAHostDeviceHandler(Sema &Actions)
|
||||
: PragmaHandler("force_cuda_host_device"), Actions(Actions) {}
|
||||
|
@ -324,6 +330,8 @@ void Parser::initializePragmaHandlers() {
|
|||
PP.AddPragmaHandler(MSRuntimeChecks.get());
|
||||
MSIntrinsic.reset(new PragmaMSIntrinsicHandler());
|
||||
PP.AddPragmaHandler(MSIntrinsic.get());
|
||||
MSOptimize.reset(new PragmaMSOptimizeHandler());
|
||||
PP.AddPragmaHandler(MSOptimize.get());
|
||||
}
|
||||
|
||||
if (getLangOpts().CUDA) {
|
||||
|
@ -410,6 +418,8 @@ void Parser::resetPragmaHandlers() {
|
|||
MSRuntimeChecks.reset();
|
||||
PP.RemovePragmaHandler(MSIntrinsic.get());
|
||||
MSIntrinsic.reset();
|
||||
PP.RemovePragmaHandler(MSOptimize.get());
|
||||
MSOptimize.reset();
|
||||
}
|
||||
|
||||
if (getLangOpts().CUDA) {
|
||||
|
@ -2949,6 +2959,61 @@ void PragmaMSIntrinsicHandler::HandlePragma(Preprocessor &PP,
|
|||
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
||||
<< "intrinsic";
|
||||
}
|
||||
|
||||
// #pragma optimize("gsty", on|off)
|
||||
void PragmaMSOptimizeHandler::HandlePragma(Preprocessor &PP,
|
||||
PragmaIntroducerKind Introducer,
|
||||
Token &Tok) {
|
||||
SourceLocation StartLoc = Tok.getLocation();
|
||||
PP.Lex(Tok);
|
||||
|
||||
if (Tok.isNot(tok::l_paren)) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "optimize";
|
||||
return;
|
||||
}
|
||||
PP.Lex(Tok);
|
||||
|
||||
if (Tok.isNot(tok::string_literal)) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_string) << "optimize";
|
||||
return;
|
||||
}
|
||||
// We could syntax check the string but it's probably not worth the effort.
|
||||
PP.Lex(Tok);
|
||||
|
||||
if (Tok.isNot(tok::comma)) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_comma) << "optimize";
|
||||
return;
|
||||
}
|
||||
PP.Lex(Tok);
|
||||
|
||||
if (Tok.is(tok::eod) || Tok.is(tok::r_paren)) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_missing_argument)
|
||||
<< "optimize" << /*Expected=*/true << "'on' or 'off'";
|
||||
return;
|
||||
}
|
||||
IdentifierInfo *II = Tok.getIdentifierInfo();
|
||||
if (!II || (!II->isStr("on") && !II->isStr("off"))) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_argument)
|
||||
<< PP.getSpelling(Tok) << "optimize" << /*Expected=*/true
|
||||
<< "'on' or 'off'";
|
||||
return;
|
||||
}
|
||||
PP.Lex(Tok);
|
||||
|
||||
if (Tok.isNot(tok::r_paren)) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen) << "optimize";
|
||||
return;
|
||||
}
|
||||
PP.Lex(Tok);
|
||||
|
||||
if (Tok.isNot(tok::eod)) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
||||
<< "optimize";
|
||||
return;
|
||||
}
|
||||
PP.Diag(StartLoc, diag::warn_pragma_optimize);
|
||||
}
|
||||
|
||||
void PragmaForceCUDAHostDeviceHandler::HandlePragma(
|
||||
Preprocessor &PP, PragmaIntroducerKind Introducer, Token &Tok) {
|
||||
Token FirstTok = Tok;
|
||||
|
|
|
@ -190,3 +190,11 @@ void g() {}
|
|||
#pragma intrinsic(asdf) // no-warning
|
||||
#pragma clang diagnostic pop
|
||||
#pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
|
||||
|
||||
#pragma optimize // expected-warning{{missing '(' after '#pragma optimize'}}
|
||||
#pragma optimize( // expected-warning{{expected string literal in '#pragma optimize'}}
|
||||
#pragma optimize(a // expected-warning{{expected string literal in '#pragma optimize'}}
|
||||
#pragma optimize("g" // expected-warning{{expected ',' in '#pragma optimize'}}
|
||||
#pragma optimize("g", // expected-warning{{missing argument to '#pragma optimize'; expected 'on' or 'off'}}
|
||||
#pragma optimize("g",xyz // expected-warning{{unexpected argument 'xyz' to '#pragma optimize'; expected 'on' or 'off'}}
|
||||
#pragma optimize("g",on) // expected-warning{{#pragma optimize' is not supported}}
|
||||
|
|
Loading…
Reference in New Issue