summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticParseKinds.td3
-rw-r--r--clang/lib/Parse/ParsePragma.cpp24
-rw-r--r--clang/test/CodeGen/pragma-comment.c1
-rw-r--r--clang/test/Preprocessor/pragma_ps4.c27
4 files changed, 46 insertions, 9 deletions
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 5f301c95d37..56a984baf4c 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -931,6 +931,9 @@ def err_pragma_fp_contract_scope : Error<
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<Microsoft>;
// - #pragma detect_mismatch
def err_pragma_detect_mismatch_malformed : Error<
"pragma detect_mismatch is malformed; it requires two comma-separated "
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 0ae46798066..96484b496d1 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -198,9 +198,12 @@ void Parser::initializePragmaHandlers() {
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 @@ void Parser::initializePragmaHandlers() {
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 @@ void Parser::resetPragmaHandlers() {
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 @@ void Parser::resetPragmaHandlers() {
MSCodeSeg.reset();
PP.RemovePragmaHandler(MSSection.get());
MSSection.reset();
- } else if (getTargetInfo().getTriple().isPS4()) {
- PP.RemovePragmaHandler(MSCommentHandler.get());
- MSCommentHandler.reset();
}
PP.RemovePragmaHandler("STDC", FPContractHandler.get());
@@ -1811,6 +1811,14 @@ void PragmaCommentHandler::HandlePragma(Preprocessor &PP,
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;
diff --git a/clang/test/CodeGen/pragma-comment.c b/clang/test/CodeGen/pragma-comment.c
index 0a7d3c7a475..fbae9d53235 100644
--- a/clang/test/CodeGen/pragma-comment.c
+++ b/clang/test/CodeGen/pragma-comment.c
@@ -30,4 +30,3 @@
// PS4: !{!"\01msvcrt.lib"}
// PS4: !{!"\01kernel32"}
// PS4: !{!"\01USER32.LIB"}
-// PS4: !{!" /bar=2"}
diff --git a/clang/test/Preprocessor/pragma_ps4.c b/clang/test/Preprocessor/pragma_ps4.c
new file mode 100644
index 00000000000..63651b6a96f
--- /dev/null
+++ b/clang/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}}
OpenPOWER on IntegriCloud