mattd created this revision.
mattd added reviewers: rnk, rsmith.
Both MS and PS4 targets are capable of recognizing the
existence of: #pragma region, #pragma endregion.
This patch adds a LangOpt and sets the value based on target
information or MS compatibility. In the case of PS4 or MS we
should avoid emitting "unknown pragma" warnings for regions.
This change prevents that situation.
https://reviews.llvm.org/D42248
Files:
include/clang/Basic/LangOptions.def
lib/Frontend/CompilerInvocation.cpp
lib/Lex/Pragma.cpp
test/Frontend/region-pragmas.c
Index: test/Frontend/region-pragmas.c
===
--- test/Frontend/region-pragmas.c
+++ test/Frontend/region-pragmas.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-scei-ps4 -Wall -verify %s
+// RUN: %clang_cc1 -fms-compatibility -Wall -verify %s
+// RUN: %clang_cc1 -Wall -Wno-unknown-pragmas -verify %s
+// expected-no-diagnostics
+
+#pragma region foo
+#pragma endregion foo
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1781,6 +1781,10 @@
if (LangOpts.MicrosoftExt) {
AddPragmaHandler(new PragmaWarningHandler());
AddPragmaHandler(new PragmaIncludeAliasHandler());
+ }
+
+ // Region support.
+ if (LangOpts.MicrosoftPragmaRegion) {
AddPragmaHandler(new PragmaRegionHandler("region"));
AddPragmaHandler(new PragmaRegionHandler("endregion"));
}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2160,6 +2160,7 @@
Opts.MSVCCompat = Args.hasArg(OPT_fms_compatibility);
Opts.MicrosoftExt = Opts.MSVCCompat || Args.hasArg(OPT_fms_extensions);
+ Opts.MicrosoftPragmaRegion = Opts.MicrosoftExt || T.isPS4();
Opts.AsmBlocks = Args.hasArg(OPT_fasm_blocks) || Opts.MicrosoftExt;
Opts.MSCompatibilityVersion = 0;
if (const Arg *A = Args.getLastArg(OPT_fms_compatibility_version)) {
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -85,6 +85,7 @@
LANGOPT(C17 , 1, 0, "C17")
LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility
mode")
LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions")
+BENIGN_LANGOPT(MicrosoftPragmaRegion, 1, 0, "region pragma support")
LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, "C++")
Index: test/Frontend/region-pragmas.c
===
--- test/Frontend/region-pragmas.c
+++ test/Frontend/region-pragmas.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-scei-ps4 -Wall -verify %s
+// RUN: %clang_cc1 -fms-compatibility -Wall -verify %s
+// RUN: %clang_cc1 -Wall -Wno-unknown-pragmas -verify %s
+// expected-no-diagnostics
+
+#pragma region foo
+#pragma endregion foo
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1781,6 +1781,10 @@
if (LangOpts.MicrosoftExt) {
AddPragmaHandler(new PragmaWarningHandler());
AddPragmaHandler(new PragmaIncludeAliasHandler());
+ }
+
+ // Region support.
+ if (LangOpts.MicrosoftPragmaRegion) {
AddPragmaHandler(new PragmaRegionHandler("region"));
AddPragmaHandler(new PragmaRegionHandler("endregion"));
}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2160,6 +2160,7 @@
Opts.MSVCCompat = Args.hasArg(OPT_fms_compatibility);
Opts.MicrosoftExt = Opts.MSVCCompat || Args.hasArg(OPT_fms_extensions);
+ Opts.MicrosoftPragmaRegion = Opts.MicrosoftExt || T.isPS4();
Opts.AsmBlocks = Args.hasArg(OPT_fasm_blocks) || Opts.MicrosoftExt;
Opts.MSCompatibilityVersion = 0;
if (const Arg *A = Args.getLastArg(OPT_fms_compatibility_version)) {
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -85,6 +85,7 @@
LANGOPT(C17 , 1, 0, "C17")
LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility mode")
LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions")
+BENIGN_LANGOPT(MicrosoftPragmaRegion, 1, 0, "region pragma support")
LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, "C++")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.