| 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 | // REQUIRES: non-ps4-sdk |
| 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 | void f() |
| 55 | { |
| 56 | __pragma() // expected-warning{{unknown pragma ignored}} |
| 57 | // CHECK: #pragma |
| 58 | |
| 59 | // If we ever actually *support* __pragma(warning(disable: x)), |
| 60 | // this warning should go away. |
| 61 | MACRO_WITH__PRAGMA // expected-warning {{lower precedence}} \ |
| 62 | // expected-note 2 {{place parentheses}} |
| 63 | // CHECK: #pragma warning(push) |
| 64 | // CHECK: #pragma warning(disable: 10000) |
| 65 | // CHECK: ; 1 + (2 > 3) ? 4 : 5; |
| 66 | // CHECK: #pragma warning(pop) |
| 67 | } |
| 68 | |
| 69 | |
| 70 | // This should include macro_arg_directive even though the include |
| 71 | // is looking for test.h This allows us to assign to "n" |
| 72 | #pragma include_alias("test.h", "macro_arg_directive.h" ) |
| 73 | #include "test.h" |
| 74 | void test( void ) { |
| 75 | n = 12; |
| 76 | } |
| 77 | |
| 78 | #pragma include_alias(<bar.h>, "bar.h") // expected-warning {{angle-bracketed include <bar.h> cannot be aliased to double-quoted include "bar.h"}} |
| 79 | #pragma include_alias("foo.h", <bar.h>) // expected-warning {{double-quoted include "foo.h" cannot be aliased to angle-bracketed include <bar.h>}} |
| 80 | #pragma include_alias("test.h") // expected-warning {{pragma include_alias expected ','}} |
| 81 | |
| 82 | // Make sure that the names match exactly for a replacement, including path information. If |
| 83 | // this were to fail, we would get a file not found error |
| 84 | #pragma include_alias(".\pp-record.h", "does_not_exist.h") |
| 85 | #include "pp-record.h" |
| 86 | |
| 87 | #pragma include_alias(12) // expected-warning {{pragma include_alias expected include filename}} |
| 88 | |
| 89 | // It's expected that we can map "bar" and <bar> separately |
| 90 | #define test |
| 91 | // We can't actually look up stdio.h because we're using cc1 without header paths, but this will ensure |
| 92 | // that we get the right bar.h, because the "bar.h" will undef test for us, where <bar.h> won't |
| 93 | #pragma include_alias(<bar.h>, <stdio.h>) |
| 94 | #pragma include_alias("bar.h", "pr2086.h") // This should #undef test |
| 95 | |
| 96 | #include "bar.h" |
| 97 | #if defined(test) |
| 98 | // This should not warn because test should not be defined |
| 99 | #pragma include_alias("test.h") |
| 100 | #endif |
| 101 | |
| 102 | // Test to make sure there are no use-after-free problems |
| 103 | #define B "pp-record.h" |
| 104 | #pragma include_alias("quux.h", B) |
| 105 | void g() {} |
| 106 | #include "quux.h" |
| 107 | |
| 108 | // Make sure that empty includes don't work |
| 109 | #pragma include_alias("", "foo.h") // expected-error {{empty filename}} |
| 110 | #pragma include_alias(<foo.h>, <>) // expected-error {{empty filename}} |
| 111 | |
| 112 | // Test that we ignore pragma warning. |
| 113 | #pragma warning(push) |
| 114 | // CHECK: #pragma warning(push) |
| 115 | #pragma warning(push, 1) |
| 116 | // CHECK: #pragma warning(push, 1) |
| 117 | #pragma warning(disable : 4705) |
| 118 | // CHECK: #pragma warning(disable: 4705) |
| 119 | #pragma warning(disable : 123 456 789 ; error : 321) |
| 120 | // CHECK: #pragma warning(disable: 123 456 789) |
| 121 | // CHECK: #pragma warning(error: 321) |
| 122 | #pragma warning(once : 321) |
| 123 | // CHECK: #pragma warning(once: 321) |
| 124 | #pragma warning(suppress : 321) |
| 125 | // CHECK: #pragma warning(suppress: 321) |
| 126 | #pragma warning(default : 321) |
| 127 | // CHECK: #pragma warning(default: 321) |
| 128 | #pragma warning(pop) |
| 129 | // CHECK: #pragma warning(pop) |
| 130 | #pragma warning(1: 123) |
| 131 | // CHECK: #pragma warning(1: 123) |
| 132 | #pragma warning(2: 234 567) |
| 133 | // CHECK: #pragma warning(2: 234 567) |
| 134 | #pragma warning(3: 123; 4: 678) |
| 135 | // CHECK: #pragma warning(3: 123) |
| 136 | // CHECK: #pragma warning(4: 678) |
| 137 | #pragma warning(5: 123) // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}} |
| 138 | |
| 139 | #pragma warning(push, 0) |
| 140 | // CHECK: #pragma warning(push, 0) |
| 141 | // FIXME: We could probably support pushing warning level 0. |
| 142 | #pragma warning(pop) |
| 143 | // CHECK: #pragma warning(pop) |
| 144 | |
| 145 | #pragma warning // expected-warning {{expected '('}} |
| 146 | #pragma warning( // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}} |
| 147 | #pragma warning() // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}} |
| 148 | #pragma warning(push 4) // expected-warning {{expected ')'}} |
| 149 | // CHECK: #pragma warning(push) |
| 150 | #pragma warning(push // expected-warning {{expected ')'}} |
| 151 | // CHECK: #pragma warning(push) |
| 152 | #pragma warning(push, 5) // expected-warning {{requires a level between 0 and 4}} |
| 153 | #pragma warning(pop, 1) // expected-warning {{expected ')'}} |
| 154 | // CHECK: #pragma warning(pop) |
| 155 | #pragma warning(push, 1) asdf // expected-warning {{extra tokens at end of #pragma warning directive}} |
| 156 | // CHECK: #pragma warning(push, 1) |
| 157 | #pragma warning(disable 4705) // expected-warning {{expected ':'}} |
| 158 | #pragma warning(disable : 0) // expected-warning {{expected a warning number}} |
| 159 | #pragma warning(default 321) // expected-warning {{expected ':'}} |
| 160 | #pragma warning(asdf : 321) // expected-warning {{expected 'push', 'pop'}} |
| 161 | #pragma warning(push, -1) // expected-warning {{requires a level between 0 and 4}} |
| 162 | |
| 163 | // Test that runtime_checks is parsed but ignored. |
| 164 | #pragma runtime_checks("sc", restore) // no-warning |
| 165 | |
| 166 | // Test pragma intrinsic |
| 167 | #pragma intrinsic(memset) // no-warning |
| 168 | #pragma intrinsic(memcpy, strlen, strlen) // no-warning |
| 169 | #pragma intrinsic() // no-warning |
| 170 | #pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}} |
| 171 | #pragma intrinsic(main) // expected-warning {{'main' is not a recognized builtin; consider including <intrin.h>}} |
| 172 | #pragma intrinsic( // expected-warning {{missing ')' after}} |
| 173 | #pragma intrinsic(int) // expected-warning {{missing ')' after}} |
| 174 | #pragma intrinsic(strcmp) asdf // expected-warning {{extra tokens at end}} |
| 175 | |
| 176 | #define __INTRIN_H // there should be no notes after defining __INTRIN_H |
| 177 | #pragma intrinsic(asdf) // expected-warning-re {{'asdf' is not a recognized builtin{{$}}}} |
| 178 | #pragma intrinsic(memset) // no-warning |
| 179 | #undef __INTRIN_H |
| 180 | #pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}} |
| 181 | |
| 182 | #pragma clang diagnostic push |
| 183 | #pragma clang diagnostic ignored "-Wignored-pragma-intrinsic" |
| 184 | #pragma intrinsic(asdf) // no-warning |
| 185 | #pragma clang diagnostic pop |
| 186 | #pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}} |
| 187 | |
| 188 | #pragma clang diagnostic push |
| 189 | #pragma clang diagnostic ignored "-Wignored-pragmas" |
| 190 | #pragma intrinsic(asdf) // no-warning |
| 191 | #pragma clang diagnostic pop |
| 192 | #pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}} |
| 193 | |
| 194 | #pragma optimize // expected-warning{{missing '(' after '#pragma optimize'}} |
| 195 | #pragma optimize( // expected-warning{{expected string literal in '#pragma optimize'}} |
| 196 | #pragma optimize(a // expected-warning{{expected string literal in '#pragma optimize'}} |
| 197 | #pragma optimize("g" // expected-warning{{expected ',' in '#pragma optimize'}} |
| 198 | #pragma optimize("g", // expected-warning{{missing argument to '#pragma optimize'; expected 'on' or 'off'}} |
| 199 | #pragma optimize("g",xyz // expected-warning{{unexpected argument 'xyz' to '#pragma optimize'; expected 'on' or 'off'}} |
| 200 | #pragma optimize("g",on) // expected-warning{{#pragma optimize' is not supported}} |
| 201 | |
| 202 | #pragma execution_character_set // expected-warning {{expected '('}} |
| 203 | #pragma execution_character_set( // expected-warning {{expected 'push' or 'pop'}} |
| 204 | #pragma execution_character_set() // expected-warning {{expected 'push' or 'pop'}} |
| 205 | #pragma execution_character_set(asdf // expected-warning {{expected 'push' or 'pop'}} |
| 206 | #pragma execution_character_set(asdf) // expected-warning {{expected 'push' or 'pop'}} |
| 207 | #pragma execution_character_set(push // expected-warning {{expected ')'}} |
| 208 | #pragma execution_character_set(pop,) // expected-warning {{expected ')'}} |
| 209 | #pragma execution_character_set(pop,"asdf") // expected-warning {{expected ')'}} |
| 210 | #pragma execution_character_set(push, // expected-error {{expected string literal}} |
| 211 | #pragma execution_character_set(push,) // expected-error {{expected string literal}} |
| 212 | #pragma execution_character_set(push,asdf) // expected-error {{expected string literal}} |
| 213 | #pragma execution_character_set(push, "asdf") // expected-warning {{only 'UTF-8' is supported}} |
| 214 | |
| 215 | #pragma execution_character_set(push) |
| 216 | #pragma execution_character_set(push, "utf-8") |
| 217 | #pragma execution_character_set(push, "UTF-8") |
| 218 | #pragma execution_character_set(pop) |