Index: include/clang/Basic/DiagnosticParseKinds.td =================================================================== --- include/clang/Basic/DiagnosticParseKinds.td +++ include/clang/Basic/DiagnosticParseKinds.td @@ -931,6 +931,9 @@ def err_pragma_comment_malformed : Error< "pragma comment requires parenthesized identifier and optional string">; 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; // - #pragma detect_mismatch def err_pragma_detect_mismatch_malformed : Error< "pragma detect_mismatch is malformed; it requires two comma-separated " Index: lib/Parse/ParsePragma.cpp =================================================================== --- lib/Parse/ParsePragma.cpp +++ lib/Parse/ParsePragma.cpp @@ -198,9 +198,12 @@ OpenMPHandler.reset(new PragmaNoOpenMPHandler()); PP.AddPragmaHandler(OpenMPHandler.get()); - if (getLangOpts().MicrosoftExt) { + if (getLangOpts().MicrosoftExt || getTargetInfo().getTriple().isPS4()) { MSCommentHandler.reset(new PragmaCommentHandler(Actions)); PP.AddPragmaHandler(MSCommentHandler.get()); + } + + if (getLangOpts().MicrosoftExt) { MSDetectMismatchHandler.reset(new PragmaDetectMismatchHandler(Actions)); PP.AddPragmaHandler(MSDetectMismatchHandler.get()); MSPointersToMembers.reset(new PragmaMSPointersToMembers()); @@ -219,9 +222,6 @@ PP.AddPragmaHandler(MSCodeSeg.get()); MSSection.reset(new PragmaMSPragma("section")); PP.AddPragmaHandler(MSSection.get()); - } else if (getTargetInfo().getTriple().isPS4()) { - MSCommentHandler.reset(new PragmaCommentHandler(Actions)); - PP.AddPragmaHandler(MSCommentHandler.get()); } OptimizeHandler.reset(new PragmaOptimizeHandler(Actions)); @@ -264,9 +264,12 @@ PP.RemovePragmaHandler(OpenMPHandler.get()); OpenMPHandler.reset(); - if (getLangOpts().MicrosoftExt) { + if (getLangOpts().MicrosoftExt || getTargetInfo().getTriple().isPS4()) { PP.RemovePragmaHandler(MSCommentHandler.get()); MSCommentHandler.reset(); + } + + if (getLangOpts().MicrosoftExt) { PP.RemovePragmaHandler(MSDetectMismatchHandler.get()); MSDetectMismatchHandler.reset(); PP.RemovePragmaHandler(MSPointersToMembers.get()); @@ -285,9 +288,6 @@ MSCodeSeg.reset(); PP.RemovePragmaHandler(MSSection.get()); MSSection.reset(); - } else if (getTargetInfo().getTriple().isPS4()) { - PP.RemovePragmaHandler(MSCommentHandler.get()); - MSCommentHandler.reset(); } PP.RemovePragmaHandler("STDC", FPContractHandler.get()); @@ -1792,6 +1792,14 @@ 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. PP.Lex(Tok); std::string ArgumentString; Index: test/CodeGen/pragma-comment.c =================================================================== --- test/CodeGen/pragma-comment.c +++ test/CodeGen/pragma-comment.c @@ -30,4 +30,3 @@ // PS4: !{!"\01msvcrt.lib"} // PS4: !{!"\01kernel32"} // PS4: !{!"\01USER32.LIB"} -// PS4: !{!" /bar=2"} Index: test/Preprocessor/pragma_ps4.c =================================================================== --- test/Preprocessor/pragma_ps4.c +++ test/Preprocessor/pragma_ps4.c @@ -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}}