diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp --- a/clang/lib/Lex/Pragma.cpp +++ b/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 diff --git a/clang/test/Lexer/pragma-operators.cpp b/clang/test/Lexer/pragma-operators.cpp --- a/clang/test/Lexer/pragma-operators.cpp +++ b/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" diff --git a/clang/test/Preprocessor/Inputs/pragma_sysheader.h b/clang/test/Preprocessor/Inputs/pragma_sysheader.h new file mode 100644 --- /dev/null +++ b/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@+1{{unknown pragma ignored}} +#pragma system_header + +// expected-note@+4{{previous definition is here}} +// expected-warning@+4{{redefinition of typedef 'x' is a C11 feature}} +#endif + +typedef int x; +typedef int x; diff --git a/clang/test/Preprocessor/pragma_sysheader.h b/clang/test/Preprocessor/pragma_sysheader.h deleted file mode 100644 --- a/clang/test/Preprocessor/pragma_sysheader.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma GCC system_header -typedef int x; -typedef int x; - diff --git a/clang/test/Preprocessor/pragma_sysheader.c b/clang/test/Preprocessor/pragma_sysheader.c --- a/clang/test/Preprocessor/pragma_sysheader.c +++ b/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