Adds a warning for unrecognized argument to #pragma comment() on PS4.

PS4 target recognizes the #pragma comment() syntax as in -fms-extensions, but
only handles the case of #pragma comment(lib). This patch adds a warning if any
other arguments are encountered.

This patch also refactors the code in ParsePragma.cpp a little bit to make it
more obvious that some codes are being shared between -fms-extensions and PS4.

llvm-svn: 233015
This commit is contained in:
Yunzhong Gao 2015-03-23 20:41:42 +00:00
parent ae3d78ac18
commit 99efc0361b
4 changed files with 46 additions and 9 deletions

View File

@ -931,6 +931,9 @@ def err_pragma_fp_contract_scope : Error<
def err_pragma_comment_malformed : Error< def err_pragma_comment_malformed : Error<
"pragma comment requires parenthesized identifier and optional string">; "pragma comment requires parenthesized identifier and optional string">;
def err_pragma_comment_unknown_kind : Error<"unknown kind of pragma comment">; def err_pragma_comment_unknown_kind : Error<"unknown kind of pragma comment">;
// PS4 recognizes only #pragma comment(lib)
def warn_pragma_comment_ignored : Warning<"'#pragma comment %0' ignored">,
InGroup<Microsoft>;
// - #pragma detect_mismatch // - #pragma detect_mismatch
def err_pragma_detect_mismatch_malformed : Error< def err_pragma_detect_mismatch_malformed : Error<
"pragma detect_mismatch is malformed; it requires two comma-separated " "pragma detect_mismatch is malformed; it requires two comma-separated "

View File

