1 // RUN: %clang_cc1 -triple i686-unknown-windows-msvc %s -fsyntax-only -verify -fms-extensions -Wunknown-pragmas
2 // RUN: not %clang_cc1 -triple i686-unknown-windows-msvc %s -fms-extensions -E | FileCheck %s
3 // UNSUPPORTED: ps4
4
5 // rdar://6495941
6
7 #define FOO 1
8 #define BAR "2"
9
10 #pragma comment(linker,"foo=" FOO) // expected-error {{pragma comment requires parenthesized identifier and optional string}}
11 // CHECK: #pragma comment(linker,"foo=" 1)
12 #pragma comment(linker," bar=" BAR)
13 // CHECK: #pragma comment(linker," bar=" "2")
14
15 #pragma comment( user, "Compiled on " __DATE__ " at " __TIME__ )
16 // CHECK: {{#pragma comment\( user, \"Compiled on \".*\" at \".*\" \)}}
17
18 #pragma comment(foo) // expected-error {{unknown kind of pragma comment}}
19 // CHECK: #pragma comment(foo)
20 #pragma comment(compiler,) // expected-error {{expected string literal in pragma comment}}
21 // CHECK: #pragma comment(compiler,)
22 #define foo compiler
23 #pragma comment(foo) // macro expand kind.
24 // CHECK: #pragma comment(compiler)
25 #pragma comment(foo) x // expected-error {{pragma comment requires}}
26 // CHECK: #pragma comment(compiler) x
27
28 #pragma comment(user, "foo\abar\nbaz\tsome thing")
29 // CHECK: #pragma comment(user, "foo\abar\nbaz\tsome thing")
30
31 #pragma detect_mismatch("test", "1")
32 // CHECK: #pragma detect_mismatch("test", "1")
33 #pragma detect_mismatch() // expected-error {{expected string literal in pragma detect_mismatch}}
34 // CHECK: #pragma detect_mismatch()
35 #pragma detect_mismatch("test") // expected-error {{pragma detect_mismatch is malformed; it requires two comma-separated string literals}}
36 // CHECK: #pragma detect_mismatch("test")
37 #pragma detect_mismatch("test", 1) // expected-error {{expected string literal in pragma detect_mismatch}}
38 // CHECK: #pragma detect_mismatch("test", 1)
39 #pragma detect_mismatch("test", BAR)
40 // CHECK: #pragma detect_mismatch("test", "2")
41
42 // __pragma
43
44 __pragma(comment(linker," bar=" BAR))
45 // CHECK: #pragma comment(linker," bar=" "2")
46
47 #define MACRO_WITH__PRAGMA { \
48 __pragma(warning(push)); \
49 __pragma(warning(disable: 10000)); \
50 1 + (2 > 3) ? 4 : 5; \
51 __pragma(warning(pop)); \
52 }
53
54 #define PRAGMA_IN_ARGS(p) p
55
f()56 void f()
57 {
58 __pragma() // expected-warning{{unknown pragma ignored}}
59 // CHECK: #pragma
60
61 // If we ever actually *support* __pragma(warning(disable: x)),
62 // this warning should go away.
63 MACRO_WITH__PRAGMA // expected-warning {{lower precedence}} \
64 // expected-note 2 {{place parentheses}}
65 // CHECK: #pragma warning(push)
66 // CHECK: #pragma warning(disable: 10000)
67 // CHECK: ; 1 + (2 > 3) ? 4 : 5;
68 // CHECK: #pragma warning(pop)
69
70 // Check that macro arguments can contain __pragma.
71 PRAGMA_IN_ARGS(MACRO_WITH__PRAGMA) // expected-warning {{lower precedence}} \
72 // expected-note 2 {{place parentheses}} \
73 // expected-warning {{expression result unused}}
74 // CHECK: #pragma warning(push)
75 // CHECK: #pragma warning(disable: 10000)
76 // CHECK: ; 1 + (2 > 3) ? 4 : 5;
77 // CHECK: #pragma warning(pop)
78 }
79
80 // This should include macro_arg_directive even though the include
81 // is looking for test.h This allows us to assign to "n"
82 #pragma include_alias("test.h", "macro_arg_directive.h" )
83 #include "test.h"
test(void)84 void test( void ) {
85 n = 12;
86 }
87
88 #pragma include_alias(<bar.h>, "bar.h") // expected-warning {{angle-bracketed include <bar.h> cannot be aliased to double-quoted include "bar.h"}}
89 #pragma include_alias("foo.h", <bar.h>) // expected-warning {{double-quoted include "foo.h" cannot be aliased to angle-bracketed include <bar.h>}}
90 #pragma include_alias("test.h") // expected-warning {{pragma include_alias expected ','}}
91
92 // Make sure that the names match exactly for a replacement, including path information. If
93 // this were to fail, we would get a file not found error
94 #pragma include_alias(".\pp-record.h", "does_not_exist.h")
95 #include "pp-record.h"
96
97 #pragma include_alias(12) // expected-warning {{pragma include_alias expected include filename}}
98
99 // It's expected that we can map "bar" and <bar> separately
100 #define test
101 // We can't actually look up stdio.h because we're using cc1 without header paths, but this will ensure
102 // that we get the right bar.h, because the "bar.h" will undef test for us, where <bar.h> won't
103 #pragma include_alias(<bar.h>, <stdio.h>)
104 #pragma include_alias("bar.h", "pr2086.h") // This should #undef test
105
106 #include "bar.h"
107 #if defined(test)
108 // This should not warn because test should not be defined
109 #pragma include_alias("test.h")
110 #endif
111
112 // Test to make sure there are no use-after-free problems
113 #define B "pp-record.h"
114 #pragma include_alias("quux.h", B)
g()115 void g() {}
116 #include "quux.h"
117
118 // Make sure that empty includes don't work
119 #pragma include_alias("", "foo.h") // expected-error {{empty filename}}
120 #pragma include_alias(<foo.h>, <>) // expected-error {{empty filename}}
121
122 // Test that we ignore pragma warning.
123 #pragma warning(push)
124 // CHECK: #pragma warning(push)
125 #pragma warning(push, 1)
126 // CHECK: #pragma warning(push, 1)
127 #pragma warning(disable : 4705)
128 // CHECK: #pragma warning(disable: 4705)
129 #pragma warning(disable : 123 456 789 ; error : 321)
130 // CHECK: #pragma warning(disable: 123 456 789)
131 // CHECK: #pragma warning(error: 321)
132 #pragma warning(once : 321)
133 // CHECK: #pragma warning(once: 321)
134 #pragma warning(suppress : 321)
135 // CHECK: #pragma warning(suppress: 321)
136 #pragma warning(default : 321)
137 // CHECK: #pragma warning(default: 321)
138 #pragma warning(pop)
139 // CHECK: #pragma warning(pop)
140 #pragma warning(1: 123)
141 // CHECK: #pragma warning(1: 123)
142 #pragma warning(2: 234 567)
143 // CHECK: #pragma warning(2: 234 567)
144 #pragma warning(3: 123; 4: 678)
145 // CHECK: #pragma warning(3: 123)
146 // CHECK: #pragma warning(4: 678)
147 #pragma warning(5: 123) // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}}
148
149 #pragma warning(push, 0)
150 // CHECK: #pragma warning(push, 0)
151 // FIXME: We could probably support pushing warning level 0.
152 #pragma warning(pop)
153 // CHECK: #pragma warning(pop)
154
155 #pragma warning // expected-warning {{expected '('}}
156 #pragma warning( // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}}
157 #pragma warning() // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}}
158 #pragma warning(push 4) // expected-warning {{expected ')'}}
159 // CHECK: #pragma warning(push)
160 #pragma warning(push // expected-warning {{expected ')'}}
161 // CHECK: #pragma warning(push)
162 #pragma warning(push, 5) // expected-warning {{requires a level between 0 and 4}}
163 #pragma warning(pop, 1) // expected-warning {{expected ')'}}
164 // CHECK: #pragma warning(pop)
165 #pragma warning(push, 1) asdf // expected-warning {{extra tokens at end of #pragma warning directive}}
166 // CHECK: #pragma warning(push, 1)
167 #pragma warning(disable 4705) // expected-warning {{expected ':'}}
168 #pragma warning(disable : 0) // expected-warning {{expected a warning number}}
169 #pragma warning(default 321) // expected-warning {{expected ':'}}
170 #pragma warning(asdf : 321) // expected-warning {{expected 'push', 'pop'}}
171 #pragma warning(push, -1) // expected-warning {{requires a level between 0 and 4}}
172
173 // Test that runtime_checks is parsed but ignored.
174 #pragma runtime_checks("sc", restore) // no-warning
175
176 // Test pragma intrinsic
177 #pragma intrinsic(memset) // no-warning
178 #pragma intrinsic(memcpy, strlen, strlen) // no-warning
179 #pragma intrinsic() // no-warning
180 #pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
181 #pragma intrinsic(main) // expected-warning {{'main' is not a recognized builtin; consider including <intrin.h>}}
182 #pragma intrinsic( // expected-warning {{missing ')' after}}
183 #pragma intrinsic(int) // expected-warning {{missing ')' after}}
184 #pragma intrinsic(strcmp) asdf // expected-warning {{extra tokens at end}}
185
186 #define __INTRIN_H // there should be no notes after defining __INTRIN_H
187 #pragma intrinsic(asdf) // expected-warning-re {{'asdf' is not a recognized builtin{{$}}}}
188 #pragma intrinsic(memset) // no-warning
189 #undef __INTRIN_H
190 #pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
191
192 #pragma clang diagnostic push
193 #pragma clang diagnostic ignored "-Wignored-pragma-intrinsic"
194 #pragma intrinsic(asdf) // no-warning
195 #pragma clang diagnostic pop
196 #pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
197
198 #pragma clang diagnostic push
199 #pragma clang diagnostic ignored "-Wignored-pragmas"
200 #pragma intrinsic(asdf) // no-warning
201 #pragma clang diagnostic pop
202 #pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
203
204 #pragma optimize // expected-warning{{missing '(' after '#pragma optimize'}}
205 #pragma optimize( // expected-warning{{expected string literal in '#pragma optimize'}}
206 #pragma optimize(a // expected-warning{{expected string literal in '#pragma optimize'}}
207 #pragma optimize("g" // expected-warning{{expected ',' in '#pragma optimize'}}
208 #pragma optimize("g", // expected-warning{{missing argument to '#pragma optimize'; expected 'on' or 'off'}}
209 #pragma optimize("g",xyz // expected-warning{{unexpected argument 'xyz' to '#pragma optimize'; expected 'on' or 'off'}}
210 #pragma optimize("g",on) // expected-warning{{#pragma optimize' is not supported}}
211
212 #pragma execution_character_set // expected-warning {{expected '('}}
213 #pragma execution_character_set( // expected-warning {{expected 'push' or 'pop'}}
214 #pragma execution_character_set() // expected-warning {{expected 'push' or 'pop'}}
215 #pragma execution_character_set(asdf // expected-warning {{expected 'push' or 'pop'}}
216 #pragma execution_character_set(asdf) // expected-warning {{expected 'push' or 'pop'}}
217 #pragma execution_character_set(push // expected-warning {{expected ')'}}
218 #pragma execution_character_set(pop,) // expected-warning {{expected ')'}}
219 #pragma execution_character_set(pop,"asdf") // expected-warning {{expected ')'}}
220 #pragma execution_character_set(push, // expected-error {{expected string literal}}
221 #pragma execution_character_set(push,) // expected-error {{expected string literal}}
222 #pragma execution_character_set(push,asdf) // expected-error {{expected string literal}}
223 #pragma execution_character_set(push, "asdf") // expected-warning {{only 'UTF-8' is supported}}
224
225 #pragma execution_character_set(push)
226 #pragma execution_character_set(push, "utf-8")
227 #pragma execution_character_set(push, "UTF-8")
228 #pragma execution_character_set(pop)
229