xref: /minix3/external/bsd/llvm/dist/clang/test/Preprocessor/pragma_microsoft.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // rdar://6495941
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc #define FOO 1
6*f4a2713aSLionel Sambuc #define BAR "2"
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc #pragma comment(linker,"foo=" FOO) // expected-error {{pragma comment requires parenthesized identifier and optional string}}
9*f4a2713aSLionel Sambuc #pragma comment(linker," bar=" BAR)
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc #pragma comment( user, "Compiled on " __DATE__ " at " __TIME__ )
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc #pragma comment(foo)    // expected-error {{unknown kind of pragma comment}}
14*f4a2713aSLionel Sambuc #pragma comment(compiler,)     // expected-error {{expected string literal in pragma comment}}
15*f4a2713aSLionel Sambuc #define foo compiler
16*f4a2713aSLionel Sambuc #pragma comment(foo)   // macro expand kind.
17*f4a2713aSLionel Sambuc #pragma comment(foo) x // expected-error {{pragma comment requires}}
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc #pragma comment(user, "foo\abar\nbaz\tsome	thing")
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc #pragma detect_mismatch("test", "1")
22*f4a2713aSLionel Sambuc #pragma detect_mismatch()  // expected-error {{expected string literal in pragma detect_mismatch}}
23*f4a2713aSLionel Sambuc #pragma detect_mismatch("test") // expected-error {{pragma detect_mismatch is malformed; it requires two comma-separated string literals}}
24*f4a2713aSLionel Sambuc #pragma detect_mismatch("test", 1) // expected-error {{expected string literal in pragma detect_mismatch}}
25*f4a2713aSLionel Sambuc #pragma detect_mismatch("test", BAR)
26*f4a2713aSLionel Sambuc 
27*f4a2713aSLionel Sambuc // __pragma
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc __pragma(comment(linker," bar=" BAR))
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc #define MACRO_WITH__PRAGMA { \
32*f4a2713aSLionel Sambuc   __pragma(warning(push)); \
33*f4a2713aSLionel Sambuc   __pragma(warning(disable: 10000)); \
34*f4a2713aSLionel Sambuc   1 + (2 > 3) ? 4 : 5; \
35*f4a2713aSLionel Sambuc   __pragma(warning(pop)); \
36*f4a2713aSLionel Sambuc }
37*f4a2713aSLionel Sambuc 
f()38*f4a2713aSLionel Sambuc void f()
39*f4a2713aSLionel Sambuc {
40*f4a2713aSLionel Sambuc   __pragma()
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc   // If we ever actually *support* __pragma(warning(disable: x)),
43*f4a2713aSLionel Sambuc   // this warning should go away.
44*f4a2713aSLionel Sambuc   MACRO_WITH__PRAGMA // expected-warning {{lower precedence}} \
45*f4a2713aSLionel Sambuc                      // expected-note 2 {{place parentheses}}
46*f4a2713aSLionel Sambuc }
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc // This should include macro_arg_directive even though the include
50*f4a2713aSLionel Sambuc // is looking for test.h  This allows us to assign to "n"
51*f4a2713aSLionel Sambuc #pragma include_alias("test.h", "macro_arg_directive.h" )
52*f4a2713aSLionel Sambuc #include "test.h"
test(void)53*f4a2713aSLionel Sambuc void test( void ) {
54*f4a2713aSLionel Sambuc   n = 12;
55*f4a2713aSLionel Sambuc }
56*f4a2713aSLionel Sambuc 
57*f4a2713aSLionel Sambuc #pragma include_alias(<bar.h>, "bar.h") // expected-warning {{angle-bracketed include <bar.h> cannot be aliased to double-quoted include "bar.h"}}
58*f4a2713aSLionel Sambuc #pragma include_alias("foo.h", <bar.h>) // expected-warning {{double-quoted include "foo.h" cannot be aliased to angle-bracketed include <bar.h>}}
59*f4a2713aSLionel Sambuc #pragma include_alias("test.h") // expected-warning {{pragma include_alias expected ','}}
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc // Make sure that the names match exactly for a replacement, including path information.  If
62*f4a2713aSLionel Sambuc // this were to fail, we would get a file not found error
63*f4a2713aSLionel Sambuc #pragma include_alias(".\pp-record.h", "does_not_exist.h")
64*f4a2713aSLionel Sambuc #include "pp-record.h"
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc #pragma include_alias(12) // expected-warning {{pragma include_alias expected include filename}}
67*f4a2713aSLionel Sambuc 
68*f4a2713aSLionel Sambuc // It's expected that we can map "bar" and <bar> separately
69*f4a2713aSLionel Sambuc #define test
70*f4a2713aSLionel Sambuc // We can't actually look up stdio.h because we're using cc1 without header paths, but this will ensure
71*f4a2713aSLionel Sambuc // that we get the right bar.h, because the "bar.h" will undef test for us, where <bar.h> won't
72*f4a2713aSLionel Sambuc #pragma include_alias(<bar.h>, <stdio.h>)
73*f4a2713aSLionel Sambuc #pragma include_alias("bar.h", "pr2086.h")  // This should #undef test
74*f4a2713aSLionel Sambuc 
75*f4a2713aSLionel Sambuc #include "bar.h"
76*f4a2713aSLionel Sambuc #if defined(test)
77*f4a2713aSLionel Sambuc // This should not warn because test should not be defined
78*f4a2713aSLionel Sambuc #pragma include_alias("test.h")
79*f4a2713aSLionel Sambuc #endif
80*f4a2713aSLionel Sambuc 
81*f4a2713aSLionel Sambuc // Test to make sure there are no use-after-free problems
82*f4a2713aSLionel Sambuc #define B "pp-record.h"
83*f4a2713aSLionel Sambuc #pragma include_alias("quux.h", B)
g()84*f4a2713aSLionel Sambuc void g() {}
85*f4a2713aSLionel Sambuc #include "quux.h"
86*f4a2713aSLionel Sambuc 
87*f4a2713aSLionel Sambuc // Make sure that empty includes don't work
88*f4a2713aSLionel Sambuc #pragma include_alias("", "foo.h")  // expected-error {{empty filename}}
89*f4a2713aSLionel Sambuc #pragma include_alias(<foo.h>, <>)  // expected-error {{empty filename}}
90*f4a2713aSLionel Sambuc 
91*f4a2713aSLionel Sambuc // Test that we ignore pragma warning.
92*f4a2713aSLionel Sambuc #pragma warning(push)
93*f4a2713aSLionel Sambuc #pragma warning(push, 1)
94*f4a2713aSLionel Sambuc #pragma warning(disable : 4705)
95*f4a2713aSLionel Sambuc #pragma warning(disable : 123 456 789 ; error : 321)
96*f4a2713aSLionel Sambuc #pragma warning(once : 321)
97*f4a2713aSLionel Sambuc #pragma warning(suppress : 321)
98*f4a2713aSLionel Sambuc #pragma warning(default : 321)
99*f4a2713aSLionel Sambuc #pragma warning(pop)
100*f4a2713aSLionel Sambuc 
101*f4a2713aSLionel Sambuc #pragma warning(push, 0)
102*f4a2713aSLionel Sambuc // FIXME: We could probably support pushing warning level 0.
103*f4a2713aSLionel Sambuc #pragma warning(pop)
104*f4a2713aSLionel Sambuc 
105*f4a2713aSLionel Sambuc #pragma warning  // expected-warning {{expected '('}}
106*f4a2713aSLionel Sambuc #pragma warning(   // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}}
107*f4a2713aSLionel Sambuc #pragma warning()   // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}}
108*f4a2713aSLionel Sambuc #pragma warning(push 4)  // expected-warning {{expected ')'}}
109*f4a2713aSLionel Sambuc #pragma warning(push  // expected-warning {{expected ')'}}
110*f4a2713aSLionel Sambuc #pragma warning(push, 5)  // expected-warning {{requires a level between 0 and 4}}
111*f4a2713aSLionel Sambuc #pragma warning(pop, 1)  // expected-warning {{expected ')'}}
112*f4a2713aSLionel Sambuc #pragma warning(push, 1) asdf // expected-warning {{extra tokens at end of #pragma warning directive}}
113*f4a2713aSLionel Sambuc #pragma warning(disable 4705) // expected-warning {{expected ':'}}
114*f4a2713aSLionel Sambuc #pragma warning(disable : 0) // expected-warning {{expected a warning number}}
115*f4a2713aSLionel Sambuc #pragma warning(default 321) // expected-warning {{expected ':'}}
116*f4a2713aSLionel Sambuc #pragma warning(asdf : 321) // expected-warning {{expected 'push', 'pop'}}
117*f4a2713aSLionel Sambuc #pragma warning(push, -1) // expected-warning {{requires a level between 0 and 4}}
118