@ -198,9 +198,12 @@ void Parser::initializePragmaHandlers() {
OpenMPHandler.reset(new PragmaNoOpenMPHandler()); OpenMPHandler.reset(new PragmaNoOpenMPHandler());
PP.AddPragmaHandler(OpenMPHandler.get()); PP.AddPragmaHandler(OpenMPHandler.get());
if (getLangOpts().MicrosoftExt) { if (getLangOpts().MicrosoftExt || getTargetInfo().getTriple().isPS4()) {
MSCommentHandler.reset(new PragmaCommentHandler(Actions)); MSCommentHandler.reset(new PragmaCommentHandler(Actions));
PP.AddPragmaHandler(MSCommentHandler.get()); PP.AddPragmaHandler(MSCommentHandler.get());
}
if (getLangOpts().MicrosoftExt) {
MSDetectMismatchHandler.reset(new PragmaDetectMismatchHandler(Actions)); MSDetectMismatchHandler.reset(new PragmaDetectMismatchHandler(Actions));
PP.AddPragmaHandler(MSDetectMismatchHandler.get()); PP.AddPragmaHandler(MSDetectMismatchHandler.get());
MSPointersToMembers.reset(new PragmaMSPointersToMembers()); MSPointersToMembers.reset(new PragmaMSPointersToMembers());
@ -219,9 +222,6 @@ void Parser::initializePragmaHandlers() {
PP.AddPragmaHandler(MSCodeSeg.get()); PP.AddPragmaHandler(MSCodeSeg.get());
MSSection.reset(new PragmaMSPragma("section")); MSSection.reset(new PragmaMSPragma("section"));
PP.AddPragmaHandler(MSSection.get()); PP.AddPragmaHandler(MSSection.get());
} else if (getTargetInfo().getTriple().isPS4()) {
MSCommentHandler.reset(new PragmaCommentHandler(Actions));
PP.AddPragmaHandler(MSCommentHandler.get());
} }
OptimizeHandler.reset(new PragmaOptimizeHandler(Actions)); OptimizeHandler.reset(new PragmaOptimizeHandler(Actions));
@ -264,9 +264,12 @@ void Parser::resetPragmaHandlers() {
PP.RemovePragmaHandler(OpenMPHandler.get()); PP.RemovePragmaHandler(OpenMPHandler.get());
OpenMPHandler.reset(); OpenMPHandler.reset();
if (getLangOpts().MicrosoftExt) { if (getLangOpts().MicrosoftExt || getTargetInfo().getTriple().isPS4()) {
PP.RemovePragmaHandler(MSCommentHandler.get()); PP.RemovePragmaHandler(MSCommentHandler.get());
MSCommentHandler.reset(); MSCommentHandler.reset();
}
if (getLangOpts().MicrosoftExt) {
PP.RemovePragmaHandler(MSDetectMismatchHandler.get()); PP.RemovePragmaHandler(MSDetectMismatchHandler.get());
MSDetectMismatchHandler.reset(); MSDetectMismatchHandler.reset();
PP.RemovePragmaHandler(MSPointersToMembers.get()); PP.RemovePragmaHandler(MSPointersToMembers.get());
@ -285,9 +288,6 @@ void Parser::resetPragmaHandlers() {
MSCodeSeg.reset(); MSCodeSeg.reset();
PP.RemovePragmaHandler(MSSection.get()); PP.RemovePragmaHandler(MSSection.get());
MSSection.reset(); MSSection.reset();
} else if (getTargetInfo().getTriple().isPS4()) {
PP.RemovePragmaHandler(MSCommentHandler.get());
MSCommentHandler.reset();
} }
PP.RemovePragmaHandler("STDC", FPContractHandler.get()); PP.RemovePragmaHandler("STDC", FPContractHandler.get());
@ -1811,6 +1811,14 @@ void PragmaCommentHandler::HandlePragma(Preprocessor &PP,
return; return;
} }
// On PS4, issue a warning about any pragma comments other than
// #pragma comment lib.
if (PP.getTargetInfo().getTriple().isPS4() && Kind != Sema::PCK_Lib) {
PP.Diag(Tok.getLocation(), diag::warn_pragma_comment_ignored)
<< II->getName();
return;
}
// Read the optional string if present. // Read the optional string if present.
PP.Lex(Tok); PP.Lex(Tok);
std::string ArgumentString; std::string ArgumentString;

View File

@ -30,4 +30,3 @@
// PS4: !{!"\01msvcrt.lib"} // PS4: !{!"\01msvcrt.lib"}
// PS4: !{!"\01kernel32"} // PS4: !{!"\01kernel32"}
// PS4: !{!"\01USER32.LIB"} // PS4: !{!"\01USER32.LIB"}
// PS4: !{!" /bar=2"}

View File

@ -0,0 +1,27 @@
// RUN: %clang_cc1 %s -triple x86_64-scei-ps4 -fsyntax-only -verify -fms-extensions
// On PS4, issue a diagnostic that pragma comments are ignored except:
// #pragma comment lib
#pragma comment(lib)
#pragma comment(lib,"foo")
__pragma(comment(lib, "bar"))
#pragma comment(linker) // expected-warning {{'#pragma comment linker' ignored}}
#pragma comment(linker,"foo") // expected-warning {{'#pragma comment linker' ignored}}
__pragma(comment(linker, " bar=" "2")) // expected-warning {{'#pragma comment linker' ignored}}
#pragma comment(user) // expected-warning {{'#pragma comment user' ignored}}
#pragma comment(user, "Compiled on " __DATE__ " at " __TIME__ ) // expected-warning {{'#pragma comment user' ignored}}
__pragma(comment(user, "foo")) // expected-warning {{'#pragma comment user' ignored}}
#pragma comment(compiler) // expected-warning {{'#pragma comment compiler' ignored}}
#pragma comment(compiler, "foo") // expected-warning {{'#pragma comment compiler' ignored}}
__pragma(comment(compiler, "foo")) // expected-warning {{'#pragma comment compiler' ignored}}
#pragma comment(exestr) // expected-warning {{'#pragma comment exestr' ignored}}
#pragma comment(exestr, "foo") // expected-warning {{'#pragma comment exestr' ignored}}
__pragma(comment(exestr, "foo")) // expected-warning {{'#pragma comment exestr' ignored}}
#pragma comment(foo) // expected-error {{unknown kind of pragma comment}}
__pragma(comment(foo)) // expected-error {{unknown kind of pragma comment}}