[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 04:31:25 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG24037c37b6c4: Add support for #pragma system_header with -fms-extensions (authored by hans).

Changed prior to commit:
  https://reviews.llvm.org/D104770?vs=353895&id=353926#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104770/new/

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,15 @@
-// RUN: %clang_cc1 -verify -pedantic %s -fsyntax-only
-// RUN: %clang_cc1 -E %s | FileCheck %s
-// expected-no-diagnostics
-// rdar://6899937
-#include "pragma_sysheader.h"
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s -fsyntax-only
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s -fsyntax-only -DGCC
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s -fsyntax-only -DCLANG
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s -fsyntax-only -fms-extensions -DMS
 
+// rdar://6899937
+#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: # 12 "{{.*}}pragma_sysheader.h"
+// CHECK: typedef int x;
+// CHECK: typedef int x;
+// CHECK-NEXT: # 8 "{{.*}}pragma_sysheader.c" 2
Index: clang/test/Preprocessor/Inputs/pragma_sysheader.h
===================================================================
--- /dev/null
+++ clang/test/Preprocessor/Inputs/pragma_sysheader.h
@@ -0,0 +1,19 @@
+#if defined(CLANG)
+#pragma clang system_header
+// expected-no-diagnostics
+#elif defined(GCC)
+#pragma GCC system_header
+// expected-no-diagnostics
+#elif defined(MS)
+#pragma system_header
+// expected-no-diagnostics
+#else
+// expected-warning at +1{{unknown pragma ignored}}
+#pragma system_header
+
+// expected-note at +4{{previous definition is here}}
+// expected-warning at +4{{redefinition of typedef 'x' is a C11 feature}}
+#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.353926.patch
Type: text/x-patch
Size: 3550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210623/623ef2a4/attachment-0001.bin>


More information about the cfe-commits mailing list