[PATCH] D104770: Add support for #pragma system_header with -fms-extensions

Hans Wennborg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 23 02:17:37 PDT 2021


hans created this revision.
hans added a reviewer: thakis.
hans requested review of this revision.
Herald added a project: clang.

Clang already supports the pragma prefixed by "GCC" or "clang".

MSVC has more recently added support for the pragma, but without any prefix; see https://devblogs.microsoft.com/cppblog/broken-warnings-theory/#external-headers


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104770

Files:
  clang/lib/Lex/Pragma.cpp
  clang/test/Lexer/pragma-operators.cpp
  clang/test/Preprocessor/Inputs/pragma_sysheader.h
  clang/test/Preprocessor/pragma_sysheader.c
  clang/test/Preprocessor/pragma_sysheader.h


Index: clang/test/Preprocessor/pragma_sysheader.h
===================================================================
--- clang/test/Preprocessor/pragma_sysheader.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma GCC system_header
-typedef int x;
-typedef int x;
-
Index: clang/test/Preprocessor/pragma_sysheader.c
===================================================================
--- clang/test/Preprocessor/pragma_sysheader.c
+++ clang/test/Preprocessor/pragma_sysheader.c
@@ -1,13 +1,14 @@
-// RUN: %clang_cc1 -verify -pedantic %s -fsyntax-only
-// RUN: %clang_cc1 -E %s | FileCheck %s
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only -DCLANG
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only -fms-extensions -DMS
 // expected-no-diagnostics
 // rdar://6899937
-#include "pragma_sysheader.h"
-
+#include "Inputs/pragma_sysheader.h"
 
+// RUN: %clang_cc1 -E %s | FileCheck %s
 // PR9861: Verify that line markers are not messed up in -E mode.
 // CHECK: # 1 "{{.*}}pragma_sysheader.h" 1
-// CHECK-NEXT: # 2 "{{.*}}pragma_sysheader.h" 3
-// CHECK-NEXT: typedef int x;
-// CHECK-NEXT: typedef int x;
-// CHECK-NEXT: # 6 "{{.*}}pragma_sysheader.c" 2
+// CHECK-NEXT: # 7 "{{.*}}pragma_sysheader.h" 3
+// CHECK: typedef int x;
+// CHECK: typedef int x;
+// CHECK-NEXT: # 7 "{{.*}}pragma_sysheader.c" 2
Index: clang/test/Preprocessor/Inputs/pragma_sysheader.h
===================================================================
--- /dev/null
+++ clang/test/Preprocessor/Inputs/pragma_sysheader.h
@@ -0,0 +1,10 @@
+#if defined(CLANG)
+#pragma clang system_header
+#elif defined(MS)
+#pragma system_header
+#else
+#pragma GCC system_header
+#endif
+
+typedef int x;
+typedef int x;
Index: clang/test/Lexer/pragma-operators.cpp
===================================================================
--- clang/test/Lexer/pragma-operators.cpp
+++ clang/test/Lexer/pragma-operators.cpp
@@ -19,7 +19,7 @@
 #pragma warning(pop)
 
 #define pragma_L _Pragma(L"GCC diagnostic push")
-#define pragma_u8 _Pragma(u8"system_header")
+#define pragma_u8 _Pragma(u8"pack(1)")
 #define pragma_u _Pragma(u"GCC diagnostic pop")
 #define pragma_U _Pragma(U"comment(lib, \"libfoo\")")
 #define pragma_R _Pragma(R"(clang diagnostic ignored "-Wunused")")
@@ -27,7 +27,7 @@
 #define pragma_hello _Pragma(u8R"x(message R"y("Hello", world!)y")x")
 // CHECK: int n =
 // CHECK: #pragma GCC diagnostic push
-// CHECK: #pragma system_header
+// CHECK: #pragma pack(1)
 // CHECK: #pragma GCC diagnostic pop
 // CHECK: #pragma comment(lib, "libfoo")
 // CHECK: #pragma clang diagnostic ignored "-Wunused"
Index: clang/lib/Lex/Pragma.cpp
===================================================================
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1955,6 +1955,7 @@
     AddPragmaHandler(new PragmaExecCharsetHandler());
     AddPragmaHandler(new PragmaIncludeAliasHandler());
     AddPragmaHandler(new PragmaHdrstopHandler());
+    AddPragmaHandler(new PragmaSystemHeaderHandler());
   }
 
   // Pragmas added by plugins


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104770.353895.patch
Type: text/x-patch
Size: 3087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210623/a50d44f7/attachment-0001.bin>


More information about the cfe-commits mailing list