<div dir="auto">From the bot changes, it seems that -Wunknown-pragma doesn't disable this new warning. Shouldn't it do that?</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Mar 20, 2018, 9:55 AM Hans Wennborg via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: hans<br>
Date: Tue Mar 20 01:53:11 2018<br>
New Revision: 327959<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=327959&view=rev" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=327959&view=rev</a><br>
Log:<br>
[ms] Parse #pragma optimize and ignore it behind its own flag<br>
<br>
This allows users to turn off warnings about this pragma specifically,<br>
while still receiving warnings about other ignored pragmas.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D44630" rel="noreferrer noreferrer" target="_blank">https://reviews.llvm.org/D44630</a><br>
<br>
Modified:<br>
cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td<br>
cfe/trunk/include/clang/Parse/Parser.h<br>
cfe/trunk/lib/Parse/ParsePragma.cpp<br>
cfe/trunk/test/Preprocessor/pragma_microsoft.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=327959&r1=327958&r2=327959&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=327959&r1=327958&r2=327959&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Mar 20 01:53:11 2018<br>
@@ -515,8 +515,13 @@ def UninitializedStaticSelfInit : DiagGr<br>
def Uninitialized : DiagGroup<"uninitialized", [UninitializedSometimes,<br>
UninitializedStaticSelfInit]>;<br>
def IgnoredPragmaIntrinsic : DiagGroup<"ignored-pragma-intrinsic">;<br>
+// #pragma optimize is often used to avoid to work around MSVC codegen bugs or<br>
+// to disable inlining. It's not completely clear what alternative to suggest<br>
+// (#pragma clang optimize, noinline) so suggest nothing for now.<br>
+def IgnoredPragmaOptimize : DiagGroup<"ignored-pragma-optimize">;<br>
def UnknownPragmas : DiagGroup<"unknown-pragmas">;<br>
-def IgnoredPragmas : DiagGroup<"ignored-pragmas", [IgnoredPragmaIntrinsic]>;<br>
+def IgnoredPragmas : DiagGroup<"ignored-pragmas",<br>
+ [IgnoredPragmaIntrinsic, IgnoredPragmaOptimize]>;<br>
def PragmaClangAttribute : DiagGroup<"pragma-clang-attribute">;<br>
def PragmaPackSuspiciousInclude : DiagGroup<"pragma-pack-suspicious-include">;<br>
def PragmaPack : DiagGroup<"pragma-pack", [PragmaPackSuspiciousInclude]>;<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=327959&r1=327958&r2=327959&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=327959&r1=327958&r2=327959&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Mar 20 01:53:11 2018<br>
@@ -895,6 +895,12 @@ def warn_pragma_expected_rparen : Warnin<br>
"missing ')' after '#pragma %0' - ignoring">, InGroup<IgnoredPragmas>;<br>
def warn_pragma_expected_identifier : Warning<<br>
"expected identifier in '#pragma %0' - ignored">, InGroup<IgnoredPragmas>;<br>
+def warn_pragma_expected_string : Warning<<br>
+ "expected string literal in '#pragma %0' - ignoring">, InGroup<IgnoredPragmas>;<br>
+def warn_pragma_missing_argument : Warning<<br>
+ "missing argument to '#pragma %0'%select{|; expected %2}1">, InGroup<IgnoredPragmas>;<br>
+def warn_pragma_invalid_argument : Warning<<br>
+ "unexpected argument '%0' to '#pragma %1'%select{|; expected %3}2">, InGroup<IgnoredPragmas>;<br>
<br>
// '#pragma clang section' related errors<br>
def err_pragma_expected_clang_section_name : Error<<br>
@@ -923,6 +929,8 @@ def warn_pragma_ms_struct : Warning<<br>
def warn_pragma_extra_tokens_at_eol : Warning<<br>
"extra tokens at end of '#pragma %0' - ignored">,<br>
InGroup<IgnoredPragmas>;<br>
+def warn_pragma_expected_comma : Warning<<br>
+ "expected ',' in '#pragma %0'">, InGroup<IgnoredPragmas>;<br>
def warn_pragma_expected_punc : Warning<<br>
"expected ')' or ',' in '#pragma %0'">, InGroup<IgnoredPragmas>;<br>
def warn_pragma_expected_non_wide_string : Warning<<br>
@@ -960,6 +968,10 @@ def warn_pragma_pack_malformed : Warning<br>
def warn_pragma_intrinsic_builtin : Warning<<br>
"%0 is not a recognized builtin%select{|; consider including <intrin.h> to access non-builtin intrinsics}1">,<br>
InGroup<IgnoredPragmaIntrinsic>;<br>
+// - #pragma optimize<br>
+def warn_pragma_optimize : Warning<<br>
+ "'#pragma optimize' is not supported">,<br>
+ InGroup<IgnoredPragmaOptimize>;<br>
// - #pragma unused<br>
def warn_pragma_unused_expected_var : Warning<<br>
"expected '#pragma unused' argument to be a variable name">,<br>
<br>
Modified: cfe/trunk/include/clang/Parse/Parser.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=327959&r1=327958&r2=327959&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=327959&r1=327958&r2=327959&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Parse/Parser.h (original)<br>
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Mar 20 01:53:11 2018<br>
@@ -179,6 +179,7 @@ class Parser : public CodeCompletionHand<br>
std::unique_ptr<PragmaHandler> MSSection;<br>
std::unique_ptr<PragmaHandler> MSRuntimeChecks;<br>
std::unique_ptr<PragmaHandler> MSIntrinsic;<br>
+ std::unique_ptr<PragmaHandler> MSOptimize;<br>
std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;<br>
std::unique_ptr<PragmaHandler> OptimizeHandler;<br>
std::unique_ptr<PragmaHandler> LoopHintHandler;<br>
<br>
Modified: cfe/trunk/lib/Parse/ParsePragma.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=327959&r1=327958&r2=327959&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=327959&r1=327958&r2=327959&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Tue Mar 20 01:53:11 2018<br>
@@ -220,6 +220,12 @@ struct PragmaMSIntrinsicHandler : public<br>
Token &FirstToken) override;<br>
};<br>
<br>
+struct PragmaMSOptimizeHandler : public PragmaHandler {<br>
+ PragmaMSOptimizeHandler() : PragmaHandler("optimize") {}<br>
+ void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
+ Token &FirstToken) override;<br>
+};<br>
+<br>
struct PragmaForceCUDAHostDeviceHandler : public PragmaHandler {<br>
PragmaForceCUDAHostDeviceHandler(Sema &Actions)<br>
: PragmaHandler("force_cuda_host_device"), Actions(Actions) {}<br>
@@ -324,6 +330,8 @@ void Parser::initializePragmaHandlers()<br>
PP.AddPragmaHandler(MSRuntimeChecks.get());<br>
MSIntrinsic.reset(new PragmaMSIntrinsicHandler());<br>
PP.AddPragmaHandler(MSIntrinsic.get());<br>
+ MSOptimize.reset(new PragmaMSOptimizeHandler());<br>
+ PP.AddPragmaHandler(MSOptimize.get());<br>
}<br>
<br>
if (getLangOpts().CUDA) {<br>
@@ -410,6 +418,8 @@ void Parser::resetPragmaHandlers() {<br>
MSRuntimeChecks.reset();<br>
PP.RemovePragmaHandler(MSIntrinsic.get());<br>
MSIntrinsic.reset();<br>
+ PP.RemovePragmaHandler(MSOptimize.get());<br>
+ MSOptimize.reset();<br>
}<br>
<br>
if (getLangOpts().CUDA) {<br>
@@ -2949,6 +2959,61 @@ void PragmaMSIntrinsicHandler::HandlePra<br>
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)<br>
<< "intrinsic";<br>
}<br>
+<br>
+// #pragma optimize("gsty", on|off)<br>
+void PragmaMSOptimizeHandler::HandlePragma(Preprocessor &PP,<br>
+ PragmaIntroducerKind Introducer,<br>
+ Token &Tok) {<br>
+ SourceLocation StartLoc = Tok.getLocation();<br>
+ PP.Lex(Tok);<br>
+<br>
+ if (Tok.isNot(tok::l_paren)) {<br>
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "optimize";<br>
+ return;<br>
+ }<br>
+ PP.Lex(Tok);<br>
+<br>
+ if (Tok.isNot(tok::string_literal)) {<br>
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_string) << "optimize";<br>
+ return;<br>
+ }<br>
+ // We could syntax check the string but it's probably not worth the effort.<br>
+ PP.Lex(Tok);<br>
+<br>
+ if (Tok.isNot(tok::comma)) {<br>
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_comma) << "optimize";<br>
+ return;<br>
+ }<br>
+ PP.Lex(Tok);<br>
+<br>
+ if (Tok.is(tok::eod) || Tok.is(tok::r_paren)) {<br>
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_missing_argument)<br>
+ << "optimize" << /*Expected=*/true << "'on' or 'off'";<br>
+ return;<br>
+ }<br>
+ IdentifierInfo *II = Tok.getIdentifierInfo();<br>
+ if (!II || (!II->isStr("on") && !II->isStr("off"))) {<br>
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_argument)<br>
+ << PP.getSpelling(Tok) << "optimize" << /*Expected=*/true<br>
+ << "'on' or 'off'";<br>
+ return;<br>
+ }<br>
+ PP.Lex(Tok);<br>
+<br>
+ if (Tok.isNot(tok::r_paren)) {<br>
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen) << "optimize";<br>
+ return;<br>
+ }<br>
+ PP.Lex(Tok);<br>
+<br>
+ if (Tok.isNot(tok::eod)) {<br>
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)<br>
+ << "optimize";<br>
+ return;<br>
+ }<br>
+ PP.Diag(StartLoc, diag::warn_pragma_optimize);<br>
+}<br>
+<br>
void PragmaForceCUDAHostDeviceHandler::HandlePragma(<br>
Preprocessor &PP, PragmaIntroducerKind Introducer, Token &Tok) {<br>
Token FirstTok = Tok;<br>
<br>
Modified: cfe/trunk/test/Preprocessor/pragma_microsoft.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_microsoft.c?rev=327959&r1=327958&r2=327959&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_microsoft.c?rev=327959&r1=327958&r2=327959&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Preprocessor/pragma_microsoft.c (original)<br>
+++ cfe/trunk/test/Preprocessor/pragma_microsoft.c Tue Mar 20 01:53:11 2018<br>
@@ -190,3 +190,11 @@ void g() {}<br>
#pragma intrinsic(asdf) // no-warning<br>
#pragma clang diagnostic pop<br>
#pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}<br>
+<br>
+#pragma optimize // expected-warning{{missing '(' after '#pragma optimize'}}<br>
+#pragma optimize( // expected-warning{{expected string literal in '#pragma optimize'}}<br>
+#pragma optimize(a // expected-warning{{expected string literal in '#pragma optimize'}}<br>
+#pragma optimize("g" // expected-warning{{expected ',' in '#pragma optimize'}}<br>
+#pragma optimize("g", // expected-warning{{missing argument to '#pragma optimize'; expected 'on' or 'off'}}<br>
+#pragma optimize("g",xyz // expected-warning{{unexpected argument 'xyz' to '#pragma optimize'; expected 'on' or 'off'}}<br>
+#pragma optimize("g",on) // expected-warning{{#pragma optimize' is not supported}}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank" rel="noreferrer">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>